From 6ff0ea6d186b3c5158f87cd522ec72d648eb2258 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 30 Nov 2013 01:55:48 -0500 Subject: [PATCH] Add -zoterodebug command-line flag to force debug output This should make it much easier to debug startup errors, particularly in Standalone. This also adds a general mechanism to set Zotero initialization options via command-line flags. --- chrome/content/zotero/xpcom/debug.js | 4 ++-- chrome/content/zotero/xpcom/zotero.js | 8 ++++++-- components/zotero-service.js | 24 ++++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js index 97ff76f382..786ed33927 100644 --- a/chrome/content/zotero/xpcom/debug.js +++ b/chrome/content/zotero/xpcom/debug.js @@ -27,8 +27,8 @@ Zotero.Debug = new function () { var _console, _stackTrace, _store, _level, _time, _lastTime, _output = []; - this.init = function () { - _console = Zotero.Prefs.get('debug.log'); + this.init = function (forceDebugLog) { + _console = forceDebugLog || Zotero.Prefs.get('debug.log'); _store = Zotero.Prefs.get('debug.store'); if (_store) { Zotero.Prefs.set('debug.store', false); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index d3f6cc8294..dd777d21d7 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -218,14 +218,18 @@ Components.utils.import("resource://gre/modules/Services.jsm"); /** * Initialize the extension */ - function init() { + function init(options) { if (this.initialized || this.skipLoading) { return false; } // Load in the preferences branch for the extension Zotero.Prefs.init(); - Zotero.Debug.init(); + Zotero.Debug.init(options && options.forceDebugLog); + + if (options) { + if (options.openPane) this.openPane = true; + } this.mainThread = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread; diff --git a/components/zotero-service.js b/components/zotero-service.js index 44a1ff2cb0..433cad5b9c 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -125,6 +125,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); var instanceID = (new Date()).getTime(); var isFirstLoadThisSession = true; var zContext = null; +var zInitOptions = {}; ZoteroContext = function() {} ZoteroContext.prototype = { @@ -169,7 +170,7 @@ ZoteroContext.prototype = { zContext.Zotero.shutdown().then(function() { // create a new zContext makeZoteroContext(isConnector); - zContext.Zotero.init(); + zContext.Zotero.init(zInitOptions); }).done(); } @@ -292,12 +293,12 @@ function ZoteroService() { if(isFirstLoadThisSession) { makeZoteroContext(false); try { - zContext.Zotero.init(); + zContext.Zotero.init(zInitOptions); } catch(e) { // if Zotero should start as a connector, reload it zContext.Zotero.shutdown().then(function() { makeZoteroContext(true); - zContext.Zotero.init(); + zContext.Zotero.init(zInitOptions); }).done(); } } @@ -341,6 +342,16 @@ function ZoteroCommandLineHandler() {} ZoteroCommandLineHandler.prototype = { /* nsICommandLineHandler */ handle : function(cmdLine) { + // Force debug output + if (cmdLine.handleFlag("zoterodebug", false)) { + zInitOptions.forceDebugLog = true; + } + + // handler to open Zotero pane at startup in Zotero for Firefox + if (!isStandalone() && cmdLine.handleFlag("ZoteroPaneOpen", false)) { + zInitOptions.openPane = true; + } + // handler for Zotero integration commands // this is typically used on Windows only, via WM_COPYDATA rather than the command line var agent = cmdLine.handleFlagWithParam("ZoteroIntegrationAgent", false); @@ -415,13 +426,6 @@ ZoteroCommandLineHandler.prototype = { } } } - // handler to open Zotero pane at startup in Zotero for Firefox - else { - var zPaneOpen = cmdLine.handleFlag("ZoteroPaneOpen", false); - if (zPaneOpen) { - this.Zotero.openPane = true; - } - } }, contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=zotero",