refactor: commands merged into a single toggle
This commit is contained in:
parent
78172bf133
commit
510a4ab32c
2 changed files with 16 additions and 21 deletions
|
@ -23,13 +23,8 @@
|
|||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "discord.enable",
|
||||
"title": "Enable Visual Studio Code Discord in the current workspace",
|
||||
"category": "VS-Discord"
|
||||
},
|
||||
{
|
||||
"command": "discord.disable",
|
||||
"title": "Disable Visual Studio Code Discord in the current workspace",
|
||||
"command": "discord.toggle",
|
||||
"title": "Wether Visual Studio Code Discord in the current workspace is enabled or not",
|
||||
"category": "VS-Discord"
|
||||
}
|
||||
],
|
||||
|
|
|
@ -32,23 +32,22 @@ export function activate(context: ExtensionContext) {
|
|||
initRPC(config.get('clientID'));
|
||||
}
|
||||
|
||||
// Register the `discord.enable` command, and set the `enabled` config option to true.
|
||||
const enabler = commands.registerCommand('discord.enable', () => {
|
||||
if (rpc) return;
|
||||
config.update('enabled', true);
|
||||
initRPC(config.get('clientID'));
|
||||
});
|
||||
|
||||
// Register the `discord.disable` command, and set the `enabled` config option to false.
|
||||
const disabler = commands.registerCommand('discord.disable', () => {
|
||||
if (!rpc) return;
|
||||
config.update('enabled', false);
|
||||
rpc.setActivity({});
|
||||
destroyRPC();
|
||||
// Register the `discord.toggle` command.
|
||||
const toggler = commands.registerCommand('discord.toggle', () => {
|
||||
if (rpc) {
|
||||
config.update('enabled', false);
|
||||
rpc.setActivity({});
|
||||
destroyRPC();
|
||||
window.showInformationMessage('Disabled Rich Presence for Discord.');
|
||||
} else {
|
||||
config.update('enabled', true);
|
||||
initRPC(config.get('clientID'));
|
||||
window.showInformationMessage('Enabled Rich Presence for Discord.');
|
||||
}
|
||||
});
|
||||
|
||||
// Push the new commands into the subscriptions.
|
||||
context.subscriptions.push(enabler, disabler);
|
||||
context.subscriptions.push(toggler);
|
||||
}
|
||||
|
||||
// `Deactivate` is fired whenever the extension is deactivated.
|
||||
|
@ -75,6 +74,7 @@ function initRPC(clientID: string): void {
|
|||
eventHandler = workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity());
|
||||
// Make sure to listen to the close event and dispose and destroy everything accordingly.
|
||||
rpc.transport.once('close', () => {
|
||||
if (!config.get('enabled')) return;
|
||||
destroyRPC();
|
||||
// Set an interval for reconnecting.
|
||||
reconnect = setInterval(() => {
|
||||
|
|
Loading…
Reference in a new issue