From af76a8b3927c79ebfa1bcd5b486416637ca755e3 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Tue, 3 Dec 2019 16:16:18 +0800 Subject: [PATCH 1/6] add leetcode.cookieIn but simple change --- README.md | 3 ++- package.json | 8 +++++++- src/extension.ts | 1 + src/leetCodeManager.ts | 26 +++++++++++++++----------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 67fb4df0..3e727458 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ - Simply click `Sign in to LeetCode` in the `LeetCode Explorer` will let you **sign in** with your LeetCode account. -- You can also use the following command to sign in/out: +- You can also use the following command to sign in/cookie in/out: - **LeetCode: Sign in** + - **LeetCode: Cookie in** - **LeetCode: Sign out** --- diff --git a/package.json b/package.json index 91bc6e59..b14fb6a8 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,17 @@ "onCommand:leetcode.testSolution", "onCommand:leetcode.submitSolution", "onCommand:leetcode.switchDefaultLanguage", + "onCommand:leetcode.cookieIn", "onView:leetCodeExplorer" ], "main": "./out/src/extension", "contributes": { "commands": [ + { + "command": "leetcode.cookieIn", + "title": "Cookie In", + "category": "LeetCode" + }, { "command": "leetcode.deleteCache", "title": "Delete Cache", @@ -683,6 +689,6 @@ "markdown-it": "^8.4.2", "require-from-string": "^2.0.2", "unescape-js": "^1.1.1", - "vsc-leetcode-cli": "2.6.16" + "vsc-leetcode-cli": "2.6.17" } } diff --git a/src/extension.ts b/src/extension.ts index 9bb3ad41..0e7d7224 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -51,6 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()), vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()), vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()), + vscode.commands.registerCommand("leetcode.cookieIn", () => leetCodeManager.signIn(true)), vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()), vscode.commands.registerCommand("leetcode.manageSessions", () => session.manageSessions()), vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)), diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index 96e3c0b0..1bbcf72f 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -34,7 +34,11 @@ class LeetCodeManager extends EventEmitter { } } - public async signIn(): Promise { + public async signIn(isCookieIn = false): Promise { + const loginArg = "-l"; + const cookieInArg = "-c"; + const commandArg = isCookieIn ? cookieInArg : loginArg; + const inMessage = isCookieIn ? "cookie in" : "sign in" try { const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise => { let result: string = ""; @@ -42,8 +46,8 @@ class LeetCodeManager extends EventEmitter { const leetCodeBinaryPath: string = await leetCodeExecutor.getLeetCodeBinaryPath(); const childProc: cp.ChildProcess = wsl.useWsl() - ? cp.spawn("wsl", [leetCodeExecutor.node, leetCodeBinaryPath, "user", "-l"], { shell: true }) - : cp.spawn(leetCodeExecutor.node, [leetCodeBinaryPath, "user", "-l"], { + ? cp.spawn("wsl", [leetCodeExecutor.node, leetCodeBinaryPath, "user", commandArg], { shell: true }) + : cp.spawn(leetCodeExecutor.node, [leetCodeBinaryPath, "user", commandArg], { shell: true, env: createEnvOption(), }); @@ -67,9 +71,9 @@ class LeetCodeManager extends EventEmitter { } childProc.stdin.write(`${name}\n`); const pwd: string | undefined = await vscode.window.showInputBox({ - prompt: "Enter password.", + prompt: isCookieIn ? "Enter cookie" : "Enter password.", password: true, - validateInput: (s: string): string | undefined => s ? undefined : "Password must not be empty", + validateInput: (s: string): string | undefined => s ? undefined : isCookieIn ? "Cookie must not be empty" : "Password must not be empty", }); if (!pwd) { childProc.kill(); @@ -78,22 +82,22 @@ class LeetCodeManager extends EventEmitter { childProc.stdin.write(`${pwd}\n`); childProc.stdin.end(); childProc.on("close", () => { - const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully login as (.*)/i); - if (match && match[1]) { - resolve(match[1]); + const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login) as (.*)/i); + if (match && match[2]) { + resolve(match[2]); } else { - reject(new Error("Failed to sign in.")); + reject(new Error(`Failed to ${inMessage}.`)); } }); }); if (userName) { - vscode.window.showInformationMessage("Successfully signed in."); + vscode.window.showInformationMessage(`Successfully ${inMessage}.`); this.currentUser = userName; this.userStatus = UserStatus.SignedIn; this.emit("statusChanged"); } } catch (error) { - promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details", DialogType.error); + promptForOpenOutputChannel(`Failed to ${inMessage}. Please open the output channel for details`, DialogType.error); } } From 312479082871e41a1331806f18431073dceb98ad Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Tue, 3 Dec 2019 16:33:26 +0800 Subject: [PATCH 2/6] try to fix ci first time --- src/leetCodeManager.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index 1bbcf72f..aefd9be6 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -34,11 +34,11 @@ class LeetCodeManager extends EventEmitter { } } - public async signIn(isCookieIn = false): Promise { - const loginArg = "-l"; - const cookieInArg = "-c"; - const commandArg = isCookieIn ? cookieInArg : loginArg; - const inMessage = isCookieIn ? "cookie in" : "sign in" + public async signIn(isCookieIn: boolean = false): Promise { + const loginArg: string = "-l"; + const cookieInArg: string = "-c"; + const commandArg: string = isCookieIn ? cookieInArg : loginArg; + const inMessage: string = isCookieIn ? "cookie in" : "sign in" try { const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise => { let result: string = ""; From 6ab8a3bb455591c24038c6eabe6577d565a2d7ae Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Tue, 3 Dec 2019 16:36:10 +0800 Subject: [PATCH 3/6] try to fix ci second time --- src/leetCodeManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index aefd9be6..d1819e2a 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -38,7 +38,7 @@ class LeetCodeManager extends EventEmitter { const loginArg: string = "-l"; const cookieInArg: string = "-c"; const commandArg: string = isCookieIn ? cookieInArg : loginArg; - const inMessage: string = isCookieIn ? "cookie in" : "sign in" + const inMessage: string = isCookieIn ? "cookie in" : "sign in"; try { const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise => { let result: string = ""; From 8d24d57a41df7b08d5635df31ed3c072b78b2250 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 4 Dec 2019 20:53:49 +0800 Subject: [PATCH 4/6] rename cookie in to Sign in (by cookie) --- README.md | 2 +- package.json | 6 +++--- src/extension.ts | 2 +- src/leetCodeManager.ts | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3e727458..84370516 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ - You can also use the following command to sign in/cookie in/out: - **LeetCode: Sign in** - - **LeetCode: Cookie in** + - **LeetCode: Sign in (by cookie)** - **LeetCode: Sign out** --- diff --git a/package.json b/package.json index b14fb6a8..f2a0d75d 100644 --- a/package.json +++ b/package.json @@ -38,15 +38,15 @@ "onCommand:leetcode.testSolution", "onCommand:leetcode.submitSolution", "onCommand:leetcode.switchDefaultLanguage", - "onCommand:leetcode.cookieIn", + "onCommand:leetcode.signinByCookie", "onView:leetCodeExplorer" ], "main": "./out/src/extension", "contributes": { "commands": [ { - "command": "leetcode.cookieIn", - "title": "Cookie In", + "command": "leetcode.signinByCookie", + "title": "Sign In By Cookie", "category": "LeetCode" }, { diff --git a/src/extension.ts b/src/extension.ts index 0e7d7224..45de4a70 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -51,7 +51,7 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()), vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()), vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()), - vscode.commands.registerCommand("leetcode.cookieIn", () => leetCodeManager.signIn(true)), + vscode.commands.registerCommand("leetcode.signinByCookie", () => leetCodeManager.signIn(true)), vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()), vscode.commands.registerCommand("leetcode.manageSessions", () => session.manageSessions()), vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)), diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index d1819e2a..0b70080e 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -34,11 +34,11 @@ class LeetCodeManager extends EventEmitter { } } - public async signIn(isCookieIn: boolean = false): Promise { + public async signIn(isByCookie: boolean = false): Promise { const loginArg: string = "-l"; - const cookieInArg: string = "-c"; - const commandArg: string = isCookieIn ? cookieInArg : loginArg; - const inMessage: string = isCookieIn ? "cookie in" : "sign in"; + const cookieArg: string = "-c"; + const commandArg: string = isByCookie ? cookieArg : loginArg; + const inMessage: string = isByCookie ? "sign in by cookie" : "sign in"; try { const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise => { let result: string = ""; @@ -71,9 +71,9 @@ class LeetCodeManager extends EventEmitter { } childProc.stdin.write(`${name}\n`); const pwd: string | undefined = await vscode.window.showInputBox({ - prompt: isCookieIn ? "Enter cookie" : "Enter password.", + prompt: isByCookie ? "Enter cookie" : "Enter password.", password: true, - validateInput: (s: string): string | undefined => s ? undefined : isCookieIn ? "Cookie must not be empty" : "Password must not be empty", + validateInput: (s: string): string | undefined => s ? undefined : isByCookie ? "Cookie must not be empty" : "Password must not be empty", }); if (!pwd) { childProc.kill(); From ae2fa0490fefa56eb8831806656338143d2f2e3a Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 4 Dec 2019 21:17:31 +0800 Subject: [PATCH 5/6] also change readme-cn --- README.md | 2 +- docs/README_zh-CN.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84370516..740f9913 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ - Simply click `Sign in to LeetCode` in the `LeetCode Explorer` will let you **sign in** with your LeetCode account. -- You can also use the following command to sign in/cookie in/out: +- You can also use the following command to sign in/sign in (by cookie)/out: - **LeetCode: Sign in** - **LeetCode: Sign in (by cookie)** - **LeetCode: Sign out** diff --git a/docs/README_zh-CN.md b/docs/README_zh-CN.md index 4c9348a1..f7570685 100644 --- a/docs/README_zh-CN.md +++ b/docs/README_zh-CN.md @@ -40,8 +40,9 @@ - 点击 `LeetCode Explorer` 中的 `Sign in to LeetCode` 即可登入。 -- 你也可以使用下来命令登入或登出: +- 你也可以使用下来命令登入或利用cookie登入或登出: - **LeetCode: Sign in** + - **LeetCode: Sign in (by cookie)** - **LeetCode: Sign out** --- From ed51cb5503b41c7c084ba99ee5325b23df0b0366 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Thu, 5 Dec 2019 10:07:51 +0800 Subject: [PATCH 6/6] fix preposition typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2a0d75d..149059de 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "commands": [ { "command": "leetcode.signinByCookie", - "title": "Sign In By Cookie", + "title": "Sign In by Cookie", "category": "LeetCode" }, {