mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
finishing up protocol handler for Windows
This commit is contained in:
@@ -1362,31 +1362,35 @@ public class Base {
|
||||
|
||||
|
||||
/**
|
||||
* Handling pde:// URLs
|
||||
* @param location everything after pde://
|
||||
* Handler for pde:// protocol URIs
|
||||
* @param schemeUri the full URI, including 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);
|
||||
public Editor handleScheme(String schemeUri) {
|
||||
String location = schemeUri.substring(6);
|
||||
if (location.length() > 0) {
|
||||
// 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))) {
|
||||
return handleOpen(tempFile.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("Could not open " + tempFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1395,6 +1399,10 @@ public class Base {
|
||||
* Note that the user may have selected/double-clicked any .pde in a sketch.
|
||||
*/
|
||||
public Editor handleOpen(String path) {
|
||||
if (path.startsWith("pde://")) {
|
||||
return handleScheme(path);
|
||||
}
|
||||
|
||||
if (path.endsWith(SKETCH_BUNDLE_EXT)) {
|
||||
return openSketchBundle(path);
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ package processing.app.platform;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Font;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -39,7 +37,6 @@ import com.sun.jna.Native;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.Util;
|
||||
import processing.app.ui.Toolkit;
|
||||
import processing.awt.ShimAWT;
|
||||
import processing.core.PApplet;
|
||||
|
||||
@@ -33,7 +33,6 @@ 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;
|
||||
@@ -95,11 +94,12 @@ public class MacPlatform extends DefaultPlatform {
|
||||
|
||||
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);
|
||||
}
|
||||
// URI uri = event.getURI();
|
||||
base.handleScheme(event.getURI().toString());
|
||||
// String location = uri.toString().substring(6);
|
||||
// if (location.length() > 0) {
|
||||
// base.handleLocation(location);
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user