Working example with start cancel

This commit is contained in:
2025-08-06 09:46:10 -05:00
parent 02a7eb8090
commit 2ef3cae6eb
6 changed files with 93 additions and 12 deletions
+2 -1
View File
@@ -7,7 +7,8 @@
"request": "launch", "request": "launch",
"runtimeExecutable": "${execPath}", "runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"], "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"] "outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: compile"
} }
] ]
} }
+12
View File
@@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "npm: compile",
"type": "shell",
"command": "npm run compile",
"group": "build",
"problemMatcher": []
}
]
}
+18
View File
@@ -8,6 +8,7 @@
"name": "speed-code", "name": "speed-code",
"version": "0.0.1", "version": "0.0.1",
"devDependencies": { "devDependencies": {
"@types/node": "^24.2.0",
"@types/vscode": "^1.70.0", "@types/vscode": "^1.70.0",
"tslint": "^6.0.0", "tslint": "^6.0.0",
"typescript": "^5.0.0" "typescript": "^5.0.0"
@@ -41,6 +42,16 @@
"node": ">=6.9.0" "node": ">=6.9.0"
} }
}, },
"node_modules/@types/node": {
"version": "24.2.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.0.tgz",
"integrity": "sha512-3xyG3pMCq3oYCNg7/ZP+E1ooTaGB4cG8JWRsqqOYQdbWNY4zbaV0Ennrd7stjiJEFZCaybcIgpTjJWHRfBSIDw==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.10.0"
}
},
"node_modules/@types/vscode": { "node_modules/@types/vscode": {
"version": "1.102.0", "version": "1.102.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.102.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.102.0.tgz",
@@ -497,6 +508,13 @@
"node": ">=14.17" "node": ">=14.17"
} }
}, },
"node_modules/undici-types": {
"version": "7.10.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz",
"integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==",
"dev": true,
"license": "MIT"
},
"node_modules/wrappy": { "node_modules/wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+11 -4
View File
@@ -6,13 +6,19 @@
"engines": { "engines": {
"vscode": "^1.70.0" "vscode": "^1.70.0"
}, },
"activationEvents": [], "activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js", "main": "./out/extension.js",
"contributes": { "contributes": {
"commands": [ "commands": [
{ {
"command": "speed-code.startSpeedRun", "command": "speed-code.startSpeedRun",
"title": "Hello World" "title": "Start Speed Run"
},
{
"command": "speed-code.cancelSpeedRun",
"title": "Cancel Speed Run"
} }
] ]
}, },
@@ -22,8 +28,9 @@
"watch": "tsc -watch -p ./" "watch": "tsc -watch -p ./"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^24.2.0",
"@types/vscode": "^1.70.0", "@types/vscode": "^1.70.0",
"typescript": "^5.0.0", "tslint": "^6.0.0",
"tslint": "^6.0.0" "typescript": "^5.0.0"
} }
} }
+48 -6
View File
@@ -1,11 +1,53 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) { let resetTimer = () => {}
const disposable = vscode.commands.registerCommand('speed-code.startSpeedRun', () => {
vscode.window.showInformationMessage('Hello World from My Extension!');
});
context.subscriptions.push(disposable); export function activate(context: vscode.ExtensionContext) {
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
statusBarItem.tooltip = 'Speedrun timer';
statusBarItem.text = "No active Speedrun";
statusBarItem.show();
let timer: undefined | NodeJS.Timeout;
resetTimer = () => {
if (timer) {
clearInterval(timer);
}
statusBarItem.text = "No active Speedrun";
};
resetTimer();
context.subscriptions.push(vscode.commands.registerCommand('speed-code.startSpeedRun', () => {
const startTime = Date.now();
timer = setInterval(() => {
const currentTime = Date.now();
const timeSeconds = (currentTime - startTime) / 1000;
if (timeSeconds > 86400) {
const days = Math.floor(timeSeconds / 86400);
const hours = Math.floor(timeSeconds / 3600);
const minutes = Math.floor(timeSeconds / 60);
statusBarItem.text = `${days}:${hours - (days * 24)}:${minutes - (hours * 60)}:${(timeSeconds - (minutes * 60)).toFixed(3)}`;
} else if (timeSeconds >= 3600) {
const hours = Math.floor(timeSeconds / 3600);
const minutes = Math.floor(timeSeconds / 60);
statusBarItem.text = `${hours}:${minutes - (hours * 60)}:${(timeSeconds - (minutes * 60)).toFixed(3)}`;
} else if (timeSeconds >= 60) {
const minutes = Math.floor(timeSeconds / 60);
statusBarItem.text = `${minutes}:${(timeSeconds - (minutes * 60)).toFixed(3)}`;
} else {
statusBarItem.text = `${timeSeconds}`;
}
statusBarItem.color = '#fff';
}, 10);
vscode.window.showInformationMessage('Speedrun Started!');
}), statusBarItem);
context.subscriptions.push(vscode.commands.registerCommand('speed-code.cancelSpeedRun', resetTimer), statusBarItem);
} }
export function deactivate() {} export function deactivate() {
resetTimer();
}
+2 -1
View File
@@ -7,7 +7,8 @@
"rootDir": "src", "rootDir": "src",
"strict": true, "strict": true,
"esModuleInterop": true, "esModuleInterop": true,
"skipLibCheck": true "skipLibCheck": true,
"types": ["node", "vscode"]
}, },
"exclude": ["node_modules", ".vscode-test"] "exclude": ["node_modules", ".vscode-test"]
} }