diff --git a/app/src/main/java/io/xpipe/app/launcher/LauncherCommand.java b/app/src/main/java/io/xpipe/app/launcher/LauncherCommand.java index 55bac0acf..6f6391ffb 100644 --- a/app/src/main/java/io/xpipe/app/launcher/LauncherCommand.java +++ b/app/src/main/java/io/xpipe/app/launcher/LauncherCommand.java @@ -11,6 +11,7 @@ import io.xpipe.core.process.OsType; import io.xpipe.core.util.XPipeDaemonMode; import io.xpipe.extension.event.ErrorEvent; import io.xpipe.extension.event.TrackEvent; +import io.xpipe.extension.util.ThreadHelper; import picocli.CommandLine; import java.awt.*; @@ -75,6 +76,14 @@ public class LauncherCommand implements Callable { con.performSimpleExchange( OpenExchange.Request.builder().arguments(inputs).build()); } + + if (OsType.getLocal().equals(OsType.MAC)) { + Desktop.getDesktop().setOpenURIHandler(e -> { + con.performSimpleExchange( + OpenExchange.Request.builder().arguments(List.of(e.getURI().toString())).build()); + }); + ThreadHelper.sleep(1000); + } } TrackEvent.info("Another instance is already running on this port. Quitting ..."); OperationMode.halt(0); diff --git a/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java b/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java index cf85e8852..a344ffbf6 100644 --- a/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java +++ b/app/src/main/java/io/xpipe/app/launcher/LauncherInput.java @@ -5,6 +5,7 @@ import io.xpipe.app.core.mode.OperationMode; import io.xpipe.core.impl.FileStore; import io.xpipe.extension.DataSourceProvider; import io.xpipe.extension.event.ErrorEvent; +import io.xpipe.extension.event.TrackEvent; import io.xpipe.extension.util.ActionProvider; import lombok.Getter; import lombok.Value; @@ -20,6 +21,8 @@ import java.util.List; public abstract class LauncherInput { public static void handle(List arguments) { + TrackEvent.withDebug("launcher", "Handling arguments").elements(arguments).handle(); + var all = new ArrayList(); arguments.forEach(s -> { try { diff --git a/extension/src/main/java/io/xpipe/extension/util/DesktopShortcuts.java b/extension/src/main/java/io/xpipe/extension/util/DesktopShortcuts.java index f3eed8dd3..359ebc0f7 100644 --- a/extension/src/main/java/io/xpipe/extension/util/DesktopShortcuts.java +++ b/extension/src/main/java/io/xpipe/extension/util/DesktopShortcuts.java @@ -45,39 +45,37 @@ public class DesktopShortcuts { private static void createMacOSShortcut(String target, String name) throws Exception { var icon = XPipeInstallation.getLocalDefaultInstallationIcon(); + var base = System.getProperty("user.home") + "/Desktop/" + name + ".app"; var content = String.format( """ #!/bin/bash open %s """, target); - var file = Path.of(System.getProperty("user.home") + "/Desktop/" + name + ".command").toRealPath(); - Files.writeString(file, content); - file.toFile().setExecutable(true); - var iconScriptContent = String.format( """ - iconSource="%s" - iconDestination="%s" - icon=/tmp/`basename $iconSource` - rsrc=/tmp/icon.rsrc - cp $iconSource $icon - sips -i $icon - DeRez -only icns $icon > $rsrc - SetFile -a C $iconDestination - Rez -append $rsrc -o $iconDestination - """, - icon, target); + iconSource="%s" + iconDestination="%s" + icon=/tmp/`basename $iconSource` + rsrc=/tmp/icon.rsrc + cp "$iconSource" "$icon" + sips -i "$icon" + DeRez -only icns "$icon" > "$rsrc" + SetFile -a C "$iconDestination" + touch $iconDestination/$'Icon\\r' + Rez -append $rsrc -o $iconDestination/Icon? + SetFile -a V $iconDestination/Icon? + """, + icon, base); try (var pc = ShellStore.local().create().start()) { - var base = System.getProperty("user.home") + "/Desktop/" + name; pc.executeSimpleCommand(pc.getShellType().flatten(pc.getShellType().getMkdirsCommand(base + "/Contents/MacOS"))); - var executable = base + "/Contents/MacOS/" + name + ".sh"; + var executable = base + "/Contents/MacOS/" + name; pc.executeSimpleCommand(pc.getShellType().getTextFileWriteCommand(content, executable)); - pc.executeSimpleCommand(pc.getShellType().getMakeExecutableCommand(executable)); + pc.executeSimpleCommand("chmod ugo+x \"" + executable + "\""); - pc.executeSimpleCommand(pc.getShellType().getTextFileWriteCommand("APPL??", base + "/PkgInfo")); + pc.executeSimpleCommand(pc.getShellType().getTextFileWriteCommand("APPL????", base + "/PkgInfo")); pc.executeSimpleCommand(iconScriptContent); } }