diff --git a/package.json b/package.json
index ed290139..e809f934 100644
--- a/package.json
+++ b/package.json
@@ -43,37 +43,40 @@
"commands": [
{
"command": "leetcode.deleteCache",
- "title": "Delete cache",
+ "title": "Delete Cache",
"category": "LeetCode"
},
{
"command": "leetcode.toogleLeetCodeCn",
- "title": "Switch endpoint",
+ "title": "Switch Endpoint",
"category": "LeetCode",
- "icon": "resources/cn.png"
+ "icon": {
+ "light": "resources/light/endpoint.svg",
+ "dark": "resources/dark/endpoint.svg"
+ }
},
{
"command": "leetcode.signin",
- "title": "Sign in",
+ "title": "Sign In",
"category": "LeetCode",
"icon": {
- "light": "resources/light/signin.png",
- "dark": "resources/dark/signin.png"
+ "light": "resources/light/signin.svg",
+ "dark": "resources/dark/signin.svg"
}
},
{
"command": "leetcode.signout",
- "title": "Sign out",
+ "title": "Sign Out",
"category": "LeetCode"
},
{
"command": "leetcode.selectSessions",
- "title": "Select session",
+ "title": "Select Session",
"category": "LeetCode"
},
{
"command": "leetcode.createSession",
- "title": "Create new session",
+ "title": "Create New Session",
"category": "LeetCode"
},
{
@@ -87,14 +90,17 @@
},
{
"command": "leetcode.showProblem",
- "title": "Show problem",
+ "title": "Show Problem",
"category": "LeetCode"
},
{
"command": "leetcode.searchProblem",
"title": "Search Problem",
"category": "LeetCode",
- "icon": "resources/search.png"
+ "icon": {
+ "light": "resources/light/search.svg",
+ "dark": "resources/dark/search.svg"
+ }
},
{
"command": "leetcode.testSolution",
diff --git a/resources/cn.png b/resources/cn.png
deleted file mode 100644
index 4b05c7f2..00000000
Binary files a/resources/cn.png and /dev/null differ
diff --git a/resources/dark/endpoint.svg b/resources/dark/endpoint.svg
new file mode 100644
index 00000000..c9b4d058
--- /dev/null
+++ b/resources/dark/endpoint.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/resources/dark/refresh.svg b/resources/dark/refresh.svg
index 2e184ea7..fbc960f4 100644
--- a/resources/dark/refresh.svg
+++ b/resources/dark/refresh.svg
@@ -1 +1,6 @@
-
+
+
diff --git a/resources/dark/search.svg b/resources/dark/search.svg
new file mode 100644
index 00000000..6cd41c04
--- /dev/null
+++ b/resources/dark/search.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/resources/dark/signin.png b/resources/dark/signin.png
deleted file mode 100644
index 35d32ba8..00000000
Binary files a/resources/dark/signin.png and /dev/null differ
diff --git a/resources/dark/signin.svg b/resources/dark/signin.svg
new file mode 100644
index 00000000..4c115bc6
--- /dev/null
+++ b/resources/dark/signin.svg
@@ -0,0 +1,7 @@
+
+
diff --git a/resources/light/endpoint.svg b/resources/light/endpoint.svg
new file mode 100644
index 00000000..5aa40abe
--- /dev/null
+++ b/resources/light/endpoint.svg
@@ -0,0 +1,6 @@
+?xml version="1.0"?>
+
diff --git a/resources/light/refresh.svg b/resources/light/refresh.svg
index a88fab81..e1969cd4 100644
--- a/resources/light/refresh.svg
+++ b/resources/light/refresh.svg
@@ -1 +1,6 @@
-
+
+
diff --git a/resources/light/search.svg b/resources/light/search.svg
new file mode 100644
index 00000000..48ffa86d
--- /dev/null
+++ b/resources/light/search.svg
@@ -0,0 +1,6 @@
+
+
diff --git a/resources/light/signin.png b/resources/light/signin.png
deleted file mode 100644
index 9a9d1250..00000000
Binary files a/resources/light/signin.png and /dev/null differ
diff --git a/resources/light/signin.svg b/resources/light/signin.svg
new file mode 100644
index 00000000..ab5fe2df
--- /dev/null
+++ b/resources/light/signin.svg
@@ -0,0 +1,7 @@
+
+
diff --git a/resources/search.png b/resources/search.png
deleted file mode 100644
index 05e881c0..00000000
Binary files a/resources/search.png and /dev/null differ
diff --git a/src/commands/plugin.ts b/src/commands/plugin.ts
index 04b82dd3..ed9286ca 100644
--- a/src/commands/plugin.ts
+++ b/src/commands/plugin.ts
@@ -1,9 +1,6 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
-import * as fse from "fs-extra";
-import * as os from "os";
-import * as path from "path";
import * as vscode from "vscode";
import { leetCodeExecutor } from "../leetCodeExecutor";
import { IQuickItemEx } from "../shared";
@@ -11,21 +8,21 @@ import { Endpoint } from "../shared";
import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
import { deleteCache } from "./cache";
-export async function toogleLeetCodeCn(): Promise {
- const isCnEnbaled: boolean = isLeetCodeCnEnabled();
+export async function switchEndpoint(): Promise {
+ const isCnEnbaled: boolean = getLeetCodeEndpoint() === Endpoint.LeetCodeCN;
const picks: Array> = [];
picks.push(
{
- label: `${isCnEnbaled ? "$(check) " : ""}On`,
- description: "",
- detail: `Enable ${Endpoint.LeetCodeCN}.`,
- value: "on",
+ label: `${isCnEnbaled ? "" : "$(check) "}LeetCode`,
+ description: "leetcode.com",
+ detail: `Enable LeetCode US`,
+ value: Endpoint.LeetCode,
},
{
- label: `${isCnEnbaled ? "" : "$(check) "}Off`,
- description: "",
- detail: `Disable ${Endpoint.LeetCodeCN}.`,
- value: "off",
+ label: `${isCnEnbaled ? "$(check) " : ""}力扣`,
+ description: "leetcode-cn.com",
+ detail: `启用中国版 LeetCode`,
+ value: Endpoint.LeetCodeCN,
},
);
const choice: IQuickItemEx | undefined = await vscode.window.showQuickPick(picks);
@@ -34,9 +31,8 @@ export async function toogleLeetCodeCn(): Promise {
}
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
try {
- const enabled: boolean = choice.value === "on";
- const endpoint: string = enabled ? Endpoint.LeetCodeCN : Endpoint.LeetCode;
- await leetCodeExecutor.toggleLeetCodeCn(enabled);
+ const endpoint: string = choice.value;
+ await leetCodeExecutor.switchEndpoint(endpoint);
await leetCodeConfig.update("endpoint", endpoint, true /* UserSetting */);
vscode.window.showInformationMessage(`Switched the endpoint to ${endpoint}`);
} catch (error) {
@@ -52,29 +48,7 @@ export async function toogleLeetCodeCn(): Promise {
}
}
-export async function initializeEndpoint(): Promise {
- const isCnEnabledInExtension: boolean = isLeetCodeCnEnabled();
- const isCnEnabledInCli: boolean = await isLeetCodeCnEnabledInCli();
- await leetCodeExecutor.toggleLeetCodeCn(isCnEnabledInExtension);
- if (isCnEnabledInCli !== isCnEnabledInExtension) {
- await deleteCache();
- }
-}
-
-export function isLeetCodeCnEnabled(): boolean {
+export function getLeetCodeEndpoint(): string {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
- const endpoint: string | undefined = leetCodeConfig.get("endpoint");
- if (endpoint && endpoint === Endpoint.LeetCodeCN) {
- return true;
- }
- return false;
-}
-
-async function isLeetCodeCnEnabledInCli(): Promise {
- const pluginsStatusFile: string = path.join(os.homedir(), ".lc", "plugins.json");
- if (!await fse.pathExists(pluginsStatusFile)) {
- return false;
- }
- const pluginsObj: {} = await fse.readJson(pluginsStatusFile);
- return pluginsObj["leetcode.cn"];
+ return leetCodeConfig.get("endpoint", Endpoint.LeetCode);
}
diff --git a/src/extension.ts b/src/extension.ts
index 4913756d..67b6c3ca 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -36,7 +36,7 @@ export async function activate(context: vscode.ExtensionContext): Promise
vscode.window.registerTreeDataProvider("leetCodeExplorer", leetCodeTreeDataProvider),
vscode.languages.registerCodeLensProvider({ scheme: "file" }, codeLensProvider),
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
- vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.toogleLeetCodeCn()),
+ vscode.commands.registerCommand("leetcode.toogleLeetCodeCn", () => plugin.switchEndpoint()),
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),
vscode.commands.registerCommand("leetcode.selectSessions", () => session.selectSession()),
@@ -48,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext): Promise
vscode.commands.registerCommand("leetcode.submitSolution", (uri?: vscode.Uri) => submit.submitSolution(uri)),
);
- await plugin.initializeEndpoint();
+ await leetCodeExecutor.switchEndpoint(plugin.getLeetCodeEndpoint());
leetCodeManager.getLoginStatus();
}
diff --git a/src/leetCodeExecutor.ts b/src/leetCodeExecutor.ts
index f8906f62..e6356a83 100644
--- a/src/leetCodeExecutor.ts
+++ b/src/leetCodeExecutor.ts
@@ -4,6 +4,7 @@
import * as cp from "child_process";
import * as path from "path";
import * as vscode from "vscode";
+import { Endpoint } from "./shared";
import { executeCommand, executeCommandWithProgress } from "./utils/cpUtils";
import { DialogOptions, openUrl } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
@@ -89,11 +90,14 @@ class LeetCodeExecutor {
return await this.executeCommandWithProgressEx("Submitting to LeetCode...", "node", [await this.getLeetCodeBinaryPath(), "test", `"${filePath}"`]);
}
- public async toggleLeetCodeCn(isEnable: boolean): Promise {
- if (isEnable) {
- return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
+ public async switchEndpoint(endpoint: string): Promise {
+ switch (endpoint) {
+ case Endpoint.LeetCodeCN:
+ return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-e", "leetcode.cn"]);
+ case Endpoint.LeetCode:
+ default:
+ return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
}
- return await this.executeCommandEx("node", [await this.getLeetCodeBinaryPath(), "plugin", "-d", "leetcode.cn"]);
}
private async executeCommandEx(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise {
diff --git a/src/utils/uiUtils.ts b/src/utils/uiUtils.ts
index aeb76ee6..3f17c97b 100644
--- a/src/utils/uiUtils.ts
+++ b/src/utils/uiUtils.ts
@@ -2,7 +2,7 @@
// Licensed under the MIT license.
import * as vscode from "vscode";
-import { isLeetCodeCnEnabled } from "../commands/plugin";
+import { getLeetCodeEndpoint } from "../commands/plugin";
import { leetCodeChannel } from "../leetCodeChannel";
export namespace DialogOptions {
@@ -46,7 +46,7 @@ export async function promptForSignIn(): Promise {
await vscode.commands.executeCommand("leetcode.signin");
break;
case DialogOptions.singUp:
- if (isLeetCodeCnEnabled()) {
+ if (getLeetCodeEndpoint()) {
openUrl("https://leetcode-cn.com");
} else {
openUrl("https://leetcode.com");