integrate sudo patch and a couple cleanups

This commit is contained in:
Ben Fry
2017-05-08 07:21:42 -04:00
parent 6a91acc1aa
commit 199eabc488
3 changed files with 24 additions and 32 deletions
@@ -22,20 +22,17 @@
package processing.app.platform;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.IOException;
import java.awt.Toolkit;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.app.platform.DefaultPlatform;
import processing.core.PApplet;
public class LinuxPlatform extends DefaultPlatform {
String homeDir;
@@ -73,48 +70,34 @@ public class LinuxPlatform extends DefaultPlatform {
}
// Java sets user.home to be /root for execution with sudo.
// This method attempts to use the user's real home directory instead.
public String getHomeDir() {
// return cached value if set
if (homeDir != null) {
return homeDir;
if (homeDir == null) {
// get home directory of SUDO_USER if set, else use user.home
homeDir = System.getProperty("user.home");
String sudoUser = System.getenv("SUDO_USER");
if (sudoUser != null && sudoUser.length() != 0) {
try {
homeDir = getHomeDir(sudoUser);
} catch (Exception e) { }
}
}
// get home directory of SUDO_USER if set,
// else use user.home
homeDir = System.getProperty("user.home");
String sudoUser = System.getenv("SUDO_USER");
if (sudoUser != null && sudoUser.length() != 0) {
try {
homeDir = getHomeDir(sudoUser);
} catch (Exception e) {}
}
return homeDir;
}
public static String getHomeDir(String user) throws IOException {
return new BufferedReader(
new InputStreamReader(
Runtime.getRuntime().exec(
new String[]{"/bin/sh", "-c", "echo ~" + user}
).getInputStream()
)
).readLine();
static public String getHomeDir(String user) throws Exception {
Process p = PApplet.exec("/bin/sh", "-c", "echo ~" + user);
return PApplet.createReader(p.getInputStream()).readLine();
}
// Java sets user.home to be /root for execution with sudo
// This method attempts to use the user's real home direcory
// instead.
public File getSettingsFolder() throws Exception {
return new File(getHomeDir(), ".processing");
}
// Java sets user.home to be /root for execution with sudo
// This method attempts to use the user's real home direcory
// instead.
public File getDefaultSketchbookFolder() throws Exception {
return new File(getHomeDir(), "sketchbook");
}
+6
View File
@@ -1,5 +1,11 @@
0261 (3.3.4 or 3.4)
jakub
X Fix keyPressed for multiple keys
X https://github.com/processing/processing/pull/5050
X https://github.com/processing/processing/issues/5049
_ WARNING: GL pipe is running in software mode (Renderer ID=0x1020400)
_ is this coming from us? if so, need to provide actions
+3
View File
@@ -20,6 +20,9 @@ X discovered during https://github.com/processing/processing/issues/4980
gohai
X IO library updates
X https://github.com/processing/processing/pull/5044
X Consider $SUDO_USER on Linux for locating the sketchbook folder
X https://github.com/processing/processing/pull/5055
o https://github.com/processing/processing/pull/5054
_ sketch.properties not being written if initial mode is p5.js?
_ when creating a sketch within non-Java mode, should write the settings file