From 26e8f697d5ac618a8c7dd716f46cb606d3047bc0 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 22 Nov 2024 11:11:46 +0100 Subject: [PATCH] Support forks of vscode in web extension --- src/utils.ts | 21 +++++++++++++++++++++ src/wakatime.ts | 19 +------------------ src/web/wakatime.ts | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 2d76f21..dbf73d7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,17 @@ import * as vscode from 'vscode'; export class Utils { + private static appNames = { + 'Arduino IDE': 'arduino', + 'Azure Data Studio': 'azdata', + Cursor: 'cursor', + Onivim: 'onivim', + 'Onivim 2': 'onivim', + 'SQL Operations Studio': 'sqlops', + 'Visual Studio Code': 'vscode', + Windsurf: 'windsurf', + }; + public static quote(str: string): string { if (str.includes(' ')) return `"${str.replace('"', '\\"')}"`; return str; @@ -104,4 +115,14 @@ export class Utils { if (!uri) return false; return uri.scheme == 'pr'; } + + public static getEditorName(): string { + if (this.appNames[vscode.env.appName]) { + return this.appNames[vscode.env.appName]; + } else if (vscode.env.appName.toLowerCase().includes('visual')) { + return 'vscode'; + } else { + return vscode.env.appName.replace(/\s/g, '').toLowerCase(); + } + } } diff --git a/src/wakatime.ts b/src/wakatime.ts index dadad27..6c4fac6 100644 --- a/src/wakatime.ts +++ b/src/wakatime.ts @@ -22,16 +22,6 @@ interface FileSelectionMap { } export class WakaTime { - private appNames = { - 'Arduino IDE': 'arduino', - 'Azure Data Studio': 'azdata', - Cursor: 'cursor', - Onivim: 'onivim', - 'Onivim 2': 'onivim', - 'SQL Operations Studio': 'sqlops', - 'Visual Studio Code': 'vscode', - Windsurf: 'windsurf', - }; private agentName: string; private extension: any; private statusBar?: vscode.StatusBarItem = undefined; @@ -85,14 +75,7 @@ export class WakaTime { let extension = vscode.extensions.getExtension('WakaTime.vscode-wakatime'); this.extension = (extension != undefined && extension.packageJSON) || { version: '0.0.0' }; - - if (this.appNames[vscode.env.appName]) { - this.agentName = this.appNames[vscode.env.appName]; - } else if (vscode.env.appName.toLowerCase().includes('visual')) { - this.agentName = 'vscode'; - } else { - this.agentName = vscode.env.appName.replace(/\s/g, '').toLowerCase(); - } + this.agentName = Utils.getEditorName(); this.options.getSetting('settings', 'disabled', false, (disabled: Setting) => { this.disabled = disabled.value === 'true'; diff --git a/src/web/wakatime.ts b/src/web/wakatime.ts index 9b26677..9c9ab5a 100644 --- a/src/web/wakatime.ts +++ b/src/web/wakatime.ts @@ -56,7 +56,7 @@ export class WakaTime { let extension = vscode.extensions.getExtension('WakaTime.vscode-wakatime'); this.extension = (extension != undefined && extension.packageJSON) || { version: '0.0.0' }; - this.agentName = 'vscode'; + this.agentName = Utils.getEditorName(); this.disabled = this.config.get('wakatime.disabled') === 'true'; if (this.disabled) {