fix: errors on boot (#121)
* fix: Reconnects not working if Discord wasn't open before VSCode * misc: Cleanup * fix: Hide and re-show the status bar item on enable/disable * nit: Crawls request * fix: Use if + .catch on the promise * nit: Crawl's request
This commit is contained in:
parent
328e4ffbe1
commit
7be2adf048
2 changed files with 18 additions and 13 deletions
|
@ -44,35 +44,37 @@ export default class RPCClient implements Disposable {
|
|||
this._rpc.once('ready', () => {
|
||||
Logger.log('Successfully connected to Discord.');
|
||||
this.statusBarIcon.text = '$(globe) Connected to Discord';
|
||||
this.statusBarIcon.tooltip = 'Connected to Discord';
|
||||
|
||||
setTimeout(() => this.statusBarIcon.text = '$(globe)', 5000);
|
||||
setTimeout(() => {
|
||||
this.statusBarIcon.text = '$(globe)';
|
||||
this.statusBarIcon.tooltip = 'Connected to Discord';
|
||||
}, 10000);
|
||||
|
||||
if (activityTimer) clearInterval(activityTimer);
|
||||
this.setActivity();
|
||||
|
||||
activityTimer = setInterval(() => {
|
||||
this.config = workspace.getConfiguration('discord');
|
||||
this.setActivity(this.config.get<boolean>('workspaceElapsedTime'));
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
this._rpc.transport.once('close', async () => {
|
||||
if (!this.config.get<boolean>('enabled')) return;
|
||||
await this.dispose();
|
||||
this.statusBarIcon.text = '$(plug) Reconnect to Discord';
|
||||
this.statusBarIcon.command = 'discord.reconnect';
|
||||
});
|
||||
|
||||
activityTimer = setInterval(() => {
|
||||
this.config = workspace.getConfiguration('discord');
|
||||
this.setActivity(this.config.get<boolean>('workspaceElapsedTime'));
|
||||
}, 10000);
|
||||
});
|
||||
await this._rpc.login({ clientId: this._clientId });
|
||||
}
|
||||
|
||||
public async dispose() {
|
||||
this._activity.dispose();
|
||||
if (this._rpc) {
|
||||
try {
|
||||
await this._rpc.destroy();
|
||||
} catch {}
|
||||
this._rpc = null;
|
||||
}
|
||||
|
||||
clearInterval(activityTimer);
|
||||
this.statusBarIcon.hide();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ export async function activate(context: ExtensionContext) {
|
|||
await rpc.login();
|
||||
} catch (error) {
|
||||
Logger.log(`Encountered following error after trying to login:\n${error}`);
|
||||
await rpc.dispose();
|
||||
if (!config.get('silent')) {
|
||||
if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!');
|
||||
else window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.toString()}`);
|
||||
|
@ -39,6 +40,7 @@ export async function activate(context: ExtensionContext) {
|
|||
config.update('enabled', true);
|
||||
rpc.config = workspace.getConfiguration('discord');
|
||||
rpc.statusBarIcon.text = '$(pulse) Connecting to Discord...';
|
||||
rpc.statusBarIcon.show();
|
||||
await rpc.login();
|
||||
window.showInformationMessage('Enabled Discord Rich Presence for this workspace.');
|
||||
});
|
||||
|
@ -47,6 +49,7 @@ export async function activate(context: ExtensionContext) {
|
|||
config.update('enabled', false);
|
||||
rpc.config = workspace.getConfiguration('discord');
|
||||
await rpc.dispose();
|
||||
rpc.statusBarIcon.hide();
|
||||
window.showInformationMessage('Disabled Discord Rich Presence for this workspace.');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue