Fix: Prevent potential crash when workspace doesn't exist

This commit addresses a potential crash that could occur when the active workspace no longer exists. The issue was that the code attempted to access the `uuid` property of the first workspace in the list even if the list was empty.

This commit fixes the issue by using optional chaining (`?.`) to safely access the `uuid` property, ensuring the code doesn't crash if the workspace list is empty.
This commit is contained in:
Kristijan Ribarić 2024-10-03 11:52:18 +02:00
parent 9bcb66c768
commit 05acfdb27e

View file

@ -62,11 +62,11 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
const activeWorkspace = this._workspaceCache.workspaces.find(w => w.uuid === activeWorkspaceId);
// Set the active workspace ID to the first one if the one with selected id doesn't exist
if (!activeWorkspace) {
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0].uuid);
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0]?.uuid);
}
} else {
// Set the active workspace ID to the first one if active workspace doesn't exist
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0].uuid);
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0]?.uuid);
}
}
return this._workspaceCache;