From 1a185bf563499b26c0353d98612c627f50824b46 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Thu, 23 Nov 2017 22:14:16 +0100 Subject: [PATCH] fix: make sure to properly destroy the rpc client --- src/extension.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index baa3078..cf8d3f4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,22 +2,26 @@ import { Client } from 'discord-rpc'; import { basename, extname } from 'path'; import { ExtensionContext, commands, window, workspace, Uri, TextDocumentChangeEvent, TextDocument } from 'vscode'; +let rpc: Client; + export function activate(context: ExtensionContext) { - const rpc = new Client({ transport: 'ipc' }); + rpc = new Client({ transport: 'ipc' }); const config = workspace.getConfiguration('discord'); rpc.once('ready', () => { - setActivity(rpc); - workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity(rpc)); + setActivity(); + workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity()); }); rpc.login(config.get('clientID')).catch(error => window.showErrorMessage(`Could not connect to discord via rpc: ${error.message}`) ); } -export function deactivate(context: ExtensionContext) {} +export function deactivate(context: ExtensionContext) { + if (rpc) rpc.destroy(); +} -function setActivity(rpc: Client): void { +function setActivity(): void { if (!rpc) return; const activity = { details: window.activeTextEditor ? `Editing ${basename(window.activeTextEditor.document.fileName)}` : 'Idle.',