Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add start and stop idle command #341

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
"command": "vscord.disablePrivacyMode",
"title": "Disable Privacy Mode",
"category": "VSCord"
},
{
"command": "vscord.startIdling",
"title": "Start Idle",
"category": "VSCord"
},
{
"command": "vscord.stopIdling",
"title": "Stop Idle",
"category": "VSCord"
}
],
"configuration": [
Expand Down
5 changes: 5 additions & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class RPCController {
listeners: Disposable[] = [];
enabled = true;
canSendActivity = true;
manualIdleMode = false;
manualIdling = false;
state: SetActivity = {};
debug = false;
client: Client;
Expand All @@ -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;
Expand Down Expand Up @@ -194,6 +198,7 @@ export class RPCController {

async sendActivity(isViewing = false, isIdling = false): Promise<SetActivityResponse | undefined> {
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;
Expand Down
26 changes: 25 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -152,6 +154,26 @@ export const registerCommands = (ctx: ExtensionContext) => {
await window.showInformationMessage("Disabled Privacy Mode.");
});

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))
await window.showInformationMessage("Started Idling.");
});

const stopIdlingCommand = commands.registerCommand("vscord.stopIdling", async () => {
logInfo("Stopped Idling");

controller.manualIdling = false;
await controller.sendActivity();

if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications))
await window.showInformationMessage("Stopped Idling.");
});

ctx.subscriptions.push(
enableCommand,
disableCommand,
Expand All @@ -160,7 +182,9 @@ export const registerCommands = (ctx: ExtensionContext) => {
reconnectCommand,
disconnectCommand,
enablePrivacyModeCommand,
disablePrivacyModeCommand
disablePrivacyModeCommand,
startIdlingCommand,
stopIdlingCommand
);

logInfo("Registered Discord Rich Presence commands");
Expand Down