From 05acfdb27efe3dab229914282802ceb6551bc84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Thu, 3 Oct 2024 11:52:18 +0200 Subject: [PATCH] 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. --- src/ZenWorkspaces.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 1f340a0..add6900 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -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;