Start stop run timer
This commit is contained in:
@@ -19,6 +19,10 @@
|
|||||||
"command": "devrun-vscode.startRun",
|
"command": "devrun-vscode.startRun",
|
||||||
"title": "DevRun: Start a Run"
|
"title": "DevRun: Start a Run"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "devrun-vscode.stopRun",
|
||||||
|
"title": "DevRun: Stop the Run"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "devrun-vscode.startServer",
|
"command": "devrun-vscode.startServer",
|
||||||
"title": "DevRun: Start the run server (for quick run starts)"
|
"title": "DevRun: Start the run server (for quick run starts)"
|
||||||
|
|||||||
+33
-7
@@ -1,5 +1,5 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import { startRun } from "./startRun";
|
import { currentRun, startRun, stopRun } from "./run";
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
console.log("dev-run Activated");
|
console.log("dev-run Activated");
|
||||||
@@ -12,9 +12,13 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
statusBarItem.text = "$(clock) No run yet";
|
statusBarItem.text = "$(clock) No run yet";
|
||||||
statusBarItem.show();
|
statusBarItem.show();
|
||||||
|
|
||||||
let disposable = vscode.commands.registerCommand(
|
context.subscriptions.push(
|
||||||
"devrun-vscode.startRun",
|
vscode.commands.registerCommand("devrun-vscode.startRun", async () => {
|
||||||
async () => {
|
if (currentRun) {
|
||||||
|
vscode.window.showErrorMessage("You are already in a run");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const problemId = await vscode.window.showInputBox({
|
const problemId = await vscode.window.showInputBox({
|
||||||
prompt: "Enter a valid problem ID",
|
prompt: "Enter a valid problem ID",
|
||||||
placeHolder: "my-problem",
|
placeHolder: "my-problem",
|
||||||
@@ -30,10 +34,32 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startRun(statusBarItem, problemId);
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
|
export var currentRun: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
export async function stopRun() {
|
||||||
|
|
||||||
|
if (currentRun) clearTimeout(currentRun);
|
||||||
|
}
|
||||||
|
|
||||||
export async function startRun(
|
export async function startRun(
|
||||||
statusBarItem: vscode.StatusBarItem,
|
statusBarItem: vscode.StatusBarItem,
|
||||||
problemId: string,
|
problemId: string,
|
||||||
@@ -11,7 +18,7 @@ export async function startRun(
|
|||||||
|
|
||||||
let start = Date.now();
|
let start = Date.now();
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
currentRun = setInterval(() => {
|
||||||
const elapsed = Date.now() - start;
|
const elapsed = Date.now() - start;
|
||||||
|
|
||||||
const minutes = Math.floor(elapsed / 60000);
|
const minutes = Math.floor(elapsed / 60000);
|
||||||
Reference in New Issue
Block a user