Only load carbon once

This commit is contained in:
Simon Kornblith 2012-01-10 17:49:25 -05:00
parent 5a7c7368b7
commit 3c61a4eae8

View file

@ -43,6 +43,7 @@ Zotero.Integration = new function() {
// these need to be global because of GC // these need to be global because of GC
var _updateTimer; var _updateTimer;
var _carbon, ProcessSerialNumber, SetFrontProcessWithOptions;
var _inProgress = false; var _inProgress = false;
this.currentWindow = false; this.currentWindow = false;
@ -276,14 +277,15 @@ Zotero.Integration = new function() {
}; };
if(Zotero.isFx4 && win) { if(Zotero.isFx4 && win) {
const carbon = ctypes.open("/System/Library/Frameworks/Carbon.framework/Carbon"); if(!_carbon) {
_carbon = ctypes.open("/System/Library/Frameworks/Carbon.framework/Carbon");
/* /*
* struct ProcessSerialNumber { * struct ProcessSerialNumber {
* unsigned long highLongOfPSN; * unsigned long highLongOfPSN;
* unsigned long lowLongOfPSN; * unsigned long lowLongOfPSN;
* }; * };
*/ */
const ProcessSerialNumber = new ctypes.StructType("ProcessSerialNumber", ProcessSerialNumber = new ctypes.StructType("ProcessSerialNumber",
[{"highLongOfPSN":ctypes.uint32_t}, {"lowLongOfPSN":ctypes.uint32_t}]); [{"highLongOfPSN":ctypes.uint32_t}, {"lowLongOfPSN":ctypes.uint32_t}]);
/* /*
@ -292,8 +294,10 @@ Zotero.Integration = new function() {
* OptionBits inOptions * OptionBits inOptions
* ); * );
*/ */
const SetFrontProcessWithOptions = carbon.declare("SetFrontProcessWithOptions", SetFrontProcessWithOptions = _carbon.declare("SetFrontProcessWithOptions",
ctypes.default_abi, ctypes.int32_t, ProcessSerialNumber.ptr, ctypes.uint32_t); ctypes.default_abi, ctypes.int32_t, ProcessSerialNumber.ptr,
ctypes.uint32_t);
}
var psn = new ProcessSerialNumber(); var psn = new ProcessSerialNumber();
psn.highLongOfPSN = 0; psn.highLongOfPSN = 0;
@ -304,7 +308,6 @@ Zotero.Integration = new function() {
psn.address(), psn.address(),
1 // kSetFrontProcessFrontWindowOnly = (1 << 0) 1 // kSetFrontProcessFrontWindowOnly = (1 << 0)
); );
carbon.close();
}, false); }, false);
} else { } else {
if(Zotero.oscpu == "PPC Mac OS X 10.4" || Zotero.oscpu == "Intel Mac OS X 10.4" if(Zotero.oscpu == "PPC Mac OS X 10.4" || Zotero.oscpu == "Intel Mac OS X 10.4"