mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
refactor b/c uri handlers not supported on Windows or Linux
This commit is contained in:
@@ -1361,6 +1361,35 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handling pde:// URLs
|
||||
* @param location everything after pde://
|
||||
*/
|
||||
public void handleLocation(String location) {
|
||||
// if it leads with a slash, then it's a file url
|
||||
if (location.charAt(0) == '/') {
|
||||
handleOpen(location); // it's a full path to a file
|
||||
} else {
|
||||
// turn it into an https url
|
||||
final String url = "https://" + location;
|
||||
if (location.toLowerCase().endsWith(".pdez") ||
|
||||
location.toLowerCase().endsWith(".pdex")) {
|
||||
String extension = location.substring(location.length() - 5);
|
||||
try {
|
||||
File tempFile = File.createTempFile("scheme", extension);
|
||||
if (PApplet.saveStream(tempFile, Util.createInput(url))) {
|
||||
handleOpen(tempFile.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("Could not open " + tempFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a sketch from the path specified. Do not use for untitled sketches.
|
||||
* Note that the user may have selected/double-clicked any .pde in a sketch.
|
||||
|
||||
@@ -98,37 +98,6 @@ public class DefaultPlatform {
|
||||
|
||||
public void initBase(Base base) {
|
||||
this.base = base;
|
||||
|
||||
final Desktop desktop = Desktop.getDesktop();
|
||||
desktop.setOpenURIHandler((event) -> {
|
||||
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URI.html
|
||||
URI uri = event.getURI();
|
||||
String location = uri.toString().substring(6);
|
||||
if (location.length() > 0) {
|
||||
System.out.println("location is " + location);
|
||||
// if it leads with a slash, then it's a file url
|
||||
if (location.charAt(0) == '/') {
|
||||
base.handleOpen(location); // it's a full path to a file
|
||||
} else {
|
||||
// turn it into an https url
|
||||
final String url = "https://" + location;
|
||||
if (location.toLowerCase().endsWith(".pdez") ||
|
||||
location.toLowerCase().endsWith(".pdex")) {
|
||||
String extension = location.substring(location.length() - 5);
|
||||
try {
|
||||
File tempFile = File.createTempFile("scheme", extension);
|
||||
if (PApplet.saveStream(tempFile, Util.createInput(url))) {
|
||||
base.handleOpen(tempFile.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("Could not open " + tempFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import javax.swing.JMenuBar;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Messages;
|
||||
import processing.app.Util;
|
||||
import processing.app.ui.About;
|
||||
import processing.core.PApplet;
|
||||
import processing.data.StringList;
|
||||
@@ -91,6 +92,15 @@ public class MacPlatform extends DefaultPlatform {
|
||||
quitResponse.cancelQuit();
|
||||
}
|
||||
});
|
||||
|
||||
desktop.setOpenURIHandler((event) -> {
|
||||
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URI.html
|
||||
URI uri = event.getURI();
|
||||
String location = uri.toString().substring(6);
|
||||
if (location.length() > 0) {
|
||||
base.handleLocation(location);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
todo.txt
1
todo.txt
@@ -6,6 +6,7 @@ _ https://github.com/processing/processing4/issues/666
|
||||
_ add a protocol handler for pdex and pdez
|
||||
_ https://github.com/processing/processing4/issues/559
|
||||
X implemented for macOS
|
||||
_ Windows implementation https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=94914f2852f0c32e60361648ec82da153b8d70ae
|
||||
_ need to also warn people about running 'em
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user