Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -2212,29 +2212,54 @@ static public InputStream getLibStream(String filename) throws IOException {
* something similar on Windows, a dot folder on Linux.) Removed this as a
* preference for 3.0a3 because we need this to be stable, but adding back
* for 4.0 beta 4 so that folks can do 'portable' versions again.
*
* @deprecated use processing.utils.Settings.getFolder() instead, this method will invoke AWT
*/
static public File getSettingsFolder() {
File settingsFolder = null;

try {
settingsFolder = Platform.getSettingsFolder();

// create the folder if it doesn't exist already
if (!settingsFolder.exists()) {
if (!settingsFolder.mkdirs()) {
Messages.showError("Settings issues",
"Processing cannot run because it could not\n" +
"create a folder to store your settings at\n" +
settingsFolder, null);
}
var override = getSettingsOverride();
if (override != null) {
return override;
}
} catch (Exception e) {
Messages.showTrace("An rare and unknowable thing happened",
"Could not get the settings folder. Please report:\n" +
"http://github.com/processing/processing/issues/new",
e, true);
}
return settingsFolder;
try {
return processing.utils.Settings.getFolder();
} catch (processing.utils.Settings.SettingsFolderException e) {
switch (e.getType()) {
case COULD_NOT_CREATE_FOLDER -> Messages.showError("Settings issues",
"""
Processing cannot run because it could not
create a folder to store your settings at
""" + e.getMessage(), null);
case WINDOWS_APPDATA_NOT_FOUND -> Messages.showError("Settings issues",
"""
Processing cannot run because it could not
find the AppData or LocalAppData folder on your system.
""", null);
case MACOS_LIBRARY_FOLDER_NOT_FOUND -> Messages.showError("Settings issues",
"""
Processing cannot run because it could not
find the Library folder on your system.
""", null);
case LINUX_CONFIG_FOLDER_NOT_FOUND -> Messages.showError("Settings issues",
"""
Processing cannot run because either your
XDG_CONFIG_HOME or SNAP_USER_COMMON is set
but the folder does not exist.
""", null);
case LINUX_SUDO_USER_ERROR -> Messages.showError("Settings issues",
"""
Processing cannot run because it was started
with sudo and Processing could not resolve
the original users home directory.
""", null);
default -> Messages.showTrace("An rare and unknowable thing happened",
"""
Could not get the settings folder. Please report:
http://github.com/processing/processing4/issues/new
""",
e, true);
}
}
throw new RuntimeException("Unreachable code in Base.getSettingsFolder()");
}


Expand Down
30 changes: 2 additions & 28 deletions app/src/processing/app/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.Map;


public class Platform {
public class Platform extends processing.utils.Platform {
static DefaultPlatform inst;

/*
Expand Down Expand Up @@ -136,12 +136,7 @@ static public float getSystemZoom() {
}


static public File getSettingsFolder() throws Exception {
return inst.getSettingsFolder();
}


static public File getDefaultSketchbookFolder() throws Exception {
static public File getDefaultSketchbookFolder() throws Exception {
return inst.getDefaultSketchbookFolder();
}

Expand Down Expand Up @@ -303,28 +298,7 @@ static public int getIndex(String platformName) {
// the MACOSX constant would instead read as the LINUX constant.


/**
* returns true if Processing is running on a Mac OS X machine.
*/
static public boolean isMacOS() {
return System.getProperty("os.name").contains("Mac"); //$NON-NLS-1$ //$NON-NLS-2$
}


/**
* returns true if running on windows.
*/
static public boolean isWindows() {
return System.getProperty("os.name").contains("Windows"); //$NON-NLS-1$ //$NON-NLS-2$
}


/**
* true if running on linux.
*/
static public boolean isLinux() {
return System.getProperty("os.name").contains("Linux"); //$NON-NLS-1$ //$NON-NLS-2$
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Expand Down
9 changes: 6 additions & 3 deletions app/src/processing/app/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package processing.app
import androidx.compose.runtime.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import processing.utils.Settings
import java.io.File
import java.io.InputStream
import java.nio.file.*
import java.util.Properties
import java.nio.file.FileSystems
import java.nio.file.StandardWatchEventKinds
import java.nio.file.WatchEvent
import java.util.*


const val PREFERENCES_FILE_NAME = "preferences.txt"
Expand All @@ -20,7 +23,7 @@ fun PlatformStart(){
fun loadPreferences(): Properties{
PlatformStart()

val settingsFolder = Platform.getSettingsFolder()
val settingsFolder = Settings.getFolder()
val preferencesFile = settingsFolder.resolve(PREFERENCES_FILE_NAME)

if(!preferencesFile.exists()){
Expand Down
34 changes: 6 additions & 28 deletions app/src/processing/app/platform/DefaultPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,19 @@

package processing.app.platform;

import java.awt.Desktop;
import java.awt.Font;
import java.io.File;

import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import com.sun.jna.Library;
import com.sun.jna.Native;

import processing.app.Base;
import processing.app.Preferences;
import processing.app.ui.Toolkit;
import processing.awt.ShimAWT;
import processing.core.PApplet;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.io.File;


/**
* Used by Base for platform-specific tweaking, for instance finding the
Expand Down Expand Up @@ -206,24 +201,7 @@ public void setInterfaceZoom() throws Exception {
public void saveLanguage(String languageCode) { }


/**
* This function should throw an exception or return a value.
* Do not return null.
*/
public File getSettingsFolder() throws Exception {
File override = Base.getSettingsOverride();
if (override != null) {
return override;
}

// If no subclass has a behavior, default to making a
// ".processing" directory in the user's home directory.
File home = new File(System.getProperty("user.home"));
return new File(home, ".processing");
}


/**
/**
* @return if not overridden, a folder named "sketchbook" in user.home.
* @throws Exception so that subclasses can throw a fit
*/
Expand Down
42 changes: 3 additions & 39 deletions app/src/processing/app/platform/LinuxPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@

package processing.app.platform;

import java.io.File;
import java.awt.Desktop;
import java.awt.Toolkit;

import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.core.PApplet;

import javax.swing.*;
import java.awt.*;
import java.io.File;


public class LinuxPlatform extends DefaultPlatform {
Expand Down Expand Up @@ -90,40 +87,7 @@ static public String getHomeDir(String user) throws Exception {
}


@Override
public File getSettingsFolder() throws Exception {
File override = Base.getSettingsOverride();
if (override != null) {
return override;
}

// https://github.com/processing/processing4/issues/203
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

File configHome = null;

// Check to see if the user has set a different location for their config
String configHomeEnv = System.getenv("XDG_CONFIG_HOME");
if (configHomeEnv != null && !configHomeEnv.isBlank()) {
configHome = new File(configHomeEnv);
if (!configHome.exists()) {
Messages.err("XDG_CONFIG_HOME is set to " + configHomeEnv + " but does not exist.");
configHome = null; // don't use non-existent folder
}
}
String snapUserCommon = System.getenv("SNAP_USER_COMMON");
if (snapUserCommon != null && !snapUserCommon.isBlank()) {
configHome = new File(snapUserCommon);
}
// If not set properly, use the default
if (configHome == null) {
configHome = new File(getHomeDir(), ".config");
}
return new File(configHome, "processing");
}


@Override
@Override
public File getDefaultSketchbookFolder() throws Exception {
return new File(getHomeDir(), "sketchbook");
}
Expand Down
41 changes: 8 additions & 33 deletions app/src/processing/app/platform/MacPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@

package processing.app.platform;

import processing.app.Base;
import processing.app.Messages;
import processing.app.ui.About;
import processing.core.PApplet;
import processing.data.StringList;

import javax.swing.*;
import java.awt.*;
import java.awt.desktop.AppReopenedEvent;
import java.awt.desktop.AppReopenedListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;

import javax.swing.JMenu;
import javax.swing.JMenuBar;

import processing.app.Base;
import processing.app.Messages;
import processing.app.ui.About;
import processing.core.PApplet;
import processing.data.StringList;


/**
* Platform handler for macOS.
Expand Down Expand Up @@ -112,16 +109,7 @@ public void initBase(Base base) {
}


public File getSettingsFolder() throws Exception {
File override = Base.getSettingsOverride();
if (override != null) {
return override;
}
return new File(getLibraryFolder(), "Processing");
}


public File getDefaultSketchbookFolder() throws Exception {
public File getDefaultSketchbookFolder() throws Exception {
return new File(getDocumentsFolder(), "Processing");
}

Expand All @@ -144,19 +132,6 @@ public void openURL(String url) throws Exception {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


// TODO I suspect this won't work much longer, since access to the user's
// home directory seems verboten on more recent macOS versions [fry 191008]
// However, anecdotally it seems that just using the name works,
// and the localization is handled transparently. [fry 220116]
// https://github.com/processing/processing4/issues/9
protected String getLibraryFolder() throws FileNotFoundException {
File folder = new File(System.getProperty("user.home"), "Library");
if (!folder.exists()) {
throw new FileNotFoundException("Folder missing: " + folder);
}
return folder.getAbsolutePath();
}


// TODO See above, and https://github.com/processing/processing4/issues/9
protected String getDocumentsFolder() throws FileNotFoundException {
Expand Down
Loading