fix: Disable command not working well (#37)
* Fix the disable command Due to update being a Thenable, and config not updating when changes happen, the code would never know that it has been disabled. Now it does! * Do Crawl's request
This commit is contained in:
parent
5685bfc522
commit
2d91d4f86e
1 changed files with 13 additions and 11 deletions
|
@ -49,15 +49,17 @@ export function activate(context: ExtensionContext) {
|
||||||
// Register the `discord.enable` command, and set the `enabled` config option to true.
|
// Register the `discord.enable` command, and set the `enabled` config option to true.
|
||||||
const enabler = commands.registerCommand('discord.enable', async () => {
|
const enabler = commands.registerCommand('discord.enable', async () => {
|
||||||
if (rpc) await destroyRPC();
|
if (rpc) await destroyRPC();
|
||||||
config.update('enabled', true);
|
await config.update('enabled', true);
|
||||||
|
config = workspace.getConfiguration('discord');
|
||||||
initRPC(config.get('clientID'));
|
initRPC(config.get('clientID'));
|
||||||
window.showInformationMessage('Enabled Discord Rich Presence for this workspace.');
|
window.showInformationMessage('Enabled Discord Rich Presence for this workspace.');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register the `discord.disable` command, and set the `enabled` config option to false.
|
// Register the `discord.disable` command, and set the `enabled` config option to false.
|
||||||
const disabler = commands.registerCommand('discord.disable', async () => {
|
const disabler = commands.registerCommand('discord.disable', async () => {
|
||||||
if (!rpc) return;
|
if (!rpc) return window.showWarningMessage('Discord Rich Presence is already disabled in this workspace.');
|
||||||
config.update('enabled', false);
|
await config.update('enabled', false);
|
||||||
|
config = workspace.getConfiguration('discord');
|
||||||
await destroyRPC();
|
await destroyRPC();
|
||||||
window.showInformationMessage('Disabled Discord Rich Presence for this workspace.');
|
window.showInformationMessage('Disabled Discord Rich Presence for this workspace.');
|
||||||
});
|
});
|
||||||
|
@ -121,7 +123,7 @@ function initRPC(clientID: string, loud?: boolean): void {
|
||||||
reconnecting = true;
|
reconnecting = true;
|
||||||
initRPC(config.get('clientID'));
|
initRPC(config.get('clientID'));
|
||||||
// Create reconnecting button
|
// Create reconnecting button
|
||||||
createButon(true);
|
createButton(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the user's activity to the `activity` variable.
|
// Update the user's activity to the `activity` variable.
|
||||||
|
@ -140,13 +142,13 @@ function initRPC(clientID: string, loud?: boolean): void {
|
||||||
// Destroy and dispose of everything after the set reconnect attempts
|
// Destroy and dispose of everything after the set reconnect attempts
|
||||||
if (reconnectCounter >= config.get('reconnectThreshold')) {
|
if (reconnectCounter >= config.get('reconnectThreshold')) {
|
||||||
// Create reconnect button
|
// Create reconnect button
|
||||||
createButon();
|
createButton();
|
||||||
await destroyRPC();
|
await destroyRPC();
|
||||||
} else {
|
} else {
|
||||||
// Increment the counter
|
// Increment the counter
|
||||||
reconnectCounter++;
|
reconnectCounter++;
|
||||||
// Create reconnecting button
|
// Create reconnecting button
|
||||||
createButon(true);
|
createButton(true);
|
||||||
// Retry connection
|
// Retry connection
|
||||||
initRPC(config.get('clientID'));
|
initRPC(config.get('clientID'));
|
||||||
return;
|
return;
|
||||||
|
@ -156,14 +158,14 @@ function initRPC(clientID: string, loud?: boolean): void {
|
||||||
if (!config.get('silent')) {
|
if (!config.get('silent')) {
|
||||||
if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!');
|
if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!');
|
||||||
else window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.message}`);
|
else window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.message}`);
|
||||||
createButon();
|
createButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create reconnect button
|
// Create reconnect button
|
||||||
function createButon(isReconnecting?: boolean): void {
|
function createButton(isReconnecting?: boolean): void {
|
||||||
// Check if the button already
|
// Check if the button exists already
|
||||||
if (!statusBarIcon) {
|
if (!statusBarIcon) {
|
||||||
// Create the icon
|
// Create the icon
|
||||||
statusBarIcon = window.createStatusBarItem(StatusBarAlignment.Left);
|
statusBarIcon = window.createStatusBarItem(StatusBarAlignment.Left);
|
||||||
|
@ -180,7 +182,7 @@ function createButon(isReconnecting?: boolean): void {
|
||||||
}
|
}
|
||||||
// Show the button
|
// Show the button
|
||||||
statusBarIcon.show();
|
statusBarIcon.show();
|
||||||
} else {
|
} else {
|
||||||
// Check if the client is reconnecting
|
// Check if the client is reconnecting
|
||||||
if (isReconnecting) {
|
if (isReconnecting) {
|
||||||
// Show attempts left
|
// Show attempts left
|
||||||
|
@ -195,7 +197,7 @@ function createButon(isReconnecting?: boolean): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanly destroy the RPC client (if it isn't already). && add icon to reconnect
|
// Cleanly destroy the RPC client (if it isn't already) && add icon to reconnect
|
||||||
async function destroyRPC(): Promise<void> {
|
async function destroyRPC(): Promise<void> {
|
||||||
// Do not continue if RPC isn't initalized.
|
// Do not continue if RPC isn't initalized.
|
||||||
if (!rpc) return;
|
if (!rpc) return;
|
||||||
|
|
Loading…
Reference in a new issue