fix: reconnect logic

This commit is contained in:
iCrawl 2021-02-16 21:49:53 +01:00
parent 6cca6b9aab
commit 7bb6b04e0d
No known key found for this signature in database
GPG key ID: 1AB888B16355FBB2
3 changed files with 14 additions and 5 deletions

4
package-lock.json generated
View file

@ -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",

View file

@ -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": {

View file

@ -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();