Skip to content

Commit 63ea615

Browse files
committed
增加 计时器 配置是否开启
1 parent 5498207 commit 63ea615

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.19.4
2+
3+
- 增加 计时器 配置是否开启
4+
15
## version 2.19.3
26

37
- 修复某些情况下, allcase 没解析成功,如 1040 题

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.19.3",
5+
"version": "2.19.4",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -1011,6 +1011,12 @@
10111011
"scope": "application",
10121012
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description%"
10131013
},
1014+
"leetcode-problem-rating.enableTimerBar": {
1015+
"type": "boolean",
1016+
"default": true,
1017+
"scope": "application",
1018+
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description%"
1019+
},
10141020
"leetcode-problem-rating.editor.shortcuts": {
10151021
"type": "array",
10161022
"default": [

package.nls.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.",
7272
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.",
7373
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.",
74+
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "Show the LeetCode timer bar or not.",
7475
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "Customize the shortcuts in editors.",
7576
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [
7677
"Submit your answer to LeetCode.",

package.nls.zh-cn.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "用于存储问题文件的工作区文件夹的路径。",
7272
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "用于保存问题文件的输出文件夹和文件名。",
7373
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "是否显示状态栏。",
74+
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "是否显示计时器。",
7475
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "自定义编辑器中的快捷方式。",
7576
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [
7677
"提交题解",

src/service/StatusBarTimeService.ts

+36-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
* Copyright (c) 2022 ccagml . All rights reserved.
88
*/
99

10-
import { Disposable, StatusBarItem, window } from "vscode";
10+
import { Disposable, StatusBarItem, window, workspace, ConfigurationChangeEvent } from "vscode";
1111
import { IProblem, ISubmitEvent, OutPutType } from "../model/Model";
1212
import { promptForOpenOutputChannel } from "../utils/OutputUtils";
1313
import { getDayNow } from "../utils/SystemUtils";
14+
import { enableTimerBar } from "../utils/ConfigUtils";
1415

1516
// 状态栏工具
1617
class StatusBarTimeService implements Disposable {
18+
private configurationChangeListener: Disposable;
1719
private showBar: StatusBarItem;
1820
private startBar: StatusBarItem;
1921
private stopBar: StatusBarItem;
@@ -49,12 +51,21 @@ class StatusBarTimeService implements Disposable {
4951

5052
this.startTime = 0;
5153
this.saveTime = 0;
54+
55+
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
56+
if (event.affectsConfiguration("leetcode-problem-rating.enableTimerBar")) {
57+
this.setStatusBarVisibility();
58+
}
59+
}, this);
60+
this.setStatusBarVisibility();
5261
}
5362

5463
public showProblemFinish(node) {
55-
this.questionNode = node;
56-
this.reset();
57-
this.start();
64+
if (enableTimerBar()) {
65+
this.questionNode = node;
66+
this.reset();
67+
this.start();
68+
}
5869
}
5970

6071
private getDiffStr(diff: number) {
@@ -71,9 +82,11 @@ class StatusBarTimeService implements Disposable {
7182
}
7283

7384
public getCostTimeStr() {
74-
if (this.startTime && this.startTime > 0) {
75-
let diff = getDayNow() - this.startTime + this.saveTime;
76-
return this.getDiffStr(diff);
85+
if (enableTimerBar()) {
86+
if (this.startTime && this.startTime > 0) {
87+
let diff = getDayNow() - this.startTime + this.saveTime;
88+
return this.getDiffStr(diff);
89+
}
7790
}
7891
return;
7992
}
@@ -137,6 +150,22 @@ class StatusBarTimeService implements Disposable {
137150
this.startBar.dispose();
138151
this.stopBar.dispose();
139152
this.resetBar.dispose();
153+
this.configurationChangeListener.dispose();
154+
}
155+
// 设置可见性
156+
private setStatusBarVisibility(): void {
157+
if (enableTimerBar()) {
158+
this.showBar.show();
159+
this.startBar.show();
160+
this.stopBar.show();
161+
this.resetBar.show();
162+
} else {
163+
this.showBar.hide();
164+
this.startBar.hide();
165+
this.stopBar.hide();
166+
this.resetBar.hide();
167+
this.reset();
168+
}
140169
}
141170
}
142171

src/utils/ConfigUtils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ export function enableStatusBar(): boolean {
122122
return getVsCodeConfig().get<boolean>("enableStatusBar", true);
123123
}
124124

125+
// 状态栏定时器可见性
126+
export function enableTimerBar(): boolean {
127+
return getVsCodeConfig().get<boolean>("enableTimerBar", true);
128+
}
129+
125130
// 展示方式
126131
export function getDescriptionConfiguration(): IDescriptionConfiguration {
127132
const setting: string = getVsCodeConfig().get<string>("showDescription", DescriptionConfiguration.InWebView);

0 commit comments

Comments
 (0)