Skip to content

增加 计时器 配置是否开启 #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.19.4

- 增加 计时器 配置是否开启

## version 2.19.3

- 修复某些情况下, allcase 没解析成功,如 1040 题
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "%main.description%",
"version": "2.19.3",
"version": "2.19.4",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -1011,6 +1011,12 @@
"scope": "application",
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description%"
},
"leetcode-problem-rating.enableTimerBar": {
"type": "boolean",
"default": true,
"scope": "application",
"description": "%main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description%"
},
"leetcode-problem-rating.editor.shortcuts": {
"type": "array",
"default": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "The path of the workspace folder to store the problem files.",
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "The output folder and filename to save the problem files.",
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "Show the LeetCode status bar or not.",
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "Show the LeetCode timer bar or not.",
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "Customize the shortcuts in editors.",
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [
"Submit your answer to LeetCode.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"main.contributes.configuration.properties.leetcode-problem-rating.workspaceFolder.description": "用于存储问题文件的工作区文件夹的路径。",
"main.contributes.configuration.properties.leetcode-problem-rating.filePath.description": "用于保存问题文件的输出文件夹和文件名。",
"main.contributes.configuration.properties.leetcode-problem-rating.enableStatusBar.description": "是否显示状态栏。",
"main.contributes.configuration.properties.leetcode-problem-rating.enableTimerBar.description": "是否显示计时器。",
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.description": "自定义编辑器中的快捷方式。",
"main.contributes.configuration.properties.leetcode-problem-rating.editor.shortcuts.items.enumDescriptions": [
"提交题解",
Expand Down
43 changes: 36 additions & 7 deletions src/service/StatusBarTimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* Copyright (c) 2022 ccagml . All rights reserved.
*/

import { Disposable, StatusBarItem, window } from "vscode";
import { Disposable, StatusBarItem, window, workspace, ConfigurationChangeEvent } from "vscode";
import { IProblem, ISubmitEvent, OutPutType } from "../model/Model";
import { promptForOpenOutputChannel } from "../utils/OutputUtils";
import { getDayNow } from "../utils/SystemUtils";
import { enableTimerBar } from "../utils/ConfigUtils";

// 状态栏工具
class StatusBarTimeService implements Disposable {
private configurationChangeListener: Disposable;
private showBar: StatusBarItem;
private startBar: StatusBarItem;
private stopBar: StatusBarItem;
Expand Down Expand Up @@ -49,12 +51,21 @@ class StatusBarTimeService implements Disposable {

this.startTime = 0;
this.saveTime = 0;

this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("leetcode-problem-rating.enableTimerBar")) {
this.setStatusBarVisibility();
}
}, this);
this.setStatusBarVisibility();
}

public showProblemFinish(node) {
this.questionNode = node;
this.reset();
this.start();
if (enableTimerBar()) {
this.questionNode = node;
this.reset();
this.start();
}
}

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

public getCostTimeStr() {
if (this.startTime && this.startTime > 0) {
let diff = getDayNow() - this.startTime + this.saveTime;
return this.getDiffStr(diff);
if (enableTimerBar()) {
if (this.startTime && this.startTime > 0) {
let diff = getDayNow() - this.startTime + this.saveTime;
return this.getDiffStr(diff);
}
}
return;
}
Expand Down Expand Up @@ -137,6 +150,22 @@ class StatusBarTimeService implements Disposable {
this.startBar.dispose();
this.stopBar.dispose();
this.resetBar.dispose();
this.configurationChangeListener.dispose();
}
// 设置可见性
private setStatusBarVisibility(): void {
if (enableTimerBar()) {
this.showBar.show();
this.startBar.show();
this.stopBar.show();
this.resetBar.show();
} else {
this.showBar.hide();
this.startBar.hide();
this.stopBar.hide();
this.resetBar.hide();
this.reset();
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/ConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export function enableStatusBar(): boolean {
return getVsCodeConfig().get<boolean>("enableStatusBar", true);
}

// 状态栏定时器可见性
export function enableTimerBar(): boolean {
return getVsCodeConfig().get<boolean>("enableTimerBar", true);
}

// 展示方式
export function getDescriptionConfiguration(): IDescriptionConfiguration {
const setting: string = getVsCodeConfig().get<string>("showDescription", DescriptionConfiguration.InWebView);
Expand Down