mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-05 08:15:48 +01:00
Don't muck with prefs any more than necessary on quit. Closes issue #162.
This commit is contained in:
@@ -930,16 +930,17 @@ const Dactyl = Module("dactyl", {
|
||||
* windows could be closed individually.
|
||||
*/
|
||||
quit: function (saveSession, force) {
|
||||
// TODO: Use safeSetPref?
|
||||
if (saveSession)
|
||||
prefs.set("browser.startup.page", 3); // start with saved session
|
||||
else
|
||||
prefs.set("browser.startup.page", 1); // start with default homepage session
|
||||
if (!force && !canQuitApplication())
|
||||
return;
|
||||
|
||||
if (force)
|
||||
services.get("appStartup").quit(Ci.nsIAppStartup.eForceQuit);
|
||||
else
|
||||
window.goQuitApplication();
|
||||
let pref = "browser.startup.page";
|
||||
prefs.save(pref);
|
||||
if (saveSession)
|
||||
prefs.safeSet(pref, 3);
|
||||
if (!saveSession && prefs.get(pref) >= 2)
|
||||
prefs.safeSet(pref, 1);
|
||||
|
||||
services.get("appStartup").quit(Ci.nsIAppStartup[force ? "eForceQuit" : "eAttemptQuit"]);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1044,23 +1045,10 @@ const Dactyl = Module("dactyl", {
|
||||
* Restart the host application.
|
||||
*/
|
||||
restart: function () {
|
||||
// notify all windows that an application quit has been requested.
|
||||
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
||||
services.get("observer").notifyObservers(cancelQuit, "quit-application-requested", null);
|
||||
|
||||
// something aborted the quit process.
|
||||
if (cancelQuit.data)
|
||||
if (!canQuitApplication())
|
||||
return;
|
||||
|
||||
// notify all windows that an application quit has been granted.
|
||||
services.get("observer").notifyObservers(null, "quit-application-granted", null);
|
||||
|
||||
// enumerate all windows and call shutdown handlers
|
||||
for (let win in iter(services.get("windowMediator").getEnumerator(null)))
|
||||
if (("tryToClose" in win) && !win.tryToClose())
|
||||
return;
|
||||
|
||||
services.get("appStartup").quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
||||
services.get("appStartup").quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1323,11 +1311,10 @@ const Dactyl = Module("dactyl", {
|
||||
"Open the help page",
|
||||
function () { dactyl.help(); });
|
||||
|
||||
if (dactyl.has("session")) {
|
||||
if (dactyl.has("session"))
|
||||
mappings.add([modes.NORMAL], ["ZQ"],
|
||||
"Quit and don't save the session",
|
||||
function () { dactyl.quit(false); });
|
||||
}
|
||||
|
||||
mappings.add([modes.NORMAL], ["ZZ"],
|
||||
"Quit and save the session",
|
||||
|
||||
@@ -1069,6 +1069,8 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
|
||||
const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
|
||||
SAVED: "extensions.dactyl.saved.",
|
||||
RESTORE: "extensions.dactyl.restore.",
|
||||
|
||||
|
||||
init: function () {
|
||||
this._prefContexts = [];
|
||||
@@ -1077,6 +1079,8 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
this._branch = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2);
|
||||
this._branch.addObserver("", this, false);
|
||||
this._observers = {};
|
||||
|
||||
this.restore();
|
||||
},
|
||||
|
||||
observe: {
|
||||
@@ -1153,9 +1157,7 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
* @param {value} defaultValue The value to return if the preference
|
||||
* is unset.
|
||||
*/
|
||||
get: function (name, defaultValue) {
|
||||
return this._load(name, defaultValue);
|
||||
},
|
||||
get: function (name, defaultValue) this._load(name, defaultValue),
|
||||
|
||||
/**
|
||||
* Returns the default value of a preference
|
||||
@@ -1164,9 +1166,7 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
* @param {value} defaultValue The value to return if the preference
|
||||
* has no default value.
|
||||
*/
|
||||
getDefault: function (name, defaultValue) {
|
||||
return this._load(name, defaultValue, true);
|
||||
},
|
||||
getDefault: function (name, defaultValue) this._load(name, defaultValue, true),
|
||||
|
||||
/**
|
||||
* Returns the names of all preferences.
|
||||
@@ -1211,10 +1211,10 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
* @param {string} name The preference name.
|
||||
* @param {value} value The new preference value.
|
||||
*/
|
||||
safeSet: function (name, value, message) {
|
||||
safeSet: function (name, value, message, skipSave) {
|
||||
this._checkSafe(name, message, value);
|
||||
this._store(name, value);
|
||||
this._store(this.SAVED + name, value);
|
||||
this[skipSave ? "reset" : "_store"](this.SAVED + name, value);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1227,6 +1227,31 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
||||
this._store(name, value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the current value of a preference to be restored at next
|
||||
* startup.
|
||||
*
|
||||
* @param {string} name The preference to save.
|
||||
*/
|
||||
save: function (name) {
|
||||
let val = this.get(name);
|
||||
this.set(this.RESTORE + name, val);
|
||||
this.safeSet(name, val);
|
||||
},
|
||||
|
||||
/**
|
||||
* Restores saved preferences in the given branch.
|
||||
*
|
||||
* @param {string} branch The branch from which to restore
|
||||
* preferences. @optional
|
||||
*/
|
||||
restore: function (branch) {
|
||||
this.getNames(this.RESTORE + (branch || "")).forEach(function (pref) {
|
||||
this.safeSet(pref.substr(this.RESTORE.length), this.get(pref), null, true)
|
||||
this.reset(pref);
|
||||
}, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the preference *name* to its default value.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user