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.
This commit is contained in:
Dan Stillman 2013-11-30 01:55:48 -05:00
parent 8e276b30d4
commit 6ff0ea6d18
3 changed files with 22 additions and 14 deletions

View File

@ -27,8 +27,8 @@
Zotero.Debug = new function () { Zotero.Debug = new function () {
var _console, _stackTrace, _store, _level, _time, _lastTime, _output = []; var _console, _stackTrace, _store, _level, _time, _lastTime, _output = [];
this.init = function () { this.init = function (forceDebugLog) {
_console = Zotero.Prefs.get('debug.log'); _console = forceDebugLog || Zotero.Prefs.get('debug.log');
_store = Zotero.Prefs.get('debug.store'); _store = Zotero.Prefs.get('debug.store');
if (_store) { if (_store) {
Zotero.Prefs.set('debug.store', false); Zotero.Prefs.set('debug.store', false);

View File

@ -218,14 +218,18 @@ Components.utils.import("resource://gre/modules/Services.jsm");
/** /**
* Initialize the extension * Initialize the extension
*/ */
function init() { function init(options) {
if (this.initialized || this.skipLoading) { if (this.initialized || this.skipLoading) {
return false; return false;
} }
// Load in the preferences branch for the extension // Load in the preferences branch for the extension
Zotero.Prefs.init(); 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; this.mainThread = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread;

View File

@ -125,6 +125,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
var instanceID = (new Date()).getTime(); var instanceID = (new Date()).getTime();
var isFirstLoadThisSession = true; var isFirstLoadThisSession = true;
var zContext = null; var zContext = null;
var zInitOptions = {};
ZoteroContext = function() {} ZoteroContext = function() {}
ZoteroContext.prototype = { ZoteroContext.prototype = {
@ -169,7 +170,7 @@ ZoteroContext.prototype = {
zContext.Zotero.shutdown().then(function() { zContext.Zotero.shutdown().then(function() {
// create a new zContext // create a new zContext
makeZoteroContext(isConnector); makeZoteroContext(isConnector);
zContext.Zotero.init(); zContext.Zotero.init(zInitOptions);
}).done(); }).done();
} }
@ -292,12 +293,12 @@ function ZoteroService() {
if(isFirstLoadThisSession) { if(isFirstLoadThisSession) {
makeZoteroContext(false); makeZoteroContext(false);
try { try {
zContext.Zotero.init(); zContext.Zotero.init(zInitOptions);
} catch(e) { } catch(e) {
// if Zotero should start as a connector, reload it // if Zotero should start as a connector, reload it
zContext.Zotero.shutdown().then(function() { zContext.Zotero.shutdown().then(function() {
makeZoteroContext(true); makeZoteroContext(true);
zContext.Zotero.init(); zContext.Zotero.init(zInitOptions);
}).done(); }).done();
} }
} }
@ -341,6 +342,16 @@ function ZoteroCommandLineHandler() {}
ZoteroCommandLineHandler.prototype = { ZoteroCommandLineHandler.prototype = {
/* nsICommandLineHandler */ /* nsICommandLineHandler */
handle : function(cmdLine) { 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 // handler for Zotero integration commands
// this is typically used on Windows only, via WM_COPYDATA rather than the command line // this is typically used on Windows only, via WM_COPYDATA rather than the command line
var agent = cmdLine.handleFlagWithParam("ZoteroIntegrationAgent", false); 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", contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=zotero",