diff --git a/README.md b/README.md index 37667c1..594a977 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Give me a little bit of time and this will be resolved! 😉 ## Features * Shows what you are editing in VSCode with no bullsh*t involved. +* Enable/Disable Rich Presence for individual workspaces (enabled by default). ## Contributing diff --git a/package.json b/package.json index 374497d..afb6a46 100644 --- a/package.json +++ b/package.json @@ -23,14 +23,19 @@ "contributes": { "commands": [ { - "command": "discord.toggle", - "title": "Wether Visual Studio Code Discord in the current workspace is enabled or not", + "command": "discord.enable", + "title": "Enable Discord Presence in the current workspace", + "category": "VS-Discord" + }, + { + "command": "discord.disable", + "title": "Disable Discord Presence in the current workspace", "category": "VS-Discord" } ], "configuration": [ { - "title": "Visual Studio Code Discord Configuration", + "title": "Discord Presence Configuration", "type": "object", "properties": { "discord.clientID": { @@ -41,7 +46,7 @@ "discord.enabled": { "type": "boolean", "default": true, - "description": "Controls if Visual Studio Code Discord is active" + "description": "Controls if Discord Presence is active" } } } diff --git a/src/extension.ts b/src/extension.ts index 735ebb0..6404f4f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,6 +21,7 @@ let config; let reconnect: NodeJS.Timer; // Define the reconnect counter and its type. let reconnectCounter = 0; +// Define the last known file name and its type. let lastKnownFileName: string; // `Activate` is fired when the extension is enabled. This SHOULD only fire once. @@ -33,22 +34,25 @@ export function activate(context: ExtensionContext) { initRPC(config.get('clientID')); } - // 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.'); - } + // Register the `discord.enable` command, and set the `enabled` config option to true. + const enabler = commands.registerCommand('discord.enable', () => { + if (rpc) destroyRPC(); + config.update('enabled', true); + initRPC(config.get('clientID')); + window.showInformationMessage('Enabled Discord Rich Presence for this workspace.'); + }); + + // 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(); + window.showInformationMessage('Disabled Discord Rich Presence for this workspace.'); }); // Push the new commands into the subscriptions. - context.subscriptions.push(toggler); + context.subscriptions.push(enabler, disabler); } // `Deactivate` is fired whenever the extension is deactivated. @@ -70,6 +74,7 @@ function initRPC(clientID: string): void { // Null reconnect variable. reconnect = null; } + // Reset the reconnect counter to 0 on a successful reconnect. reconnectCounter = 0; setActivity(); eventHandler = workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity()); @@ -145,5 +150,3 @@ function setActivity(): void { // Update the user's activity to the `activity` variable. rpc.setActivity(activity); } - -process.on('unhandledRejection', err => console.error(err));