From c0769954658bc6747e62204242aa49923c775c01 Mon Sep 17 00:00:00 2001 From: YXL Date: Tue, 28 May 2024 23:58:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(local):=20delete=20library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: YXL #974 --- packages/client/src/activate/local.ts | 13 ++++++------- packages/client/src/treeview/local.ts | 13 ++++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/client/src/activate/local.ts b/packages/client/src/activate/local.ts index 14e3340b1..66977325f 100644 --- a/packages/client/src/activate/local.ts +++ b/packages/client/src/activate/local.ts @@ -15,17 +15,16 @@ export function initLocal(context: ExtensionContext): void { await window.showOpenDialog({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false }) )?.shift()?.fsPath; if (!path) return; - try { - const folders = await LocalProvider.addFolder(path); - if (folders) await context.globalState.update(LOCAL_FOLDER_KEY, folders); - } catch {} + const folders = await LocalProvider.addFolder(path); + if (folders) await context.globalState.update(LOCAL_FOLDER_KEY, folders); }), commands.registerCommand("cloudmusic.refreshLocalLibrary", () => LocalProvider.refresh()), - commands.registerCommand("cloudmusic.deleteLocalLibrary", ({ label }: LocalLibraryTreeItem) => - LocalProvider.deleteFolder(label), - ), + commands.registerCommand("cloudmusic.deleteLocalLibrary", ({ label }: LocalLibraryTreeItem) => { + const folders = LocalProvider.deleteFolder(label); + if (folders !== undefined) void context.globalState.update(LOCAL_FOLDER_KEY, folders); + }), commands.registerCommand( "cloudmusic.openLocalLibrary", diff --git a/packages/client/src/treeview/local.ts b/packages/client/src/treeview/local.ts index 2ef7781b2..98b462144 100644 --- a/packages/client/src/treeview/local.ts +++ b/packages/client/src/treeview/local.ts @@ -37,20 +37,23 @@ export class LocalProvider implements TreeDataProvider { static async addFolder(path: string): Promise { if (!this._folders.has(path)) { try { - await stat(path); - this._folders.add(path); - this.refresh(); - return [...this._folders]; + if ((await stat(path)).isDirectory()) { + this._folders.add(path); + this.refresh(); + return [...this._folders]; + } } catch {} } return; } - static deleteFolder(path: string): void { + static deleteFolder(path: string): string[] | undefined { if (this._folders.has(path)) { this._folders.delete(path); this.refresh(); + return [...this._folders]; } + return; } static refresh(): void {