Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix qz:steal on macOS #1309

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions 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
Loading