MacOS fixes

This commit is contained in:
crschnick 2023-02-05 19:57:14 +00:00
parent 45b4b84bf3
commit 137c6ff9f8
3 changed files with 29 additions and 19 deletions

View file

@ -11,6 +11,7 @@ import io.xpipe.core.process.OsType;
import io.xpipe.core.util.XPipeDaemonMode; import io.xpipe.core.util.XPipeDaemonMode;
import io.xpipe.extension.event.ErrorEvent; import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.event.TrackEvent; import io.xpipe.extension.event.TrackEvent;
import io.xpipe.extension.util.ThreadHelper;
import picocli.CommandLine; import picocli.CommandLine;
import java.awt.*; import java.awt.*;
@ -75,6 +76,14 @@ public class LauncherCommand implements Callable<Integer> {
con.performSimpleExchange( con.performSimpleExchange(
OpenExchange.Request.builder().arguments(inputs).build()); 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 ..."); TrackEvent.info("Another instance is already running on this port. Quitting ...");
OperationMode.halt(0); OperationMode.halt(0);

View file

@ -5,6 +5,7 @@ import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.core.impl.FileStore; import io.xpipe.core.impl.FileStore;
import io.xpipe.extension.DataSourceProvider; import io.xpipe.extension.DataSourceProvider;
import io.xpipe.extension.event.ErrorEvent; import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.event.TrackEvent;
import io.xpipe.extension.util.ActionProvider; import io.xpipe.extension.util.ActionProvider;
import lombok.Getter; import lombok.Getter;
import lombok.Value; import lombok.Value;
@ -20,6 +21,8 @@ import java.util.List;
public abstract class LauncherInput { public abstract class LauncherInput {
public static void handle(List<String> arguments) { public static void handle(List<String> arguments) {
TrackEvent.withDebug("launcher", "Handling arguments").elements(arguments).handle();
var all = new ArrayList<ActionProvider.Action>(); var all = new ArrayList<ActionProvider.Action>();
arguments.forEach(s -> { arguments.forEach(s -> {
try { try {

View file

@ -45,39 +45,37 @@ public class DesktopShortcuts {
private static void createMacOSShortcut(String target, String name) throws Exception { private static void createMacOSShortcut(String target, String name) throws Exception {
var icon = XPipeInstallation.getLocalDefaultInstallationIcon(); var icon = XPipeInstallation.getLocalDefaultInstallationIcon();
var base = System.getProperty("user.home") + "/Desktop/" + name + ".app";
var content = String.format( var content = String.format(
""" """
#!/bin/bash #!/bin/bash
open %s open %s
""", """,
target); 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( var iconScriptContent = String.format(
""" """
iconSource="%s" iconSource="%s"
iconDestination="%s" iconDestination="%s"
icon=/tmp/`basename $iconSource` icon=/tmp/`basename $iconSource`
rsrc=/tmp/icon.rsrc rsrc=/tmp/icon.rsrc
cp $iconSource $icon cp "$iconSource" "$icon"
sips -i $icon sips -i "$icon"
DeRez -only icns $icon > $rsrc DeRez -only icns "$icon" > "$rsrc"
SetFile -a C $iconDestination SetFile -a C "$iconDestination"
Rez -append $rsrc -o $iconDestination touch $iconDestination/$'Icon\\r'
""", Rez -append $rsrc -o $iconDestination/Icon?
icon, target); SetFile -a V $iconDestination/Icon?
""",
icon, base);
try (var pc = ShellStore.local().create().start()) { 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"))); 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().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); pc.executeSimpleCommand(iconScriptContent);
} }
} }