Use process id instead of bundle identifier to activate Mac app
This prevents a second copy of Zotero from being launched if you're running the Zotero beta and click on a word processor plugin button while a dialog is already open.
This commit is contained in:
parent
6e38c36804
commit
2acec4184a
1 changed files with 19 additions and 10 deletions
|
@ -2031,13 +2031,6 @@ Zotero.Utilities.Internal.activate = new function() {
|
|||
|
||||
return function(win) {
|
||||
if (Zotero.isMac) {
|
||||
const BUNDLE_IDS = {
|
||||
"Zotero":"org.zotero.zotero",
|
||||
"Firefox":"org.mozilla.firefox",
|
||||
"Aurora":"org.mozilla.aurora",
|
||||
"Nightly":"org.mozilla.nightly"
|
||||
};
|
||||
|
||||
if (win) {
|
||||
Components.utils.import("resource://gre/modules/ctypes.jsm");
|
||||
win.focus();
|
||||
|
@ -2075,7 +2068,13 @@ Zotero.Utilities.Internal.activate = new function() {
|
|||
);
|
||||
}, false);
|
||||
} else {
|
||||
Zotero.Utilities.Internal.executeAppleScript('tell application id "'+BUNDLE_IDS[Zotero.appName]+'" to activate');
|
||||
let pid = Zotero.Utilities.Internal.getProcessID();
|
||||
let script = `
|
||||
tell application "System Events"
|
||||
set frontmost of the first process whose unix id is ${pid} to true
|
||||
end tell
|
||||
`;
|
||||
Zotero.Utilities.Internal.executeAppleScript(script);
|
||||
}
|
||||
} else if(!Zotero.isWin && win) {
|
||||
Components.utils.import("resource://gre/modules/ctypes.jsm");
|
||||
|
@ -2289,16 +2288,26 @@ Zotero.Utilities.Internal.activate = new function() {
|
|||
|
||||
Zotero.Utilities.Internal.sendToBack = function() {
|
||||
if (Zotero.isMac) {
|
||||
let pid = Zotero.Utilities.Internal.getProcessID();
|
||||
Zotero.Utilities.Internal.executeAppleScript(`
|
||||
tell application "System Events"
|
||||
if frontmost of application id "org.zotero.zotero" then
|
||||
set visible of process "Zotero" to false
|
||||
set myProcess to first process whose unix id is ${pid}
|
||||
if frontmost of myProcess then
|
||||
set visible of myProcess to false
|
||||
end if
|
||||
end tell
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Zotero.Utilities.Internal.getProcessID = function () {
|
||||
return Components.classes["@mozilla.org/xre/app-info;1"]
|
||||
.getService(Components.interfaces.nsIXULRuntime)
|
||||
.processID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base64 encode / decode
|
||||
* From http://www.webtoolkit.info/
|
||||
|
|
Loading…
Add table
Reference in a new issue