Skip to content

Commit 92d48db

Browse files
committed
clear cache when switch endpoint
1 parent 42512f8 commit 92d48db

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/commands/plugin.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"use strict";
22

3+
import * as fse from "fs-extra";
4+
import * as os from "os";
5+
import * as path from "path";
36
import * as vscode from "vscode";
47
import { leetCodeExecutor } from "../leetCodeExecutor";
58
import { IQuickItemEx } from "../shared";
69
import { Endpoint } from "../shared";
710
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
11+
import { deleteCache } from "./cache";
812

913
export async function toogleLeetCodeCn(): Promise<void> {
1014
const isCnEnbaled: boolean = isLeetCodeCnEnabled();
@@ -40,15 +44,20 @@ export async function toogleLeetCodeCn(): Promise<void> {
4044

4145
try {
4246
await vscode.commands.executeCommand("leetcode.signout");
43-
await vscode.commands.executeCommand("leetcode.deleteCache");
47+
await deleteCache();
4448
await promptForSignIn();
4549
} catch (error) {
4650
await promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details.", DialogType.error);
4751
}
4852
}
4953

5054
export async function initializeEndpoint(): Promise<void> {
51-
await leetCodeExecutor.toggleLeetCodeCn(isLeetCodeCnEnabled());
55+
const isCnEnabledInExtension: boolean = isLeetCodeCnEnabled();
56+
const isCnEnabledInCli: boolean = await isLeetCodeCnEnabledInCli();
57+
await leetCodeExecutor.toggleLeetCodeCn(isCnEnabledInExtension);
58+
if (isCnEnabledInCli !== isCnEnabledInExtension) {
59+
await deleteCache();
60+
}
5261
}
5362

5463
export function isLeetCodeCnEnabled(): boolean {
@@ -59,3 +68,12 @@ export function isLeetCodeCnEnabled(): boolean {
5968
}
6069
return false;
6170
}
71+
72+
async function isLeetCodeCnEnabledInCli(): Promise<boolean> {
73+
const pluginsStatusFile: string = path.join(os.homedir(), ".lc", "plugins.json");
74+
if (!await fse.pathExists(pluginsStatusFile)) {
75+
return false;
76+
}
77+
const pluginsObj: {} = await fse.readJson(pluginsStatusFile);
78+
return pluginsObj["leetcode.cn"];
79+
}

0 commit comments

Comments
 (0)