Skip to content

Commit

Permalink
🐞 fix(local): delete library
Browse files Browse the repository at this point in the history
Signed-off-by: YXL <[email protected]>

#974
  • Loading branch information
YXL76 committed May 28, 2024
1 parent 91788db commit c076995
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 6 additions & 7 deletions packages/client/src/activate/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions packages/client/src/treeview/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ export class LocalProvider implements TreeDataProvider<Content> {
static async addFolder(path: string): Promise<string[] | undefined> {
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 {
Expand Down

0 comments on commit c076995

Please sign in to comment.