Skip to content

Commit

Permalink
Initial attempt at uri handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Dec 13, 2024
1 parent 71c1c48 commit 46c51a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/qz/common/TrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ private void addMenuItems() {
componentList.add(aboutDialog);

if (SystemUtilities.isMac()) {
MacUtilities.registerUriHandler();
MacUtilities.registerAboutDialog(aboutDialog);
MacUtilities.registerQuitHandler(this);
}
Expand Down
25 changes: 24 additions & 1 deletion src/qz/utils/MacUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -68,6 +69,28 @@ public static void registerAboutDialog(Dialog aboutDialog) {
}
}

/**
* Configure macOS to intercept URIs when app is running
* See also: https://github.com/qzind/tray/issues/850
*/
public static void registerUriHandler() {
Desktop.getDesktop().setOpenURIHandler(e -> {
// TODO: Filter for "qz:launch"
URI uri = e.getURI();
log.warn("Scheme: {}, Host: {}, Path: {}, ", uri.getScheme(), uri.getHost(), uri.getPath());
//if(uri.getScheme().equals(Constants.DATA_DIR)) {
//if(uri.getScheme().equals()) {
ShellUtilities.execute("/usr/bin/open",
// Open a new instance of the application even if one is already running.
"-n",
// Opens the specified application.
"-a", Constants.ABOUT_TITLE,
// All remaining arguments are passed to the opened application in the argv parameter to main().
// These arguments are not opened or interpreted by the open tool.
"--args", ArgValue.STEAL.getMatch());
});
}

/**
* Calculates CFBundleIdentifier for macOS
* @return
Expand Down Expand Up @@ -113,7 +136,7 @@ public static void registerQuitHandler(TrayManager trayManager) {
}

/**
* Runs a shell command to determine if "Dark" desktop theme is enabled
* Runs a shell command to determine if "Dark" top theme is enabled
* @return true if enabled, false if not
*/
public static boolean isDarkDesktop() {
Expand Down

0 comments on commit 46c51a8

Please sign in to comment.