From f9c58691e31983da48ac172b6c3e068708b8fe5f Mon Sep 17 00:00:00 2001 From: sorpdev Date: Sat, 7 Sep 2024 20:50:16 +0200 Subject: [PATCH 1/3] add start and stop idle command --- package.json | 10 ++++++++++ src/extension.ts | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 88a6bf25..06bffc66 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,16 @@ "command": "vscord.disablePrivacyMode", "title": "Disable Privacy Mode", "category": "VSCord" + }, + { + "command": "vscord.startIdling", + "title": "Start Idling", + "category": "VSCord" + }, + { + "command": "vscord.stopIdling", + "title": "Stop Idling", + "category": "VSCord" } ], "configuration": [ diff --git a/src/extension.ts b/src/extension.ts index 18b64198..067faec1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -152,6 +152,24 @@ export const registerCommands = (ctx: ExtensionContext) => { await window.showInformationMessage("Disabled Privacy Mode."); }); + const startIdlingCommand = commands.registerCommand("vscord.startIdling", async () => { + logInfo("Started Idling"); + + await controller.sendActivity(false, true); + + if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications)) + await window.showInformationMessage("Started Idling."); + }); + + const stopIdlingCommand = commands.registerCommand("vscord.stopIdling", async () => { + logInfo("Stopped Idling"); + + await controller.sendActivity(); + + if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications)) + await window.showInformationMessage("Stopped Idling."); + }); + ctx.subscriptions.push( enableCommand, disableCommand, @@ -160,7 +178,9 @@ export const registerCommands = (ctx: ExtensionContext) => { reconnectCommand, disconnectCommand, enablePrivacyModeCommand, - disablePrivacyModeCommand + disablePrivacyModeCommand, + startIdlingCommand, + stopIdlingCommand ); logInfo("Registered Discord Rich Presence commands"); From a4381909651c0854877423625fcea8b6d322c103 Mon Sep 17 00:00:00 2001 From: sorpdev Date: Sat, 7 Sep 2024 20:55:33 +0200 Subject: [PATCH 2/3] change idle commands to better name --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 06bffc66..60b51228 100644 --- a/package.json +++ b/package.json @@ -105,12 +105,12 @@ }, { "command": "vscord.startIdling", - "title": "Start Idling", + "title": "Start Idle", "category": "VSCord" }, { "command": "vscord.stopIdling", - "title": "Stop Idling", + "title": "Stop Idle", "category": "VSCord" } ], From 3d9b3862fc37a071fdb10a9a133bc884df085a8c Mon Sep 17 00:00:00 2001 From: sorpdev Date: Sat, 7 Sep 2024 22:27:21 +0200 Subject: [PATCH 3/3] add manualIdleMode and manualIdling to controller --- src/controller.ts | 5 +++++ src/extension.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/controller.ts b/src/controller.ts index 8d67d2f8..5743c5ef 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -21,6 +21,8 @@ export class RPCController { listeners: Disposable[] = []; enabled = true; canSendActivity = true; + manualIdleMode = false; + manualIdling = false; state: SetActivity = {}; debug = false; client: Client; @@ -34,8 +36,10 @@ export class RPCController { ); constructor(clientId: string, debug = false) { + const config = getConfig(); this.client = new Client({ clientId }); this.debug = debug; + this.manualIdleMode = config.get(CONFIG_KEYS.Status.Idle.Check) === false; editor.statusBarItem.text = "$(pulse) Connecting to Discord Gateway..."; editor.statusBarItem.command = undefined; @@ -194,6 +198,7 @@ export class RPCController { async sendActivity(isViewing = false, isIdling = false): Promise { if (!this.enabled) return; + if (this.manualIdleMode) isIdling = this.manualIdling; this.checkCanSend(isIdling); this.state = await activity(this.state, isViewing, isIdling); this.state.instance = true; diff --git a/src/extension.ts b/src/extension.ts index 067faec1..d22edb0c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -28,6 +28,8 @@ export const registerListeners = (ctx: ExtensionContext) => { await controller.login(); if (isEnabled) await controller.enable(); } + + controller.manualIdleMode = config.get(CONFIG_KEYS.Status.Idle.Check) === false; }); ctx.subscriptions.push(onConfigurationChanged); @@ -155,6 +157,7 @@ export const registerCommands = (ctx: ExtensionContext) => { const startIdlingCommand = commands.registerCommand("vscord.startIdling", async () => { logInfo("Started Idling"); + controller.manualIdling = true; await controller.sendActivity(false, true); if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications)) @@ -164,6 +167,7 @@ export const registerCommands = (ctx: ExtensionContext) => { const stopIdlingCommand = commands.registerCommand("vscord.stopIdling", async () => { logInfo("Stopped Idling"); + controller.manualIdling = false; await controller.sendActivity(); if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications))