From 3c61a4eae865f36130a0cdacd0a081bb2872ef9f Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 10 Jan 2012 17:49:25 -0500 Subject: [PATCH] Only load carbon once --- chrome/content/zotero/xpcom/integration.js | 41 ++++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 4842efb03..488a9e20e 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -43,6 +43,7 @@ Zotero.Integration = new function() { // these need to be global because of GC var _updateTimer; + var _carbon, ProcessSerialNumber, SetFrontProcessWithOptions; var _inProgress = false; this.currentWindow = false; @@ -276,24 +277,27 @@ Zotero.Integration = new function() { }; if(Zotero.isFx4 && win) { - const carbon = ctypes.open("/System/Library/Frameworks/Carbon.framework/Carbon"); - /* - * struct ProcessSerialNumber { - * unsigned long highLongOfPSN; - * unsigned long lowLongOfPSN; - * }; - */ - const ProcessSerialNumber = new ctypes.StructType("ProcessSerialNumber", - [{"highLongOfPSN":ctypes.uint32_t}, {"lowLongOfPSN":ctypes.uint32_t}]); - - /* - * OSStatus SetFrontProcessWithOptions ( - * const ProcessSerialNumber *inProcess, - * OptionBits inOptions - * ); - */ - const SetFrontProcessWithOptions = carbon.declare("SetFrontProcessWithOptions", - ctypes.default_abi, ctypes.int32_t, ProcessSerialNumber.ptr, ctypes.uint32_t); + if(!_carbon) { + _carbon = ctypes.open("/System/Library/Frameworks/Carbon.framework/Carbon"); + /* + * struct ProcessSerialNumber { + * unsigned long highLongOfPSN; + * unsigned long lowLongOfPSN; + * }; + */ + ProcessSerialNumber = new ctypes.StructType("ProcessSerialNumber", + [{"highLongOfPSN":ctypes.uint32_t}, {"lowLongOfPSN":ctypes.uint32_t}]); + + /* + * OSStatus SetFrontProcessWithOptions ( + * const ProcessSerialNumber *inProcess, + * OptionBits inOptions + * ); + */ + SetFrontProcessWithOptions = _carbon.declare("SetFrontProcessWithOptions", + ctypes.default_abi, ctypes.int32_t, ProcessSerialNumber.ptr, + ctypes.uint32_t); + } var psn = new ProcessSerialNumber(); psn.highLongOfPSN = 0; @@ -304,7 +308,6 @@ Zotero.Integration = new function() { psn.address(), 1 // kSetFrontProcessFrontWindowOnly = (1 << 0) ); - carbon.close(); }, false); } else { if(Zotero.oscpu == "PPC Mac OS X 10.4" || Zotero.oscpu == "Intel Mac OS X 10.4"