diff --git a/CHANGELOG.md b/CHANGELOG.md index d432ac1..35c5d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.19.4 + +- 增加 计时器 配置是否开启 + ## version 2.19.3 - 修复某些情况下, allcase 没解析成功,如 1040 题 diff --git a/package.json b/package.json index ff0fbe1..f113166 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [ diff --git a/package.nls.json b/package.nls.json index f019dac..6b45439 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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.", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index 0186908..e18d5ba 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -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": [ "提交题解", diff --git a/src/service/StatusBarTimeService.ts b/src/service/StatusBarTimeService.ts index 10f03b1..eb0e0ed 100644 --- a/src/service/StatusBarTimeService.ts +++ b/src/service/StatusBarTimeService.ts @@ -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; @@ -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) { @@ -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; } @@ -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(); + } } } diff --git a/src/utils/ConfigUtils.ts b/src/utils/ConfigUtils.ts index d481952..d8d7d00 100644 --- a/src/utils/ConfigUtils.ts +++ b/src/utils/ConfigUtils.ts @@ -122,6 +122,11 @@ export function enableStatusBar(): boolean { return getVsCodeConfig().get("enableStatusBar", true); } +// 状态栏定时器可见性 +export function enableTimerBar(): boolean { + return getVsCodeConfig().get("enableTimerBar", true); +} + // 展示方式 export function getDescriptionConfiguration(): IDescriptionConfiguration { const setting: string = getVsCodeConfig().get("showDescription", DescriptionConfiguration.InWebView);