From 5955cbfe1a9d8244eaacd936e4159c5eb31de922 Mon Sep 17 00:00:00 2001 From: ZanzyTHEbar Date: Mon, 17 Feb 2025 18:44:18 +0000 Subject: [PATCH] fix: refactor disable method and improve settings handling --- gnome-extension/src/extension.ts | 58 ++++++++++++++------------------ 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/gnome-extension/src/extension.ts b/gnome-extension/src/extension.ts index 7d8fec2..d503689 100644 --- a/gnome-extension/src/extension.ts +++ b/gnome-extension/src/extension.ts @@ -40,7 +40,7 @@ export default class VSCodeWorkspacesExtension extends Extension { private _indicator?: PanelMenu.Button; private _refreshInterval: number = 300; - private _refreshTimeout: number | null = null; + private _refreshTimeout: any = null; private _newWindow: boolean = false; private _editorLocation: string = ''; private _preferCodeWorkspaceFile: boolean = false; @@ -104,26 +104,6 @@ export default class VSCodeWorkspacesExtension extends Extension { this._initializeWorkspaces(); } - disable() { - if (this._refreshTimeout) { - GLib.source_remove(this._refreshTimeout); - this._refreshTimeout = null; - } - if (this._indicator) { - this._indicator.destroy(); - this._indicator = undefined; - } - this.gsettings = undefined; - - // clean up the cache - this._workspaces.clear(); - this._recentWorkspaces.clear(); - this._foundEditors = []; - this._activeEditor = undefined; - - this._log(`VSCode Workspaces Extension disabled`); - } - _initializeWorkspaces() { this._log('Initializing workspaces'); this._workspaces.clear(); @@ -176,18 +156,32 @@ export default class VSCodeWorkspacesExtension extends Extension { } } - _setSettings() { - - if (!this.gsettings) { - this._log('No GSettings found'); - return; + disable() { + if (this._refreshTimeout) { + GLib.source_remove(this._refreshTimeout); + this._refreshTimeout = null; } + if (this._indicator) { + this._indicator.destroy(); + this._indicator = undefined; + } + this.gsettings = undefined; - this._newWindow = this.gsettings.get_value('new-window').deepUnpack() ?? false; - this._editorLocation = this.gsettings.get_value('editor-location').deepUnpack() ?? 'auto'; - this._refreshInterval = this.gsettings.get_value('refresh-interval').deepUnpack() ?? 300; - this._preferCodeWorkspaceFile = this.gsettings.get_value('prefer-workspace-file').deepUnpack() ?? false; - this._debug = this.gsettings.get_value('debug').deepUnpack() ?? false; + // clean up the cache + this._workspaces.clear(); + this._recentWorkspaces.clear(); + this._foundEditors = []; + this._activeEditor = undefined; + + this._log(`VSCode Workspaces Extension disabled`); + } + + _setSettings() { + this._newWindow = this.gsettings!.get_value('new-window').deepUnpack() ?? false; + this._editorLocation = this.gsettings!.get_value('editor-location').deepUnpack() ?? 'auto'; + this._refreshInterval = this.gsettings!.get_value('refresh-interval').deepUnpack() ?? 300; + this._preferCodeWorkspaceFile = this.gsettings!.get_value('prefer-workspace-file').deepUnpack() ?? false; + this._debug = this.gsettings!.get_value('debug').deepUnpack() ?? false; this._log(`Workspaces Extension enabled`); this._log(`New Window: ${this._newWindow}`); @@ -778,7 +772,7 @@ export default class VSCodeWorkspacesExtension extends Extension { } _startRefresh() { - if (this._refreshTimeout !== null) { + if (this._refreshTimeout) { GLib.source_remove(this._refreshTimeout); this._refreshTimeout = null; }