zotero/app/assets/commandLineHandler.js
Dan Stillman 13ab3bd87f fx115: Add command-line handling to Firefox command-line handler
XPCOM objects have to be statically registered now, so instead of
creating our own command-line handler, just stuff our code into the
Firefox one.

A few parameters require the Zotero object, which isn't available in the
Firefox CLH, so I've left those in zotero-service.js for now until we
decide how to deal with those.
2024-03-30 00:58:53 -04:00

90 lines
3.2 KiB
JavaScript

let { CommandLineOptions, TestOptions } = ChromeUtils.importESModule("chrome://zotero/content/modules/commandLineOptions.mjs");
// Force debug output to window
if (cmdLine.handleFlag("ZoteroDebug", false)) {
CommandLineOptions.forceDebugLog = 2;
}
// Force debug output to text console
else if (cmdLine.handleFlag("ZoteroDebugText", false)) {
CommandLineOptions.forceDebugLog = 1;
}
// Pressing Ctrl-C via the terminal is interpreted as a crash, and after three crashes
// Firefox starts up in automatic safe mode (troubleshooting mode). To avoid this, we clear the crash
// counter when using one of the debug-logging flags, which generally imply terminal usage.
if (CommandLineOptions.forceDebugLog) {
Services.prefs.getBranch("toolkit.startup.").clearUserPref("recent_crashes");
}
CommandLineOptions.forceDataDir = cmdLine.handleFlagWithParam("datadir", false);
var processTestOptions = false;
if (cmdLine.handleFlag("ZoteroTest", false)) {
CommandLineOptions.test = true;
processTestOptions = true;
}
if (cmdLine.handleFlag("ZoteroAutomatedTest", false)) {
CommandLineOptions.automatedTest = true;
}
if (cmdLine.handleFlag("ZoteroSkipBundledFiles", false)) {
CommandLineOptions.skipBundledFiles = true;
}
if (processTestOptions) {
TestOptions.tests = cmdLine.handleFlagWithParam("test", false);
TestOptions.noquit = cmdLine.handleFlag("noquit", false);
TestOptions.makeTestData = cmdLine.handleFlag("makeTestData", false);
TestOptions.noquit = !TestOptions.makeTestData && this.noquit;
TestOptions.runTests = !TestOptions.makeTestData;
TestOptions.bail = cmdLine.handleFlag("bail", false);
TestOptions.startAt = cmdLine.handleFlagWithParam("startAtTestFile", false);
TestOptions.stopAt = cmdLine.handleFlagWithParam("stopAtTestFile", false);
TestOptions.grep = cmdLine.handleFlagWithParam("grep", false);
TestOptions.timeout = cmdLine.handleFlagWithParam("ZoteroTestTimeout", false);
Services.ww.openWindow(
null,
"chrome://zotero-unit/content/runtests.html",
"_blank",
"chrome,dialog=no,all",
Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray)
);
cmdLine.preventDefault = true;
}
if (cmdLine.handleFlag("debugger", false)) {
(async function () {
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);
}
})();
}