From 2f776eebe7153b86be8d4a45d92b35b1e9b18e1f Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 1 Oct 2011 02:36:27 -0400 Subject: [PATCH] Add +purgecaches startup flag. Process startup flags in :restart. Don't purge caches on :rehash. --- common/content/dactyl.js | 77 +++++++++++++++++++------------- common/locale/en-US/starting.xml | 21 ++++++++- common/modules/config.jsm | 3 ++ common/modules/help.jsm | 2 +- common/modules/options.jsm | 4 +- common/modules/sanitizer.jsm | 6 +-- common/modules/util.jsm | 5 ++- 7 files changed, 80 insertions(+), 38 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 474f533b..db778156 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -853,7 +853,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {number} level The logging level 0 - 15. */ log: function (msg, level) { - let verbose = localPrefs.get("loglevel", 0); + let verbose = config.prefs.get("loglevel", 0); if (!level || level <= verbose) { if (isObject(msg) && !isinstance(msg, _)) @@ -1110,10 +1110,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { /** * Restart the host application. */ - restart: function () { + restart: function (args) { if (!this.confirmQuit()) return; + config.prefs.set("commandline-args", args); + services.appStartup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); }, @@ -1579,6 +1581,35 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { bang: true }); + let startupOptions = [ + { + names: ["+u"], + description: "The initialization file to execute at startup", + type: CommandOption.STRING + }, + { + names: ["++noplugin"], + description: "Do not automatically load plugins" + }, + { + names: ["++cmd"], + description: "Ex commands to execute prior to initialization", + type: CommandOption.STRING, + multiple: true + }, + { + names: ["+c"], + description: "Ex commands to execute after initialization", + type: CommandOption.STRING, + multiple: true + }, + { + names: ["+purgecaches"], + description: "Purge " + config.appName + " caches at startup", + type: CommandOption.NOARG + } + ]; + commands.add(["reh[ash]"], "Reload the " + config.appName + " add-on", function (args) { @@ -1589,35 +1620,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }, { argCount: "0", // FIXME - options: [ - { - names: ["+u"], - description: "The initialization file to execute at startup", - type: CommandOption.STRING - }, - { - names: ["++noplugin"], - description: "Do not automatically load plugins" - }, - { - names: ["++cmd"], - description: "Ex commands to execute prior to initialization", - type: CommandOption.STRING, - multiple: true - }, - { - names: ["+c"], - description: "Ex commands to execute after initialization", - type: CommandOption.STRING, - multiple: true - } - ] + options: startupOptions }); commands.add(["res[tart]"], "Force " + config.host + " to restart", - function () { dactyl.restart(); }, - { argCount: "0" }); + function (args) { dactyl.restart(args.string); }, + { + argCount: "0", + options: startupOptions + }); function findToolbar(name) DOM.XPath( "//*[@toolbarname=" + util.escapeString(name, "'") + " or " + @@ -1821,7 +1833,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { dactyl.timeout(function () { try { - var args = storage.session.commandlineArgs || services.commandLineHandler.optionValue; + var args = config.prefs.get("commandline-args") + || storage.session.commandlineArgs + || services.commandLineHandler.optionValue; + + config.prefs.reset("commandline-args"); + if (isString(args)) args = dactyl.parseCommandLine(args); @@ -1839,9 +1856,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { dactyl.log(_("dactyl.commandlineOpts", util.objectToString(dactyl.commandLineOptions)), 3); - if (localPrefs.get("first-run", true)) + if (config.prefs.get("first-run", true)) dactyl.timeout(function () { - localPrefs.set("first-run", false); + config.prefs.set("first-run", false); this.withSavedValues(["forceTarget"], function () { this.forceTarget = dactyl.NEW_TAB; help.help(); diff --git a/common/locale/en-US/starting.xml b/common/locale/en-US/starting.xml index 39e1c40e..0a9ce2b3 100644 --- a/common/locale/en-US/starting.xml +++ b/common/locale/en-US/starting.xml @@ -76,6 +76,18 @@ + + +purgecaches + + +purgecaches + +

+ Purges &dactyl.appName; caches at startup. May occasionally be + necessary after making local changes to the source tree. +

+
+
+

Initialization

At startup, &dactyl.appName; completes the following tasks in order.

@@ -182,10 +194,12 @@ repository, this is a good way to update to the latest version or to test your changes.

+

Any arguments supplied are parsed as command-line arguments as specified in startup-options.

+ Not all plugins are designed to cleanly un-apply during a rehash. While official plugins are safe, beware of possible instability @@ -196,9 +210,14 @@ :res :restart - :restart + :restart arg

Force &dactyl.host; to restart. Useful when installing extensions.

+ +

+ Any arguments supplied are parsed as command-line arguments as + specified in startup-options. +

diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 20c70987..094b7bdd 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -17,6 +17,7 @@ this.lazyRequire("addons", ["AddonManager"]); this.lazyRequire("cache", ["cache"]); this.lazyRequire("highlight", ["highlight"]); this.lazyRequire("messages", ["_"]); +this.lazyRequire("prefs", ["localPrefs", "prefs"]); function AboutHandler() {} AboutHandler.prototype = { @@ -66,6 +67,8 @@ var ConfigBase = Class("ConfigBase", { }); }, + get prefs() localPrefs, + get has() Set.has(this.features), configFiles: [ diff --git a/common/modules/help.jsm b/common/modules/help.jsm index 1326c565..31e2ec0d 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -57,7 +57,7 @@ var HelpBuilder = Class("HelpBuilder", { let result = []; for (let base in values(this.bases)) { let url = [base, file, ".xml"].join(""); - let res = util.httpGet(url); + let res = util.httpGet(url, { quiet: true }); if (res) { if (res.responseXML.documentElement.localName == "document") this.files[file] = url; diff --git a/common/modules/options.jsm b/common/modules/options.jsm index a2a71c3a..a1a0dbf7 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -14,6 +14,8 @@ defineModule("options", { require: ["contexts", "messages", "storage"] }, this); +this.lazyRequire("config", ["config"]); + /** @scope modules */ let ValueError = Class("ValueError", ErrorBase); @@ -947,7 +949,7 @@ var Options = Module("options", { setPref: deprecated("prefs.set", function setPref() prefs.set.apply(prefs, arguments)), withContext: deprecated("prefs.withContext", function withContext() prefs.withContext.apply(prefs, arguments)), - cleanupPrefs: Class.Memoize(function () localPrefs.Branch("cleanup.option.")), + cleanupPrefs: Class.Memoize(function () config.prefs.Branch("cleanup.option.")), cleanup: function cleanup(reason) { if (~["disable", "uninstall"].indexOf(reason)) diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index e0c9f998..ba18674f 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -55,7 +55,7 @@ var Item = Class("SanitizeItem", { shouldSanitize: function (shutdown) (!shutdown || this.builtin || this.persistent) && prefs.get(shutdown ? this.shutdownPref : this.pref) }, { - PREFIX: localPrefs.branch.root, + PREFIX: config.prefs.branch.root, BRANCH: "privacy.cpd.", SHUTDOWN_BRANCH: "privacy.clearOnShutdown." }); @@ -290,8 +290,8 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef } }, - get ranAtShutdown() localPrefs.get("didSanitizeOnShutdown"), - set ranAtShutdown(val) localPrefs.set("didSanitizeOnShutdown", Boolean(val)), + get ranAtShutdown() config.prefs.get("didSanitizeOnShutdown"), + set ranAtShutdown(val) config.prefs.set("didSanitizeOnShutdown", Boolean(val)), get runAtShutdown() prefs.get("privacy.sanitize.sanitizeOnShutdown"), set runAtShutdown(val) prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val)), diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 30d466d6..1e21f3fc 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -739,7 +739,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), return xmlhttp; } catch (e) { - util.dactyl.log(_("error.cantOpen", String.quote(url), e), 1); + if (!params.quiet) + util.dactyl.log(_("error.cantOpen", String.quote(url), e), 1); return null; } }, @@ -1183,7 +1184,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), rehash: function (args) { storage.session.commandlineArgs = args; this.timeout(function () { - cache.flushAll(); + this.flushCache(); this.rehashing = true; let addon = config.addon; addon.userDisabled = true;