From 66c4e3a8d5b9806d7dcc4c8b65216f8183b5e886 Mon Sep 17 00:00:00 2001 From: Violet Evergarden <2929724643@qq.com> Date: Sun, 17 May 2026 17:10:16 +0800 Subject: [PATCH] feat: add HTTP Basic Auth support for nginx reverse proxy - Add host, port, authUser, authPassword config settings in package.json - Read settings in extension.ts and inject Authorization header into axios --- package.json | 20 ++++++++++++++++++++ src/extension.ts | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 78e2e74..9bfe072 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,26 @@ "type": "object", "title": "aw-watcher-vscode extension configuration", "properties": { + "aw-watcher-vscode.host": { + "type": "string", + "default": "", + "description": "ActivityWatch server hostname. Leave empty for localhost." + }, + "aw-watcher-vscode.port": { + "type": "number", + "default": 0, + "description": "ActivityWatch server port. Set to 0 for default (5600)." + }, + "aw-watcher-vscode.authUser": { + "type": "string", + "default": "", + "description": "Username for HTTP Basic Auth (for nginx-proxied servers)." + }, + "aw-watcher-vscode.authPassword": { + "type": "string", + "default": "", + "description": "Password for HTTP Basic Auth (for nginx-proxied servers)." + }, "aw-watcher-vscode.maxHeartbeatsPerSec": { "type": "number", "default": 1, diff --git a/src/extension.ts b/src/extension.ts index b54452b..9d7de9c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -50,8 +50,28 @@ class ActivityWatch { }; this._bucket.id = `${this._bucket.clientName}_${this._bucket.hostName}`; + // Read server configuration + const extConfig = workspace.getConfiguration('aw-watcher-vscode'); + const host = extConfig.get('host') || ''; + const port = extConfig.get('port') || 0; + const authUser = extConfig.get('authUser') || ''; + const authPassword = extConfig.get('authPassword') || ''; + + // Build client options + const clientOptions: any = { testing: false }; + if (host) { + const effectivePort = port || 5600; + clientOptions.baseURL = `http://${host}:${effectivePort}`; + } + // Create AWClient - this._client = new AWClient(this._bucket.clientName, { testing: false }); + this._client = new AWClient(this._bucket.clientName, clientOptions); + + // Inject Basic Auth into axios instance if configured + if (authUser && authPassword) { + const token = Buffer.from(`${authUser}:${authPassword}`).toString('base64'); + this._client.req.defaults.headers.common['Authorization'] = `Basic ${token}`; + } // subscribe to VS Code Events let subscriptions: Disposable[] = [];