Skip to content

Commit 42512f8

Browse files
committed
delete cache after switch the endpoint
1 parent b9cea44 commit 42512f8

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
"main": "./out/src/extension",
4141
"contributes": {
4242
"commands": [
43+
{
44+
"command": "leetcode.deleteCache",
45+
"title": "Delete cache",
46+
"category": "LeetCode"
47+
},
4348
{
4449
"command": "leetcode.toogleLeetCodeCn",
4550
"title": "Switch endpoint",

src/commands/cache.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
3+
import { leetCodeExecutor } from "../leetCodeExecutor";
4+
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
5+
6+
export async function deleteCache(): Promise<void> {
7+
try {
8+
await leetCodeExecutor.deleteCache();
9+
} catch (error) {
10+
await promptForOpenOutputChannel("Failed to delete cache. Please open the output channel for details.", DialogType.error);
11+
}
12+
}

src/commands/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export async function toogleLeetCodeCn(): Promise<void> {
4040

4141
try {
4242
await vscode.commands.executeCommand("leetcode.signout");
43+
await vscode.commands.executeCommand("leetcode.deleteCache");
4344
await promptForSignIn();
4445
} catch (error) {
4546
await promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details.", DialogType.error);

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
import * as vscode from "vscode";
4+
import * as cache from "./commands/cache";
45
import * as plugin from "./commands/plugin";
56
import * as session from "./commands/session";
67
import * as show from "./commands/show";
@@ -21,6 +22,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
2122

2223
context.subscriptions.push(
2324
vscode.window.registerTreeDataProvider("leetCodeExplorer", leetCodeTreeDataProvider),
25+
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
2426
vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.toogleLeetCodeCn()),
2527
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
2628
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),

src/leetCodeExecutor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export interface ILeetCodeExecutor {
1212
meetRequirements(): Promise<boolean>;
1313
getLeetCodeBinaryPath(): Promise<string>;
1414

15+
/* section for cache command */
16+
deleteCache(): Promise<string>;
17+
1518
/* section for user command */
1619
getUserInfo(): Promise<string>;
1720
signOut(): Promise<string>;
@@ -70,6 +73,10 @@ class LeetCodeExecutor implements ILeetCodeExecutor {
7073
}
7174
}
7275

76+
public async deleteCache(): Promise<string> {
77+
return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "cache", "-d"]);
78+
}
79+
7380
public async getUserInfo(): Promise<string> {
7481
return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "user"]);
7582
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy