diff --git a/esbuild.js b/esbuild.js index 36a12597..c650c6c9 100644 --- a/esbuild.js +++ b/esbuild.js @@ -1,4 +1,4 @@ -const esbuild = require("esbuild"); +import esbuild from "esbuild"; const production = process.argv.includes("--production"); const watch = process.argv.includes("--watch"); @@ -32,7 +32,7 @@ async function main() { sourcemap: !production, sourcesContent: false, platform: "node", - outfile: "dist/extension.js", + outfile: "dist/extension.cjs", external: ["vscode"], logLevel: "silent", plugins: [ diff --git a/package.json b/package.json index d0f5d07c..d450c6af 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "activationEvents": [ "onStartupFinished" ], - "main": "dist/extension.js", + "main": "dist/extension.cjs", + "type": "module", "private": true, "icon": "assets/icon.png", "scripts": { diff --git a/src/controller.ts b/src/controller.ts index ef1d2e6f..475b1152 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -72,33 +72,38 @@ export class RPCController { private listen() { const config = getConfig(); - const sendActivity = (isViewing = false, isIdling = false) => { - this.activityThrottle.reset(); - void this.sendActivity(isViewing, isIdling); - }; - - const fileSwitch = window.onDidChangeActiveTextEditor(() => { + const fileSwitch = window.onDidChangeActiveTextEditor((e) => { logInfo("onDidChangeActiveTextEditor()"); - sendActivity(true); + if (e) { + this.activityThrottle.reset(); + void this.activityThrottle.callable(); + return; + } + setTimeout(() => { + this.checkIdle(window.state); + }, 500); }); const fileEdit = workspace.onDidChangeTextDocument((e) => { if (e.document !== dataClass.editor?.document) return; logInfo("onDidChangeTextDocument()"); - dataClass.updateGitInfo(); + this.activityThrottle.reset(); void this.activityThrottle.callable(); }); const fileSelectionChanged = window.onDidChangeTextEditorSelection((e) => { if (e.textEditor !== dataClass.editor) return; logInfo("onDidChangeTextEditorSelection()"); - dataClass.updateGitInfo(); + this.activityThrottle.reset(); + void this.activityThrottle.callable(); + }); + const debugStart = debug.onDidStartDebugSession(() => { + void this.activityThrottle.callable(); + }); + const debugEnd = debug.onDidTerminateDebugSession(() => { void this.activityThrottle.callable(); }); - const debugStart = debug.onDidStartDebugSession(() => sendActivity()); - const debugEnd = debug.onDidTerminateDebugSession(() => sendActivity()); const diagnosticsChange = languages.onDidChangeDiagnostics(() => onDiagnosticsChange()); const changeWindowState = window.onDidChangeWindowState((e: WindowState) => { logInfo("onDidChangeWindowState()"); - dataClass.updateGitInfo(); this.checkIdle(e); }); @@ -127,7 +132,7 @@ export class RPCController { return (this.canSendActivity = true); } - private async checkIdle(windowState: WindowState) { + private checkIdle(windowState: WindowState) { if (!this.enabled) return; const config = getConfig(); @@ -135,7 +140,7 @@ export class RPCController { if (config.get(CONFIG_KEYS.Status.Idle.Timeout) !== 0) { if (windowState.focused && this.idleTimeout) { clearTimeout(this.idleTimeout); - await this.sendActivity(); + void this.activityThrottle.callable(); } else if (config.get(CONFIG_KEYS.Status.Idle.Check)) { this.idleTimeout = setTimeout( async () => { @@ -150,8 +155,7 @@ export class RPCController { if (!this.enabled) return; - this.activityThrottle.reset(); - await this.sendActivity(false, true); + void this.activityThrottle.callable(false, true); }, config.get(CONFIG_KEYS.Status.Idle.Timeout)! * 1000 ); @@ -220,7 +224,7 @@ export class RPCController { editor.setStatusBarItem(StatusBarMode.Succeeded); logInfo("[004] Debug:", "Enabled - isConnected", this.client.isConnected, "isReady", this.client.clientId); - await this.sendActivity(); + await this.activityThrottle.callable(); this.cleanUp(); this.listen(); diff --git a/src/data.ts b/src/data.ts index 10ac0f88..10952ee2 100644 --- a/src/data.ts +++ b/src/data.ts @@ -159,15 +159,22 @@ export class Data implements Disposable { return v; } + #lastValidGitRemoteUrl = ""; + public get gitRemoteUrl(): gitUrlParse.GitUrl | undefined { - this.debug(`gitRemoteUrl(): Remote: ${this._remote}`); const v = stripCredential(this._remote?.fetchUrl ?? this._remote?.pushUrl ?? ""); - this.debug(`gitRemoteUrl(): Url: ${v ?? ""}`); if (!v) return; - logInfo(`gitRemoteUrl(): Parsed: ${JSON.stringify(gitUrlParse(v), null, 2)}`); + const parsed = gitUrlParse(v); + + if (this.#lastValidGitRemoteUrl !== v) { + this.#lastValidGitRemoteUrl = v; + this.debug(`gitRemoteUrl(): Remote: ${this._remote}`); + this.debug(`gitRemoteUrl(): Url: ${v ?? ""}`); + logInfo(`gitRemoteUrl(): Parsed: ${JSON.stringify(parsed, null, 2)}`); + } - return gitUrlParse(v); + return parsed; } public get gitBranchName(): string | undefined {