Skip to content

Commit 41bf5cb

Browse files
committed
update
1 parent 4c21b29 commit 41bf5cb

File tree

9 files changed

+37
-37
lines changed

9 files changed

+37
-37
lines changed

src/childProcessCall/commands/plugin.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PluginCommand {
5050
handler = function (argv) {
5151
session.argv = argv;
5252

53-
let plugins = myPluginBase.plugins;
53+
let all_plugin = myPluginBase.installed;
5454
const name = argv.name;
5555

5656
// if (argv.install) {
@@ -64,21 +64,22 @@ class PluginCommand {
6464
// return;
6565
// }
6666

67-
if (name) plugins = plugins.filter(x => x.name === name);
68-
if (plugins.length === 0) return log.fatal('Plugin not found!');
69-
70-
const p = plugins[0];
71-
if (p.missing && (argv.enable || argv.disable))
72-
return log.fatal('Plugin missing, install it first');
67+
if (name) {
68+
all_plugin = all_plugin.filter(x => x.name === name);
69+
};
70+
if (all_plugin.length === 0) {
71+
return log.fatal('Plugin not found!');
72+
}
7373

74+
const p = all_plugin[0];
7475
if (argv.enable) {
7576
p.enabled = true;
7677
p.save();
7778
} else if (argv.disable) {
7879
p.enabled = false;
7980
p.save();
8081
} else if (argv.delete) {
81-
p.delete();
82+
// p.delete();
8283
p.save();
8384
myPluginBase.init();
8485
} else if (argv.config) {

src/childProcessCall/file.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ class File {
6969
return path.join(this.homeDir(), 'config.json');
7070
};
7171

72-
public pluginFile(name) {
73-
return path.join(this.codeDir('lib/plugins'), path.basename(name));
74-
};
75-
7672
public listCodeDir(dir) {
7773
dir = this.codeDir(dir);
7874
return this.list(dir).map(function (f) {
@@ -145,7 +141,7 @@ class File {
145141
};
146142

147143
public render(tpl, data) {
148-
const tplfile = path.join(__dirname, "..", "..", "..", "..", "resources", "templates", tpl + '.tpl');
144+
const tplfile = path.join(__dirname, "..", "..", "..", "resources", "templates", tpl + '.tpl');
149145
let result = _.template(this.data(tplfile).replace(/\r\n/g, '\n'))(data);
150146
if (this.isWindows()) {
151147
result = result.replace(/\n/g, '\r\n');

src/childProcessCall/my_plugin_base.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export class MyPluginBase {
2323
desc;
2424
enabled;
2525
deleted;
26-
missing;
2726
builtin;
2827
deps;
2928
next;
3029
plugins: Array<any> = [];
30+
installed: Array<MyPluginBase> = [];
3131
head; // 插件头 是core
3232
config;
3333
constructor() {
@@ -37,7 +37,6 @@ export class MyPluginBase {
3737
const stats = cache.get(helper.KEYS.plugins) || {};
3838

3939
if (this.deleted) delete stats[this.name];
40-
else if (this.missing) return;
4140
else stats[this.name] = this.enabled;
4241

4342
cache.set(helper.KEYS.plugins, stats);
@@ -51,8 +50,8 @@ export class MyPluginBase {
5150
public base_init(head?) {
5251
head = head || require('./core').corePlugin;
5352
const stats = cache.get(helper.KEYS.plugins) || {};
54-
let installed: Array<MyPluginBase> = [];
5553
let file_plugin: Array<any> = file.listCodeDir('plugins');
54+
this.installed = [];
5655
for (let f of file_plugin) {
5756
const p = f.data;
5857
if (!p) continue;
@@ -65,19 +64,19 @@ export class MyPluginBase {
6564
p.enabled = false;
6665
}
6766
}
68-
installed.push(p);
67+
this.installed.push(p);
6968
}
7069
// 根据id大小排序, 大的前面
71-
installed = underscore.sortBy(installed, x => -x.id);
70+
this.installed = underscore.sortBy(this.installed, x => -x.id);
7271
// 从小的开始init
73-
for (let i = installed.length - 1; i >= 0; --i) {
74-
const p = installed[i];
72+
for (let i = this.installed.length - 1; i >= 0; --i) {
73+
const p = this.installed[i];
7574
if (p.enabled) {
7675
p.init();
7776
}
7877
}
7978
// 连成链表状
80-
this.plugins = installed.filter(x => x.enabled);
79+
this.plugins = this.installed.filter(x => x.enabled);
8180
let last = head;
8281
for (let p of this.plugins) {
8382
last.setNext(p);

src/controller/EventController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { eventService } from "../service/EventService";
11+
// 事件的控制器
1112
class EventContorller {
1213
/**
1314
* 监听事件

src/controller/FileButtonController.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@
99

1010

1111
import { ConfigurationChangeEvent, Disposable, languages, workspace } from "vscode";
12-
import { fileButtonService, FileButtonService } from "../service/FileButtonService";
13-
12+
import { fileButtonService } from "../service/FileButtonService";
13+
// 文件按钮的控制器
1414
class FileButtonController implements Disposable {
15-
private internalProvider: FileButtonService;
15+
1616
private registeredProvider: Disposable | undefined;
1717
private configurationChangeListener: Disposable;
1818

1919
constructor() {
20-
this.internalProvider = fileButtonService;
21-
2220
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
2321
if (event.affectsConfiguration("leetcode-problem-rating.editor.shortcuts")) {
24-
this.internalProvider.refresh();
22+
fileButtonService.refresh();
2523
}
2624
}, this);
2725

28-
this.registeredProvider = languages.registerCodeLensProvider({ scheme: "file" }, this.internalProvider);
26+
this.registeredProvider = languages.registerCodeLensProvider({ scheme: "file" }, fileButtonService);
2927
}
3028

3129
public dispose(): void {

src/controller/LoginController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LoginContorller {
3030
picks.push(
3131
{
3232
label: "LeetCode Account",
33-
detail: "Use LeetCode account to login (US endpoint is not supported)",
33+
detail: "只能登录leetcode.cn",
3434
value: "LeetCode",
3535
},
3636
{
@@ -157,7 +157,7 @@ class LoginContorller {
157157
window.showInformationMessage("Successfully signed out.");
158158
eventService.emit("statusChanged", UserStatus.SignedOut, undefined);
159159
} catch (error) {
160-
promptForOpenOutputChannel(`Failed to signOut. Please open the output channel for details`, DialogType.error);
160+
// promptForOpenOutputChannel(`Failed to signOut. Please open the output channel for details`, DialogType.error);
161161
}
162162
}
163163

src/controller/MainController.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ class MainContorller {
2727
}
2828
}
2929

30+
// 初始化上下文
3031
public initialize(context: ExtensionContext) {
3132
treeDataService.initialize(context);
3233
}
3334

3435

35-
/**
36-
* name
37-
*/
36+
// 删除缓存
3837
public async deleteCache() {
3938
await executeService.deleteCache();
4039
}

src/extension.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ import { loginContorller } from "./controller/LoginController";
2727
import { getLeetCodeEndpoint } from "./utils/ConfigUtils";
2828
import { DialogType } from "./model/Model";
2929

30-
30+
// 激活插件
3131
export async function activate(context: ExtensionContext): Promise<void> {
3232
try {
3333

34+
// 初始化控制器
35+
mainContorller.initialize(context);
36+
// 检查node环境
3437
await mainContorller.checkNodeEnv(context);
38+
// 事件监听
3539
eventController.add_event();
36-
mainContorller.initialize(context);
3740

41+
// 资源管理
3842
context.subscriptions.push(
3943
statusBarService,
4044
logOutput,
@@ -68,7 +72,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
6872
commands.registerCommand("leetcode.problems.sort", () => treeViewController.switchSortingStrategy()),
6973
);
7074

75+
// 设置站点
7176
await executeService.switchEndpoint(getLeetCodeEndpoint());
77+
// 获取登录状态
7278
await loginContorller.getLoginStatus();
7379
} catch (error) {
7480
logOutput.appendLine(error.toString());

src/service/TreeDataService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TreeDataService implements vscode.TreeDataProvider<NodeModel> {
5151
collapsibleState: vscode.TreeItemCollapsibleState.None,
5252
command: {
5353
command: "leetcode.signin",
54-
title: "Sign in to LeetCode",
54+
title: "未登录",
5555
},
5656
};
5757
}
@@ -80,7 +80,7 @@ export class TreeDataService implements vscode.TreeDataProvider<NodeModel> {
8080
return [
8181
new NodeModel(Object.assign({}, defaultProblem, {
8282
id: "notSignIn",
83-
name: "Sign in to LeetCode",
83+
name: "未登录",
8484
}), false),
8585
];
8686
}

0 commit comments

Comments
 (0)