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