1
1
"use strict" ;
2
2
3
+ import * as fse from "fs-extra" ;
4
+ import * as os from "os" ;
5
+ import * as path from "path" ;
3
6
import * as vscode from "vscode" ;
4
7
import { leetCodeExecutor } from "../leetCodeExecutor" ;
5
8
import { IQuickItemEx } from "../shared" ;
6
9
import { Endpoint } from "../shared" ;
7
10
import { DialogType , promptForOpenOutputChannel , promptForSignIn } from "../utils/uiUtils" ;
11
+ import { deleteCache } from "./cache" ;
8
12
9
13
export async function toogleLeetCodeCn ( ) : Promise < void > {
10
14
const isCnEnbaled : boolean = isLeetCodeCnEnabled ( ) ;
@@ -40,15 +44,20 @@ export async function toogleLeetCodeCn(): Promise<void> {
40
44
41
45
try {
42
46
await vscode . commands . executeCommand ( "leetcode.signout" ) ;
43
- await vscode . commands . executeCommand ( "leetcode. deleteCache" ) ;
47
+ await deleteCache ( ) ;
44
48
await promptForSignIn ( ) ;
45
49
} catch ( error ) {
46
50
await promptForOpenOutputChannel ( "Failed to sign in. Please open the output channel for details." , DialogType . error ) ;
47
51
}
48
52
}
49
53
50
54
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
+ }
52
61
}
53
62
54
63
export function isLeetCodeCnEnabled ( ) : boolean {
@@ -59,3 +68,12 @@ export function isLeetCodeCnEnabled(): boolean {
59
68
}
60
69
return false ;
61
70
}
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