revert: use 2 commands for enabling and disabling
This commit is contained in:
parent
0ca42d0288
commit
9d47c438b4
3 changed files with 28 additions and 19 deletions
|
@ -13,6 +13,7 @@ Give me a little bit of time and this will be resolved! 😉
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* Shows what you are editing in VSCode with no bullsh*t involved.
|
* Shows what you are editing in VSCode with no bullsh*t involved.
|
||||||
|
* Enable/Disable Rich Presence for individual workspaces (enabled by default).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
13
package.json
13
package.json
|
@ -23,14 +23,19 @@
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "discord.toggle",
|
"command": "discord.enable",
|
||||||
"title": "Wether Visual Studio Code Discord in the current workspace is enabled or not",
|
"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"
|
"category": "VS-Discord"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"configuration": [
|
"configuration": [
|
||||||
{
|
{
|
||||||
"title": "Visual Studio Code Discord Configuration",
|
"title": "Discord Presence Configuration",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"discord.clientID": {
|
"discord.clientID": {
|
||||||
|
@ -41,7 +46,7 @@
|
||||||
"discord.enabled": {
|
"discord.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "Controls if Visual Studio Code Discord is active"
|
"description": "Controls if Discord Presence is active"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ let config;
|
||||||
let reconnect: NodeJS.Timer;
|
let reconnect: NodeJS.Timer;
|
||||||
// Define the reconnect counter and its type.
|
// Define the reconnect counter and its type.
|
||||||
let reconnectCounter = 0;
|
let reconnectCounter = 0;
|
||||||
|
// Define the last known file name and its type.
|
||||||
let lastKnownFileName: string;
|
let lastKnownFileName: string;
|
||||||
|
|
||||||
// `Activate` is fired when the extension is enabled. This SHOULD only fire once.
|
// `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'));
|
initRPC(config.get('clientID'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the `discord.toggle` command.
|
// Register the `discord.enable` command, and set the `enabled` config option to true.
|
||||||
const toggler = commands.registerCommand('discord.toggle', () => {
|
const enabler = commands.registerCommand('discord.enable', () => {
|
||||||
if (rpc) {
|
if (rpc) destroyRPC();
|
||||||
config.update('enabled', false);
|
config.update('enabled', true);
|
||||||
rpc.setActivity({});
|
initRPC(config.get('clientID'));
|
||||||
destroyRPC();
|
window.showInformationMessage('Enabled Discord Rich Presence for this workspace.');
|
||||||
window.showInformationMessage('Disabled Rich Presence for Discord.');
|
});
|
||||||
} else {
|
|
||||||
config.update('enabled', true);
|
// Register the `discord.disable` command, and set the `enabled` config option to false.
|
||||||
initRPC(config.get('clientID'));
|
const disabler = commands.registerCommand('discord.disable', () => {
|
||||||
window.showInformationMessage('Enabled Rich Presence for Discord.');
|
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.
|
// Push the new commands into the subscriptions.
|
||||||
context.subscriptions.push(toggler);
|
context.subscriptions.push(enabler, disabler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Deactivate` is fired whenever the extension is deactivated.
|
// `Deactivate` is fired whenever the extension is deactivated.
|
||||||
|
@ -70,6 +74,7 @@ function initRPC(clientID: string): void {
|
||||||
// Null reconnect variable.
|
// Null reconnect variable.
|
||||||
reconnect = null;
|
reconnect = null;
|
||||||
}
|
}
|
||||||
|
// Reset the reconnect counter to 0 on a successful reconnect.
|
||||||
reconnectCounter = 0;
|
reconnectCounter = 0;
|
||||||
setActivity();
|
setActivity();
|
||||||
eventHandler = workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity());
|
eventHandler = workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => setActivity());
|
||||||
|
@ -145,5 +150,3 @@ function setActivity(): void {
|
||||||
// Update the user's activity to the `activity` variable.
|
// Update the user's activity to the `activity` variable.
|
||||||
rpc.setActivity(activity);
|
rpc.setActivity(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('unhandledRejection', err => console.error(err));
|
|
||||||
|
|
Loading…
Reference in a new issue