Skip to content

Commit af50607

Browse files
committed
macOS: wrap sketch in .app bundle for proper window server access
1 parent 171213c commit af50607

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

mode/CppMode.jar

504 Bytes
Binary file not shown.

src/java/CppRunner.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,27 @@ public void launch() {
3535
}
3636
ProcessBuilder pb;
3737
if (System.getProperty("os.name","").toLowerCase().contains("mac")) {
38-
// macOS: use open command to properly register with window server
39-
pb = new ProcessBuilder("open", "-W", "-n", "-a", exeToRun.getAbsolutePath());
38+
// macOS: wrap in minimal .app bundle so the process gets window server access
39+
java.io.File appBundle = new java.io.File(sketchFolder, exeToRun.getName() + ".app");
40+
java.io.File macosDir = new java.io.File(appBundle, "Contents/MacOS");
41+
macosDir.mkdirs();
42+
java.io.File bundledBin = new java.io.File(macosDir, exeToRun.getName());
43+
java.nio.file.Files.copy(exeToRun.toPath(), bundledBin.toPath(),
44+
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
45+
bundledBin.setExecutable(true);
46+
// Write minimal Info.plist
47+
java.io.File plist = new java.io.File(appBundle, "Contents/Info.plist");
48+
java.nio.file.Files.writeString(plist.toPath(),
49+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
50+
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
51+
+ "<plist version=\"1.0\"><dict>\n"
52+
+ "<key>CFBundleExecutable</key><string>" + exeToRun.getName() + "</string>\n"
53+
+ "<key>CFBundleIdentifier</key><string>processing.cpp." + exeToRun.getName() + "</string>\n"
54+
+ "<key>CFBundleName</key><string>" + exeToRun.getName() + "</string>\n"
55+
+ "<key>NSHighResolutionCapable</key><true/>\n"
56+
+ "<key>NSPrincipalClass</key><string>NSApplication</string>\n"
57+
+ "</dict></plist>\n");
58+
pb = new ProcessBuilder("open", "-W", "-n", appBundle.getAbsolutePath());
4059
} else {
4160
pb = new ProcessBuilder(exeToRun.getAbsolutePath());
4261
}

0 commit comments

Comments
 (0)