Don't clear the saved session if startup fails

Zotero.Session.save() runs from a quit-application-granted observer
registered before the database checks, but session.json is only read
after them, so a startup error -- an incompatible database from a newer
version, say -- meant that quitting overwrote the file with an empty
state and all open tabs were lost.

https://forums.zotero.org/discussion/133542/

(cherry picked from commit 9e28eb0d39)
This commit is contained in:
Dan Stillman 2026-09-01 22:54:15 -04:00
parent ec128e020a
commit 7fe1162405

View file

@ -30,6 +30,7 @@ Zotero.Session = new function () {
let _state = {
windows: []
};
let _initialized = false;
Zotero.defineProperty(this, 'state', {
get: () => {
@ -48,6 +49,7 @@ Zotero.Session = new function () {
Zotero.logError(e);
}
}
_initialized = true;
};
this.setLastClosedZoteroPaneState = function (state) {
@ -59,6 +61,11 @@ Zotero.Session = new function () {
}, DEBOUNCED_SAVING_DELAY);
this.save = async function () {
// Don't overwrite the saved session if startup failed before the session was loaded
if (!_initialized) {
return;
}
try {
// Saving is triggered in `zotero.js` when a quit event is received,
// though if it was triggered by closing a window, ZoteroPane might