fix: reconnect logic
This commit is contained in:
parent
6cca6b9aab
commit
7bb6b04e0d
3 changed files with 14 additions and 5 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "discord-vscode",
|
"name": "discord-vscode",
|
||||||
"version": "5.2.1",
|
"version": "5.2.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bufferutil": "^4.0.3",
|
"bufferutil": "^4.0.3",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "discord-vscode",
|
"name": "discord-vscode",
|
||||||
"displayName": "Discord Presence",
|
"displayName": "Discord Presence",
|
||||||
"version": "5.2.1",
|
"version": "5.2.2",
|
||||||
"description": "Update your discord status with a rich presence.",
|
"description": "Update your discord status with a rich presence.",
|
||||||
"private": true,
|
"private": true,
|
||||||
"author": {
|
"author": {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { getConfig } from './util';
|
||||||
const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
|
const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
|
||||||
statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
||||||
|
|
||||||
const rpc = new Client({ transport: 'ipc' });
|
let rpc = new Client({ transport: 'ipc' });
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
|
|
||||||
let state = {};
|
let state = {};
|
||||||
|
@ -41,8 +41,11 @@ async function sendActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login() {
|
async function login() {
|
||||||
|
rpc = new Client({ transport: 'ipc' });
|
||||||
|
|
||||||
rpc.once('ready', () => {
|
rpc.once('ready', () => {
|
||||||
log(LogLevel.Info, 'Successfully connected to Discord');
|
log(LogLevel.Info, 'Successfully connected to Discord');
|
||||||
|
cleanUp();
|
||||||
|
|
||||||
statusBarIcon.text = '$(globe) Connected to Discord';
|
statusBarIcon.text = '$(globe) Connected to Discord';
|
||||||
statusBarIcon.tooltip = 'Connected to Discord';
|
statusBarIcon.tooltip = 'Connected to Discord';
|
||||||
|
@ -57,6 +60,13 @@ async function login() {
|
||||||
listeners.push(onChangeActiveTextEditor, onChangeTextDocument, onStartDebugSession, onTerminateDebugSession);
|
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 {
|
try {
|
||||||
await rpc.login({ clientId: CLIENT_ID });
|
await rpc.login({ clientId: CLIENT_ID });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -91,7 +101,6 @@ export async function activate(context: ExtensionContext) {
|
||||||
void config.update('enabled', true);
|
void config.update('enabled', true);
|
||||||
}
|
}
|
||||||
cleanUp();
|
cleanUp();
|
||||||
await rpc.destroy();
|
|
||||||
statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
||||||
statusBarIcon.show();
|
statusBarIcon.show();
|
||||||
await login();
|
await login();
|
||||||
|
|
Loading…
Reference in a new issue