11"use strict" ;
22
3+ import * as fse from "fs-extra" ;
4+ import * as os from "os" ;
5+ import * as path from "path" ;
36import * as vscode from "vscode" ;
47import { leetCodeExecutor } from "../leetCodeExecutor" ;
58import { IQuickItemEx } from "../shared" ;
69import { Endpoint } from "../shared" ;
710import { DialogType , promptForOpenOutputChannel , promptForSignIn } from "../utils/uiUtils" ;
11+ import { deleteCache } from "./cache" ;
812
913export 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
5054export 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
5463export 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