Remove all uses of Zotero.isStandalone

(View diff with -w)
This commit is contained in:
Dan Stillman 2023-07-11 05:34:04 -04:00
parent 4b7a1e8607
commit 8d3f874e64
7 changed files with 245 additions and 316 deletions

View file

@ -982,7 +982,7 @@ Zotero.DataDirectory = {
false,
null,
// Don't show message in a popup in Standalone if pane isn't ready
Zotero.isStandalone
true
);
}
catch (e) {
@ -1005,7 +1005,7 @@ Zotero.DataDirectory = {
// Clear status line from progress meter
try {
Zotero.showZoteroPaneProgressMeter("", false, null, Zotero.isStandalone);
Zotero.showZoteroPaneProgressMeter("", false, null, true);
}
catch (e) {
Zotero.logError(e);

View file

@ -70,16 +70,14 @@ Zotero.Debug = new function () {
this.storing = _store;
this.updateEnabled();
if (Zotero.isStandalone) {
// Enable dump() from window (non-XPCOM) scopes when terminal or viewer logging is enabled.
// (These will always go to the terminal, even in viewer mode.)
Zotero.Prefs.set('browser.dom.window.dump.enabled', _console || _consoleViewer || Zotero.test, true);
if (_consoleViewer) {
setTimeout(function () {
Zotero.openInViewer("chrome://zotero/content/debugViewer.html");
}, 1000);
}
// Enable dump() from window (non-XPCOM) scopes when terminal or viewer logging is enabled.
// (These will always go to the terminal, even in viewer mode.)
Zotero.Prefs.set('browser.dom.window.dump.enabled', _console || _consoleViewer || Zotero.test, true);
if (_consoleViewer) {
setTimeout(function () {
Zotero.openInViewer("chrome://zotero/content/debugViewer.html");
}, 1000);
}
}

View file

@ -949,8 +949,7 @@ Zotero.HTTP = new function() {
* to wait for proxy authentication can wait for that promise.
*/
this.triggerProxyAuth = function () {
if (!Zotero.isStandalone
|| !Zotero.Prefs.get("triggerProxyAuthentication")
if (!Zotero.Prefs.get("triggerProxyAuthentication")
|| Zotero.HTTP.browserIsOffline()) {
Zotero.proxyAuthComplete = Zotero.Promise.resolve();
return false;

View file

@ -92,8 +92,7 @@ Zotero.Profile = {
/**
* Get the path to the Profiles directory of the other app from this one (Firefox or Zotero),
* which may or may not exist
* Get the path to the Firefox Profiles directory, which may or may not exist
*
* @return {String|null} - Path, or null if none due to filesystem location
*/
@ -103,26 +102,14 @@ Zotero.Profile = {
return null;
}
if (Zotero.isStandalone) {
if (Zotero.isWin) {
dir = OS.Path.join(OS.Path.dirname(dir), "Mozilla", "Firefox");
}
else if (Zotero.isMac) {
dir = OS.Path.join(dir, "Firefox");
}
else {
dir = OS.Path.join(dir, ".mozilla", "firefox");
}
if (Zotero.isWin) {
dir = OS.Path.join(OS.Path.dirname(dir), "Mozilla", "Firefox");
}
else if (Zotero.isMac) {
dir = OS.Path.join(dir, "Firefox");
}
else {
if (Zotero.isWin) {
dir = OS.Path.join(OS.Path.dirname(dir), "Zotero", "Zotero");
}
else if (Zotero.isMac) {
dir = OS.Path.join(dir, "Zotero");
} else {
dir = OS.Path.join(dir, ".zotero", "zotero");
}
dir = OS.Path.join(dir, ".mozilla", "firefox");
}
return OS.Path.join(dir, "Profiles");

View file

@ -348,7 +348,7 @@ Zotero.Schema = new function(){
}, 250);
}
}
}.bind(this), Zotero.isStandalone ? 1000 : 0);
}.bind(this), 1000);
});
return updated;
@ -928,37 +928,10 @@ Zotero.Schema = new function(){
// Get path to add-on
// Synchronous in Standalone
if (Zotero.isStandalone) {
var installLocation = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("AChrom", Components.interfaces.nsIFile).parent;
installLocation.append("omni.ja");
}
// Asynchronous in Firefox
else {
let resolve, reject;
let promise = new Zotero.Promise(function () {
resolve = arguments[0];
reject = arguments[1];
});
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID(
ZOTERO_CONFIG.GUID,
function (addon) {
try {
installLocation = addon.getResourceURI()
.QueryInterface(Components.interfaces.nsIFileURL).file;
}
catch (e) {
reject(e);
return;
}
resolve();
}
);
await promise;
}
var installLocation = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("AChrom", Components.interfaces.nsIFile).parent;
installLocation.append("omni.ja");
installLocation = installLocation.path;
let initOpts = { fromSchemaUpdate: true };

View file

@ -209,23 +209,9 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
this.platformMajorVersion = parseInt(this.platformVersion.match(/^[0-9]+/)[0]);
this.isFx = true;
this.isClient = true;
this.isStandalone = Services.appinfo.ID == ZOTERO_CONFIG['GUID'];
this.isStandalone = true;
if (Zotero.isStandalone) {
var version = Services.appinfo.version;
}
else {
let deferred = Zotero.Promise.defer();
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID(
ZOTERO_CONFIG.GUID,
function (addon) {
deferred.resolve(addon.version);
}
);
var version = await deferred.promise;
}
Zotero.version = version;
Zotero.version = Services.appinfo.version;
Zotero.isDevBuild = Zotero.version.includes('beta')
|| Zotero.version.includes('dev')
|| Zotero.version.includes('SOURCE');
@ -244,14 +230,21 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
// Browser
Zotero.browser = "g";
if (this.isWin) {
let branch = Services.prefs.getBranch("toolkit.startup.");
if (branch.getUserPref('recent_crashes') > 2) {
branch.clearUserPref('recent_crashes');
}
}
Zotero.Intl.init();
if (this.restarting) return;
await Zotero.Prefs.init();
Zotero.Debug.init(options && options.forceDebugLog);
// Make sure that Zotero Standalone is not running as root
if(Zotero.isStandalone && !Zotero.isWin) _checkRoot();
// Make sure that Zotero isn't running as root
if (!Zotero.isWin) _checkRoot();
if (!_checkExecutableLocation()) {
return;
@ -405,7 +398,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
return false;
}
if (Zotero.isStandalone) Zotero.Standalone.init();
Zotero.Standalone.init();
await Zotero.initComplete();
};
@ -545,55 +538,53 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
try {
// Require >=2.1b3 database to ensure proper locking
if (Zotero.isStandalone) {
let dbSystemVersion = yield Zotero.Schema.getDBVersion('system');
if (dbSystemVersion > 0 && dbSystemVersion < 31) {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.createInstance(Components.interfaces.nsIPromptService);
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_POS_2_DEFAULT;
var index = ps.confirmEx(
null,
Zotero.getString('dataDir.incompatibleDbVersion.title'),
Zotero.getString('dataDir.incompatibleDbVersion.text'),
buttonFlags,
Zotero.getString('general.useDefault'),
Zotero.getString('dataDir.chooseNewDataDirectory'),
Zotero.getString('general.quit'),
null,
{}
let dbSystemVersion = yield Zotero.Schema.getDBVersion('system');
if (dbSystemVersion > 0 && dbSystemVersion < 31) {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.createInstance(Components.interfaces.nsIPromptService);
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_POS_2_DEFAULT;
var index = ps.confirmEx(
null,
Zotero.getString('dataDir.incompatibleDbVersion.title'),
Zotero.getString('dataDir.incompatibleDbVersion.text'),
buttonFlags,
Zotero.getString('general.useDefault'),
Zotero.getString('dataDir.chooseNewDataDirectory'),
Zotero.getString('general.quit'),
null,
{}
);
var quit = false;
// Default location
if (index == 0) {
Zotero.Prefs.set("useDataDir", false)
Services.startup.quit(
Components.interfaces.nsIAppStartup.eAttemptQuit
| Components.interfaces.nsIAppStartup.eRestart
);
var quit = false;
// Default location
if (index == 0) {
Zotero.Prefs.set("useDataDir", false)
Services.startup.quit(
Components.interfaces.nsIAppStartup.eAttemptQuit
| Components.interfaces.nsIAppStartup.eRestart
);
}
// Select new data directory
else if (index == 1) {
let dir = yield Zotero.DataDirectory.choose(true);
if (!dir) {
quit = true;
}
}
else {
}
// Select new data directory
else if (index == 1) {
let dir = yield Zotero.DataDirectory.choose(true);
if (!dir) {
quit = true;
}
if (quit) {
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
}
throw true;
}
else {
quit = true;
}
if (quit) {
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
}
throw true;
}
try {

View file

@ -328,10 +328,7 @@ function makeZoteroContext(isConnector) {
subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/translate/src/" + rdfXpcomFiles[i] + ".js", zContext.Zotero.RDF, 'utf-8');
}
if(isStandalone()) {
// If isStandalone, load standalone.js
subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/standalone.js", zContext, 'utf-8');
}
subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/standalone.js", zContext);
// add connector-related properties
zContext.Zotero.isConnector = isConnector;
@ -355,74 +352,66 @@ function ZoteroService() {
if (!zContext.Zotero.startupError) {
zContext.Zotero.startupError = e.stack || e;
}
if (!isStandalone()) {
throw e;
}
})
.then(function () {
if (isStandalone()) {
if (zContext.Zotero.startupErrorHandler || zContext.Zotero.startupError) {
if (zContext.Zotero.startupErrorHandler) {
zContext.Zotero.startupErrorHandler();
}
else if (zContext.Zotero.startupError) {
// Try to repair the DB on the next startup, in case it helps resolve
// the error
try {
zContext.Zotero.Schema.setIntegrityCheckRequired(true);
}
catch (e) {}
try {
zContext.Zotero.startupError =
zContext.Zotero.Utilities.Internal.filterStack(
zContext.Zotero.startupError
);
}
catch (e) {}
let ps = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING);
// Get the stringbundle manually
let errorStr = "Error";
let quitStr = "Quit";
let checkForUpdateStr = "Check for Update";
try {
let src = 'chrome://zotero/locale/zotero.properties';
let stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
let stringBundle = stringBundleService.createBundle(src);
errorStr = stringBundle.GetStringFromName('general.error');
checkForUpdateStr = stringBundle.GetStringFromName('general.checkForUpdate');
quitStr = stringBundle.GetStringFromName('general.quit');
}
catch (e) {}
let index = ps.confirmEx(
null,
errorStr,
zContext.Zotero.startupError,
buttonFlags,
checkForUpdateStr,
quitStr,
null,
null,
{}
);
if (index == 0) {
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://mozapps/content/update/updates.xul',
'updateChecker', 'chrome,centerscreen,modal', null);
}
}
zContext.Zotero.Utilities.Internal.quitZotero();
if (zContext.Zotero.startupErrorHandler || zContext.Zotero.startupError) {
if (zContext.Zotero.startupErrorHandler) {
zContext.Zotero.startupErrorHandler();
}
return;
else if (zContext.Zotero.startupError) {
// Try to repair the DB on the next startup, in case it helps resolve
// the error
try {
zContext.Zotero.Schema.setIntegrityCheckRequired(true);
}
catch (e) {}
try {
zContext.Zotero.startupError =
zContext.Zotero.Utilities.Internal.filterStack(
zContext.Zotero.startupError
);
}
catch (e) {}
let ps = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING);
// Get the stringbundle manually
let errorStr = "Error";
let quitStr = "Quit";
let checkForUpdateStr = "Check for Update";
try {
let src = 'chrome://zotero/locale/zotero.properties';
let stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
let stringBundle = stringBundleService.createBundle(src);
errorStr = stringBundle.GetStringFromName('general.error');
checkForUpdateStr = stringBundle.GetStringFromName('general.checkForUpdate');
quitStr = stringBundle.GetStringFromName('general.quit');
}
catch (e) {}
let index = ps.confirmEx(
null,
errorStr,
zContext.Zotero.startupError,
buttonFlags,
checkForUpdateStr,
quitStr,
null,
null,
{}
);
if (index == 0) {
Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher)
.openWindow(null, 'chrome://mozapps/content/update/updates.xul',
'updateChecker', 'chrome,centerscreen,modal', null);
}
}
zContext.Zotero.Utilities.Internal.quitZotero();
}
zContext.Zotero.debug("Initialized in "+(Date.now() - start)+" ms");
isFirstLoadThisSession = false;
});
let cb;
@ -457,7 +446,6 @@ function addInitCallback(callback) {
}
}
var _isStandalone = null;
/**
* Determine whether Zotero Standalone is running
*/
@ -505,11 +493,6 @@ ZoteroCommandLineHandler.prototype = {
zInitOptions.forceDataDir = cmdLine.handleFlagWithParam("datadir", false);
// handler to open Zotero pane at startup in Zotero for Firefox
if (!isStandalone() && cmdLine.handleFlag("ZoteroPaneOpen", false)) {
zInitOptions.openPane = true;
}
if (cmdLine.handleFlag("ZoteroTest", false)) {
zInitOptions.test = true;
}
@ -535,126 +518,124 @@ ZoteroCommandLineHandler.prototype = {
zContext.Zotero.Integration.execCommand(agent, command, docId, templateVersion);
}
if(isStandalone()) {
var fileToOpen;
// Handle zotero:// and file URIs and prevent them from opening a new window
var param = cmdLine.handleFlagWithParam("url", false);
if (param) {
cmdLine.preventDefault = true;
var uri = cmdLine.resolveURI(param);
if (uri.schemeIs("zotero")) {
addInitCallback(function (Zotero) {
Zotero.uiReadyPromise
.then(function () {
// Check for existing window and focus it
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
if (win) {
win.focus();
win.ZoteroPane.loadURI(uri.spec)
}
});
});
}
// See below
else if (uri.schemeIs("file")) {
Components.utils.import("resource://gre/modules/osfile.jsm")
fileToOpen = OS.Path.fromFileURI(uri.spec)
}
else {
dump(`Not handling URL: ${uri.spec}\n\n`);
}
}
var fileToOpen;
// Handle zotero:// and file URIs and prevent them from opening a new window
var param = cmdLine.handleFlagWithParam("url", false);
if (param) {
cmdLine.preventDefault = true;
param = cmdLine.handleFlag("debugger", false);
if (param) {
try {
let portOrPath = Services.prefs.getBranch('').getIntPref('devtools.debugger.remote-port');
const { DevToolsLoader } = ChromeUtils.import(
"resource://devtools/shared/loader/Loader.jsm"
);
const loader = new DevToolsLoader({
freshCompartment: true,
});
const { DevToolsServer } = loader.require("devtools/server/devtools-server");
const { SocketListener } = loader.require("devtools/shared/security/socket");
if (DevToolsServer.initialized) {
dump("Debugger server already initialized\n\n");
return;
}
DevToolsServer.init();
DevToolsServer.registerAllActors();
DevToolsServer.allowChromeProcess = true;
const socketOptions = { portOrPath };
const listener = new SocketListener(DevToolsServer, socketOptions);
await listener.open();
if (!DevToolsServer.listeningSockets) {
throw new Error("No listening sockets");
}
dump(`Debugger server started on ${portOrPath}\n\n`);
}
catch (e) {
dump(e + "\n\n");
Components.utils.reportError(e);
}
}
// In Fx49-based Mac Standalone, if Zotero is closed, an associated file is launched, and
// Zotero hasn't been opened before, a -file parameter is passed and two main windows open.
// Subsequent file openings when closed result in -url with file:// URLs (converted above)
// and don't result in two windows. Here we prevent the double window.
param = fileToOpen;
if (!param) {
param = cmdLine.handleFlagWithParam("file", false);
if (param && isMac()) {
cmdLine.preventDefault = true;
}
}
if (param) {
var uri = cmdLine.resolveURI(param);
if (uri.schemeIs("zotero")) {
addInitCallback(function (Zotero) {
// Wait to handle things that require the UI until after it's loaded
Zotero.uiReadyPromise
.then(function () {
var file = Zotero.File.pathToFile(param);
if(file.leafName.substr(-4).toLowerCase() === ".csl"
|| file.leafName.substr(-8).toLowerCase() === ".csl.txt") {
// Install CSL file
Zotero.Styles.install({ file: file.path }, file.path);
} else {
// Ask before importing
var checkState = {
value: Zotero.Prefs.get('import.createNewCollection.fromFileOpenHandler')
};
if (Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService)
.confirmCheck(null, Zotero.getString('ingester.importFile.title'),
Zotero.getString('ingester.importFile.text', [file.leafName]),
Zotero.getString('ingester.importFile.intoNewCollection'),
checkState)) {
Zotero.Prefs.set(
'import.createNewCollection.fromFileOpenHandler', checkState.value
);
// Perform file import in front window
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
browserWindow.Zotero_File_Interface.importFile({
file,
createNewCollection: checkState.value
});
}
// Check for existing window and focus it
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
if (win) {
win.focus();
win.ZoteroPane.loadURI(uri.spec)
}
});
});
}
// See below
else if (uri.schemeIs("file")) {
Components.utils.import("resource://gre/modules/osfile.jsm")
fileToOpen = OS.Path.fromFileURI(uri.spec)
}
else {
dump(`Not handling URL: ${uri.spec}\n\n`);
}
}
param = cmdLine.handleFlag("debugger", false);
if (param) {
try {
let portOrPath = Services.prefs.getBranch('').getIntPref('devtools.debugger.remote-port');
const { DevToolsLoader } = ChromeUtils.import(
"resource://devtools/shared/loader/Loader.jsm"
);
const loader = new DevToolsLoader({
freshCompartment: true,
});
const { DevToolsServer } = loader.require("devtools/server/devtools-server");
const { SocketListener } = loader.require("devtools/shared/security/socket");
if (DevToolsServer.initialized) {
dump("Debugger server already initialized\n\n");
return;
}
DevToolsServer.init();
DevToolsServer.registerAllActors();
DevToolsServer.allowChromeProcess = true;
const socketOptions = { portOrPath };
const listener = new SocketListener(DevToolsServer, socketOptions);
await listener.open();
if (!DevToolsServer.listeningSockets) {
throw new Error("No listening sockets");
}
dump(`Debugger server started on ${portOrPath}\n\n`);
}
catch (e) {
dump(e + "\n\n");
Components.utils.reportError(e);
}
}
// In Fx49-based Mac Standalone, if Zotero is closed, an associated file is launched, and
// Zotero hasn't been opened before, a -file parameter is passed and two main windows open.
// Subsequent file openings when closed result in -url with file:// URLs (converted above)
// and don't result in two windows. Here we prevent the double window.
param = fileToOpen;
if (!param) {
param = cmdLine.handleFlagWithParam("file", false);
if (param && isMac()) {
cmdLine.preventDefault = true;
}
}
if (param) {
addInitCallback(function (Zotero) {
// Wait to handle things that require the UI until after it's loaded
Zotero.uiReadyPromise
.then(function () {
var file = Zotero.File.pathToFile(param);
if(file.leafName.substr(-4).toLowerCase() === ".csl"
|| file.leafName.substr(-8).toLowerCase() === ".csl.txt") {
// Install CSL file
Zotero.Styles.install({ file: file.path }, file.path);
} else {
// Ask before importing
var checkState = {
value: Zotero.Prefs.get('import.createNewCollection.fromFileOpenHandler')
};
if (Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService)
.confirmCheck(null, Zotero.getString('ingester.importFile.title'),
Zotero.getString('ingester.importFile.text', [file.leafName]),
Zotero.getString('ingester.importFile.intoNewCollection'),
checkState)) {
Zotero.Prefs.set(
'import.createNewCollection.fromFileOpenHandler', checkState.value
);
// Perform file import in front window
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
browserWindow.Zotero_File_Interface.importFile({
file,
createNewCollection: checkState.value
});
}
}
});
});
}
},