From e8df4556118f0b519f9afc30e8dcfa7bb7fb3f88 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 8 Feb 2026 01:58:21 +0100 Subject: [PATCH] Start stop run timer --- package.json | 4 ++++ src/extension.ts | 40 ++++++++++++++++++++++++++++++------- src/{startRun.ts => run.ts} | 9 ++++++++- 3 files changed, 45 insertions(+), 8 deletions(-) rename src/{startRun.ts => run.ts} (79%) diff --git a/package.json b/package.json index 77f1073..6d921a3 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,10 @@ "command": "devrun-vscode.startRun", "title": "DevRun: Start a Run" }, + { + "command": "devrun-vscode.stopRun", + "title": "DevRun: Stop the Run" + }, { "command": "devrun-vscode.startServer", "title": "DevRun: Start the run server (for quick run starts)" diff --git a/src/extension.ts b/src/extension.ts index 3bb95b2..187c1ae 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { startRun } from "./startRun"; +import { currentRun, startRun, stopRun } from "./run"; export function activate(context: vscode.ExtensionContext) { console.log("dev-run Activated"); @@ -12,9 +12,13 @@ export function activate(context: vscode.ExtensionContext) { statusBarItem.text = "$(clock) No run yet"; statusBarItem.show(); - let disposable = vscode.commands.registerCommand( - "devrun-vscode.startRun", - async () => { + context.subscriptions.push( + vscode.commands.registerCommand("devrun-vscode.startRun", async () => { + if (currentRun) { + vscode.window.showErrorMessage("You are already in a run"); + return; + } + const problemId = await vscode.window.showInputBox({ prompt: "Enter a valid problem ID", placeHolder: "my-problem", @@ -30,10 +34,32 @@ export function activate(context: vscode.ExtensionContext) { } startRun(statusBarItem, problemId); - }, + }), ); - context.subscriptions.push(disposable); + context.subscriptions.push( + vscode.commands.registerCommand("devrun-vscode.stopRun", async () => { + const isStop = await vscode.window.showWarningMessage( + "Are you sure you want to stop the run?", + { modal: true }, + "Yes", + "No", + ); + + if (isStop === "Yes") { + stopRun(); + statusBarItem.text = "$(clock) No run yet"; + } + }), + ); + + context.subscriptions.push( + vscode.commands.registerCommand("devrun-vscode.startServer", async () => { + + }), + ); } -export function deactivate() {} +export function deactivate() { + stopRun(); +} diff --git a/src/startRun.ts b/src/run.ts similarity index 79% rename from src/startRun.ts rename to src/run.ts index 8d42938..98d46da 100644 --- a/src/startRun.ts +++ b/src/run.ts @@ -1,5 +1,12 @@ import * as vscode from "vscode"; +export var currentRun: NodeJS.Timeout | null = null; + +export async function stopRun() { + + if (currentRun) clearTimeout(currentRun); +} + export async function startRun( statusBarItem: vscode.StatusBarItem, problemId: string, @@ -11,7 +18,7 @@ export async function startRun( let start = Date.now(); - const interval = setInterval(() => { + currentRun = setInterval(() => { const elapsed = Date.now() - start; const minutes = Math.floor(elapsed / 60000);