Skip to content

Commit 46c51a8

Browse files
committed
Initial attempt at uri handling
1 parent 71c1c48 commit 46c51a8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/qz/common/TrayManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ private void addMenuItems() {
349349
componentList.add(aboutDialog);
350350

351351
if (SystemUtilities.isMac()) {
352+
MacUtilities.registerUriHandler();
352353
MacUtilities.registerAboutDialog(aboutDialog);
353354
MacUtilities.registerQuitHandler(this);
354355
}

src/qz/utils/MacUtilities.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.awt.event.ActionListener;
2727
import java.lang.reflect.Field;
2828
import java.lang.reflect.Method;
29+
import java.net.URI;
2930
import java.nio.file.Files;
3031
import java.nio.file.Path;
3132
import java.util.ArrayList;
@@ -68,6 +69,28 @@ public static void registerAboutDialog(Dialog aboutDialog) {
6869
}
6970
}
7071

72+
/**
73+
* Configure macOS to intercept URIs when app is running
74+
* See also: https://github.com/qzind/tray/issues/850
75+
*/
76+
public static void registerUriHandler() {
77+
Desktop.getDesktop().setOpenURIHandler(e -> {
78+
// TODO: Filter for "qz:launch"
79+
URI uri = e.getURI();
80+
log.warn("Scheme: {}, Host: {}, Path: {}, ", uri.getScheme(), uri.getHost(), uri.getPath());
81+
//if(uri.getScheme().equals(Constants.DATA_DIR)) {
82+
//if(uri.getScheme().equals()) {
83+
ShellUtilities.execute("/usr/bin/open",
84+
// Open a new instance of the application even if one is already running.
85+
"-n",
86+
// Opens the specified application.
87+
"-a", Constants.ABOUT_TITLE,
88+
// All remaining arguments are passed to the opened application in the argv parameter to main().
89+
// These arguments are not opened or interpreted by the open tool.
90+
"--args", ArgValue.STEAL.getMatch());
91+
});
92+
}
93+
7194
/**
7295
* Calculates CFBundleIdentifier for macOS
7396
* @return
@@ -113,7 +136,7 @@ public static void registerQuitHandler(TrayManager trayManager) {
113136
}
114137

115138
/**
116-
* Runs a shell command to determine if "Dark" desktop theme is enabled
139+
* Runs a shell command to determine if "Dark" top theme is enabled
117140
* @return true if enabled, false if not
118141
*/
119142
public static boolean isDarkDesktop() {

0 commit comments

Comments
 (0)