mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-02 00:35:46 +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.
|
* windows could be closed individually.
|
||||||
*/
|
*/
|
||||||
quit: function (saveSession, force) {
|
quit: function (saveSession, force) {
|
||||||
// TODO: Use safeSetPref?
|
if (!force && !canQuitApplication())
|
||||||
if (saveSession)
|
return;
|
||||||
prefs.set("browser.startup.page", 3); // start with saved session
|
|
||||||
else
|
|
||||||
prefs.set("browser.startup.page", 1); // start with default homepage session
|
|
||||||
|
|
||||||
if (force)
|
let pref = "browser.startup.page";
|
||||||
services.get("appStartup").quit(Ci.nsIAppStartup.eForceQuit);
|
prefs.save(pref);
|
||||||
else
|
if (saveSession)
|
||||||
window.goQuitApplication();
|
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 the host application.
|
||||||
*/
|
*/
|
||||||
restart: function () {
|
restart: function () {
|
||||||
// notify all windows that an application quit has been requested.
|
if (!canQuitApplication())
|
||||||
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)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// notify all windows that an application quit has been granted.
|
services.get("appStartup").quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1323,11 +1311,10 @@ const Dactyl = Module("dactyl", {
|
|||||||
"Open the help page",
|
"Open the help page",
|
||||||
function () { dactyl.help(); });
|
function () { dactyl.help(); });
|
||||||
|
|
||||||
if (dactyl.has("session")) {
|
if (dactyl.has("session"))
|
||||||
mappings.add([modes.NORMAL], ["ZQ"],
|
mappings.add([modes.NORMAL], ["ZQ"],
|
||||||
"Quit and don't save the session",
|
"Quit and don't save the session",
|
||||||
function () { dactyl.quit(false); });
|
function () { dactyl.quit(false); });
|
||||||
}
|
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["ZZ"],
|
mappings.add([modes.NORMAL], ["ZZ"],
|
||||||
"Quit and save the session",
|
"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]), {
|
const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
|
||||||
SAVED: "extensions.dactyl.saved.",
|
SAVED: "extensions.dactyl.saved.",
|
||||||
|
RESTORE: "extensions.dactyl.restore.",
|
||||||
|
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
this._prefContexts = [];
|
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 = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2);
|
||||||
this._branch.addObserver("", this, false);
|
this._branch.addObserver("", this, false);
|
||||||
this._observers = {};
|
this._observers = {};
|
||||||
|
|
||||||
|
this.restore();
|
||||||
},
|
},
|
||||||
|
|
||||||
observe: {
|
observe: {
|
||||||
@@ -1153,9 +1157,7 @@ const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference
|
|||||||
* @param {value} defaultValue The value to return if the preference
|
* @param {value} defaultValue The value to return if the preference
|
||||||
* is unset.
|
* is unset.
|
||||||
*/
|
*/
|
||||||
get: function (name, defaultValue) {
|
get: function (name, defaultValue) this._load(name, defaultValue),
|
||||||
return this._load(name, defaultValue);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default value of a preference
|
* 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
|
* @param {value} defaultValue The value to return if the preference
|
||||||
* has no default value.
|
* has no default value.
|
||||||
*/
|
*/
|
||||||
getDefault: function (name, defaultValue) {
|
getDefault: function (name, defaultValue) this._load(name, defaultValue, true),
|
||||||
return this._load(name, defaultValue, true);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the names of all preferences.
|
* 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 {string} name The preference name.
|
||||||
* @param {value} value The new preference value.
|
* @param {value} value The new preference value.
|
||||||
*/
|
*/
|
||||||
safeSet: function (name, value, message) {
|
safeSet: function (name, value, message, skipSave) {
|
||||||
this._checkSafe(name, message, value);
|
this._checkSafe(name, message, value);
|
||||||
this._store(name, 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);
|
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.
|
* Resets the preference *name* to its default value.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user