First commit
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "vsc-adda",
|
||||
"image": "git.kvarnarp.se/vscode/vsc-extension:latest",
|
||||
"updateRemoteUserUID": false,
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["esbenp.prettier-vscode"]
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
out/
|
||||
dist/
|
||||
node_modules/
|
||||
**/test
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
.env
|
||||
|
||||
5
.vscode-test.mjs
Normal file
5
.vscode-test.mjs
Normal file
@@ -0,0 +1,5 @@
|
||||
import { defineConfig } from '@vscode/test-cli';
|
||||
|
||||
export default defineConfig({
|
||||
files: 'out/test/**/*.test.js',
|
||||
});
|
||||
8
.vscode/extensions.json
vendored
Normal file
8
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"ms-vscode.extension-test-runner"
|
||||
]
|
||||
}
|
||||
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
.vscode/settings.json
vendored
Normal file
11
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
||||
20
.vscode/tasks.json
vendored
Normal file
20
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
12
.vscodeignore
Normal file
12
.vscodeignore
Normal file
@@ -0,0 +1,12 @@
|
||||
.devcontainer/**
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
src/**
|
||||
.gitignore
|
||||
.yarnrc
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/eslint.config.mjs
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/.vscode-test.*
|
||||
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to the "vsc-adda" extension will be documented in this file.
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Initial release
|
||||
27
README.md
27
README.md
@@ -1,12 +1,19 @@
|
||||
# README
|
||||
# vsc-adda README
|
||||
|
||||
## Getting started
|
||||
Just sit back, enjoy a good time coding, and let your gym’s visitor counter rest quietly in the corner — like a happy little cloud, always within sight but never in the way.
|
||||
|
||||
1. Create a new repository from this template.
|
||||
2. Open the repository in the dev container.
|
||||
3. Run the following command inside the container:
|
||||
```sh
|
||||
yo code .
|
||||
```
|
||||
4. Follow the prompts to scaffold your extension.
|
||||
5. Commit the generated project files.
|
||||
## Known Issues
|
||||
|
||||
Every masterpiece has its quirks — we’re aware of them, and we’ll gently brush them away.
|
||||
|
||||
## Release Notes
|
||||
|
||||
### 1.0.0
|
||||
|
||||
Initial release.
|
||||
|
||||
---
|
||||
|
||||
## Legal
|
||||
|
||||
_Adda_ is a trademark of Adda Hälsoperspektiv AB. All rights reserved.
|
||||
|
||||
BIN
assets/adda-128x128.png
Normal file
BIN
assets/adda-128x128.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
BIN
assets/adda.woff
Normal file
BIN
assets/adda.woff
Normal file
Binary file not shown.
5
assets/icons/fitness.svg
Normal file
5
assets/icons/fitness.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<svg viewBox="0 0 17 17" width="32" height="32" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="translate(0 17)" id="fitness" fill="currentColor">
|
||||
<path d="M12.1-7c0.2,0,0.4-0.2,0.4-0.5S12.3-8,12-8h-0.3c0-0.2-0.1-0.3-0.1-0.5h0.1c0.3,0,0.5-0.2,0.5-0.5S12-9.5,11.7-9.5h-0.3 c0-0.2-0.1-0.3-0.1-0.5h0.1c0.3,0,0.5-0.2,0.5-0.5S11.6-11,11.4-11h-0.3c-0.1-0.8-0.3-1.3-0.8-1.5v-2c0-0.2-0.1-0.4-0.3-0.5 c-0.2,0-0.4,0-0.5,0.1l-2.1,2C6.6-13.2,6-13.8,6-14.8c0-0.2,0-1.1,0-1.1c0-0.1,0-0.4-0.1-0.5c0-0.1-0.1-0.2-0.2-0.3 c-0.1-0.1-0.2-0.2-0.3-0.2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After Width: | Height: | Size: 1.6 KiB |
27
eslint.config.mjs
Normal file
27
eslint.config.mjs
Normal file
@@ -0,0 +1,27 @@
|
||||
import typescriptEslint from "typescript-eslint";
|
||||
|
||||
export default [{
|
||||
files: ["**/*.ts"],
|
||||
}, {
|
||||
plugins: {
|
||||
"@typescript-eslint": typescriptEslint.plugin,
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
parser: typescriptEslint.parser,
|
||||
ecmaVersion: 2022,
|
||||
sourceType: "module",
|
||||
},
|
||||
|
||||
rules: {
|
||||
"@typescript-eslint/naming-convention": ["warn", {
|
||||
selector: "import",
|
||||
format: ["camelCase", "PascalCase"],
|
||||
}],
|
||||
|
||||
curly: "warn",
|
||||
eqeqeq: "warn",
|
||||
"no-throw-literal": "warn",
|
||||
semi: "warn",
|
||||
},
|
||||
}];
|
||||
6794
package-lock.json
generated
Normal file
6794
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
package.json
Normal file
53
package.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "vsc-adda",
|
||||
"displayName": "Adda",
|
||||
"description": "Track the number of checked-in visitors at Adda Hälsoperspektiv AB.",
|
||||
"version": "0.0.1",
|
||||
"publisher": "oaklake89",
|
||||
"preview": true,
|
||||
"engines": {
|
||||
"vscode": "^1.109.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "vsc-adda.refresh",
|
||||
"category": "Adda",
|
||||
"title": "Refresh"
|
||||
}
|
||||
],
|
||||
"icons": {
|
||||
"adda-fitness": {
|
||||
"description": "Fitness icon",
|
||||
"default": {
|
||||
"fontPath": "assets/adda.woff",
|
||||
"fontCharacter": "\\e900"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src",
|
||||
"test": "vscode-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "22.x",
|
||||
"@types/vscode": "^1.109.0",
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
"@vscode/test-electron": "^2.5.2",
|
||||
"@vscode/vsce": "^3.7.1",
|
||||
"eslint": "^9.39.3",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.56.1"
|
||||
}
|
||||
}
|
||||
65
src/extension.ts
Normal file
65
src/extension.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { getVisitorCount } from './http';
|
||||
import { initStatusBar, refresh } from './statusBar';
|
||||
|
||||
const OPEN = 4;
|
||||
const CLOSE = 23;
|
||||
const INTERVAL_MS = 2 * 60 * 1000;
|
||||
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
const subscriptions = context.subscriptions;
|
||||
const commandId = 'vsc-adda.refresh';
|
||||
|
||||
const item = initStatusBar(getVisitorCount, commandId);
|
||||
subscriptions.push(item);
|
||||
|
||||
subscriptions.push(
|
||||
vscode.commands.registerCommand(commandId, async () => {
|
||||
await refresh();
|
||||
})
|
||||
);
|
||||
|
||||
await refresh();
|
||||
scheduleNext();
|
||||
|
||||
subscriptions.push({ dispose: () => timer && clearTimeout(timer) });
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
function isOpen(d: Date = new Date()): boolean {
|
||||
return d.getHours() >= OPEN && d.getHours() < CLOSE;
|
||||
}
|
||||
|
||||
function timeUntilOpenMs(from: Date = new Date()): number {
|
||||
const next = new Date(from);
|
||||
if (from.getHours() < OPEN) {
|
||||
next.setHours(OPEN, 0, 0, 0);
|
||||
} else {
|
||||
next.setDate(next.getDate() + 1);
|
||||
next.setHours(OPEN, 0, 0, 0);
|
||||
}
|
||||
return next.getTime() - from.getTime();
|
||||
}
|
||||
|
||||
function scheduleNext(): void {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
if (isOpen()) {
|
||||
timer = setTimeout(() => {
|
||||
refresh().finally(scheduleNext);
|
||||
}, INTERVAL_MS);
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
refresh().finally(scheduleNext);
|
||||
}, timeUntilOpenMs());
|
||||
}
|
||||
}
|
||||
37
src/http.ts
Normal file
37
src/http.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as https from 'https';
|
||||
|
||||
export function getVisitorCount(): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.get('https://www.gymcontrol.se/global/checkedin/checkedin.php?uid=9094', (res) => {
|
||||
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
||||
res.resume();
|
||||
reject(new Error(`HTTP ${res.statusCode ?? '?'}`));
|
||||
return;
|
||||
}
|
||||
|
||||
res.setEncoding('utf8');
|
||||
|
||||
let raw = '';
|
||||
res.on('data', (chunk) => {
|
||||
raw += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
const text = raw.trim();
|
||||
const n = Number.parseInt(text, 10);
|
||||
|
||||
if (Number.isFinite(n)) {
|
||||
resolve(n);
|
||||
} else {
|
||||
reject(new Error(`Invalid response: "${text}"`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
|
||||
req.setTimeout(5000, () => {
|
||||
req.destroy(new Error('Timeout after 5000 ms'));
|
||||
});
|
||||
});
|
||||
}
|
||||
42
src/statusBar.ts
Normal file
42
src/statusBar.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const TOOLTIP_TEXT = 'Current Gym Visitors';
|
||||
|
||||
let item: vscode.StatusBarItem;
|
||||
let getCount: (() => Promise<number>) | undefined;
|
||||
|
||||
export function initStatusBar(getVisitorCount: () => Promise<number>, commandId: string): vscode.StatusBarItem {
|
||||
getCount = getVisitorCount;
|
||||
|
||||
item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1000);
|
||||
item.command = commandId;
|
||||
item.text = '$(adda-fitness) 0';
|
||||
item.tooltip = TOOLTIP_TEXT;
|
||||
item.show();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
export async function refresh(): Promise<void> {
|
||||
if (!item || !getCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
item.text = '$(adda-fitness) $(sync~spin)';
|
||||
|
||||
try {
|
||||
const [count] = await Promise.all([getCount(), sleep(1500)]);
|
||||
|
||||
item.text = `$(adda-fitness) ${count}`;
|
||||
item.tooltip = TOOLTIP_TEXT;
|
||||
} catch (e: any) {
|
||||
item.text = '$(warning) Adda';
|
||||
item.tooltip = e?.message ?? 'Unknown error';
|
||||
} finally {
|
||||
item.show();
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "Node16",
|
||||
"target": "ES2022",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"ES2022"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true, /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user