From 7bb6b04e0dde31a4a4d694db521a645668f1b504 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Tue, 16 Feb 2021 21:49:53 +0100 Subject: [PATCH] fix: reconnect logic --- package-lock.json | 4 ++-- package.json | 2 +- src/extension.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ae49ce..fab0ab8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "discord-vscode", - "version": "5.2.1", + "version": "5.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "5.2.1", + "version": "5.2.2", "license": "MIT", "dependencies": { "bufferutil": "^4.0.3", diff --git a/package.json b/package.json index 41e9c5f..e1cd54b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "discord-vscode", "displayName": "Discord Presence", - "version": "5.2.1", + "version": "5.2.2", "description": "Update your discord status with a rich presence.", "private": true, "author": { diff --git a/src/extension.ts b/src/extension.ts index 0bcb180..b0d5804 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ import { getConfig } from './util'; const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left); statusBarIcon.text = '$(pulse) Connecting to Discord...'; -const rpc = new Client({ transport: 'ipc' }); +let rpc = new Client({ transport: 'ipc' }); const config = getConfig(); let state = {}; @@ -41,8 +41,11 @@ async function sendActivity() { } async function login() { + rpc = new Client({ transport: 'ipc' }); + rpc.once('ready', () => { log(LogLevel.Info, 'Successfully connected to Discord'); + cleanUp(); statusBarIcon.text = '$(globe) Connected to Discord'; statusBarIcon.tooltip = 'Connected to Discord'; @@ -57,6 +60,13 @@ async function login() { listeners.push(onChangeActiveTextEditor, onChangeTextDocument, onStartDebugSession, onTerminateDebugSession); }); + rpc.once('disconnected', async () => { + cleanUp(); + await rpc.destroy(); + statusBarIcon.text = '$(pulse) Reconnect to Discord'; + statusBarIcon.command = 'discord.reconnect'; + }); + try { await rpc.login({ clientId: CLIENT_ID }); } catch (error) { @@ -91,7 +101,6 @@ export async function activate(context: ExtensionContext) { void config.update('enabled', true); } cleanUp(); - await rpc.destroy(); statusBarIcon.text = '$(pulse) Connecting to Discord...'; statusBarIcon.show(); await login();