refactor: Simplify workspace initialization logic

This commit is contained in:
mauro-balades 2024-09-04 19:05:09 +02:00
parent 82824a1716
commit 9a5efb4a87

View file

@ -38,9 +38,9 @@ var ZenWorkspaces = {
return this._workspaceCache; return this._workspaceCache;
}, },
onWorkspacesEnabledChanged() { async onWorkspacesEnabledChanged() {
if (this.workspaceEnabled) { if (this.workspaceEnabled) {
this.initializeWorkspaces(); throw Error("Shoud've had reloaded the window");
} else { } else {
this._workspaceCache = null; this._workspaceCache = null;
document.getElementById("zen-workspaces-button")?.remove(); document.getElementById("zen-workspaces-button")?.remove();
@ -50,10 +50,8 @@ var ZenWorkspaces = {
} }
}, },
async initializeWorkspaces(init = false) { async initializeWorkspaces() {
if (init) {
Services.prefs.addObserver("zen.workspaces.enabled", this.onWorkspacesEnabledChanged.bind(this)); Services.prefs.addObserver("zen.workspaces.enabled", this.onWorkspacesEnabledChanged.bind(this));
}
this.initializeWorkspacesButton(); this.initializeWorkspacesButton();
let file = new FileUtils.File(this._storeFile); let file = new FileUtils.File(this._storeFile);
if (!file.exists()) { if (!file.exists()) {
@ -78,12 +76,10 @@ var ZenWorkspaces = {
} }
this.changeWorkspace(activeWorkspace, true); this.changeWorkspace(activeWorkspace, true);
} }
if (init) {
this._initializeWorkspaceCreationIcons(); this._initializeWorkspaceCreationIcons();
this._initializeWorkspaceEditIcons(); this._initializeWorkspaceEditIcons();
this._initializeWorkspaceTabContextMenus(); this._initializeWorkspaceTabContextMenus();
} }
}
}, },
handleTabClose(event) { handleTabClose(event) {