Skip to content

Commit 57ee4c6

Browse files
committed
finishing up protocol handler for Windows
1 parent f14389a commit 57ee4c6

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

app/src/processing/app/Base.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,31 +1362,35 @@ private File moveLikeSketchFolder(File pdeFile, String baseName) throws IOExcept
13621362

13631363

13641364
/**
1365-
* Handling pde:// URLs
1366-
* @param location everything after pde://
1365+
* Handler for pde:// protocol URIs
1366+
* @param schemeUri the full URI, including pde://
13671367
*/
1368-
public void handleLocation(String location) {
1369-
// if it leads with a slash, then it's a file url
1370-
if (location.charAt(0) == '/') {
1371-
handleOpen(location); // it's a full path to a file
1372-
} else {
1373-
// turn it into an https url
1374-
final String url = "https://" + location;
1375-
if (location.toLowerCase().endsWith(".pdez") ||
1376-
location.toLowerCase().endsWith(".pdex")) {
1377-
String extension = location.substring(location.length() - 5);
1378-
try {
1379-
File tempFile = File.createTempFile("scheme", extension);
1380-
if (PApplet.saveStream(tempFile, Util.createInput(url))) {
1381-
handleOpen(tempFile.getAbsolutePath());
1382-
} else {
1383-
System.err.println("Could not open " + tempFile);
1368+
public Editor handleScheme(String schemeUri) {
1369+
String location = schemeUri.substring(6);
1370+
if (location.length() > 0) {
1371+
// if it leads with a slash, then it's a file url
1372+
if (location.charAt(0) == '/') {
1373+
handleOpen(location); // it's a full path to a file
1374+
} else {
1375+
// turn it into an https url
1376+
final String url = "https://" + location;
1377+
if (location.toLowerCase().endsWith(".pdez") ||
1378+
location.toLowerCase().endsWith(".pdex")) {
1379+
String extension = location.substring(location.length() - 5);
1380+
try {
1381+
File tempFile = File.createTempFile("scheme", extension);
1382+
if (PApplet.saveStream(tempFile, Util.createInput(url))) {
1383+
return handleOpen(tempFile.getAbsolutePath());
1384+
} else {
1385+
System.err.println("Could not open " + tempFile);
1386+
}
1387+
} catch (IOException e) {
1388+
e.printStackTrace();
13841389
}
1385-
} catch (IOException e) {
1386-
e.printStackTrace();
13871390
}
13881391
}
13891392
}
1393+
return null;
13901394
}
13911395

13921396

@@ -1395,6 +1399,10 @@ public void handleLocation(String location) {
13951399
* Note that the user may have selected/double-clicked any .pde in a sketch.
13961400
*/
13971401
public Editor handleOpen(String path) {
1402+
if (path.startsWith("pde://")) {
1403+
return handleScheme(path);
1404+
}
1405+
13981406
if (path.endsWith(SKETCH_BUNDLE_EXT)) {
13991407
return openSketchBundle(path);
14001408

app/src/processing/app/platform/DefaultPlatform.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import java.awt.Desktop;
2727
import java.awt.Font;
2828
import java.io.File;
29-
import java.io.IOException;
30-
import java.net.URI;
3129

3230
import javax.swing.UIManager;
3331
import javax.swing.border.EmptyBorder;
@@ -39,7 +37,6 @@
3937

4038
import processing.app.Base;
4139
import processing.app.Preferences;
42-
import processing.app.Util;
4340
import processing.app.ui.Toolkit;
4441
import processing.awt.ShimAWT;
4542
import processing.core.PApplet;

app/src/processing/app/platform/MacPlatform.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import processing.app.Base;
3535
import processing.app.Messages;
36-
import processing.app.Util;
3736
import processing.app.ui.About;
3837
import processing.core.PApplet;
3938
import processing.data.StringList;
@@ -95,11 +94,12 @@ public void initBase(Base base) {
9594

9695
desktop.setOpenURIHandler((event) -> {
9796
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/URI.html
98-
URI uri = event.getURI();
99-
String location = uri.toString().substring(6);
100-
if (location.length() > 0) {
101-
base.handleLocation(location);
102-
}
97+
// URI uri = event.getURI();
98+
base.handleScheme(event.getURI().toString());
99+
// String location = uri.toString().substring(6);
100+
// if (location.length() > 0) {
101+
// base.handleLocation(location);
102+
// }
103103
});
104104
}
105105

0 commit comments

Comments
 (0)