Skip to content

Commit

Permalink
Add configuration option to suppress RPC connection error notifications
Browse files Browse the repository at this point in the history
Useful if Discord is not permanently running (e.g. no auto start-up)
  • Loading branch information
MrMinemeet committed Feb 2, 2025
1 parent 47e17e1 commit 69bf380
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@
"default": false,
"description": "Suppresses all notifications from the extension."
},
"vscord.behaviour.supressRpcCouldNotConnect": {
"type": "boolean",
"default": false,
"description": "Suppresses \"RPC_COULD_NOT_CONNECT\" notification."
},
"vscord.behaviour.prioritizeLanguagesOverExtensions": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface ExtensionConfigurationType {
"file.size.spacer": string;
"behaviour.additionalFileMapping": Record<string, string>;
"behaviour.suppressNotifications": boolean;
"behaviour.supressRpcCouldNotConnect": boolean;
"behaviour.prioritizeLanguagesOverExtensions": boolean;
"behaviour.statusBarAlignment": "Left" | "Right";
"behaviour.debug": boolean;
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const CONFIG_KEYS = {
Behaviour: {
AdditionalFileMapping: "behaviour.additionalFileMapping" as const,
SuppressNotifications: "behaviour.suppressNotifications" as const,
SuppressRpcCouldNotConnect: "behaviour.supressRpcCouldNotConnect" as const,
PrioritizeLanguagesOverExtensions: "behaviour.prioritizeLanguagesOverExtensions" as const,
StatusBarAlignment: "behaviour.statusBarAlignment" as const,
Debug: "behaviour.debug" as const
Expand Down
20 changes: 15 additions & 5 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ export class RPCController {
editor.statusBarItem.tooltip = "Reconnect to Discord Gateway";

if (!config.get(CONFIG_KEYS.Behaviour.SuppressNotifications)) {
const result = await (error?.message?.includes("ENOENT")
? window.showErrorMessage("No Discord client detected")
: window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.name}`, "Reconnect"));
editor.statusBarItem.text = "$(search-refresh) Reconnect to Discord Gateway";
let result: Thenable<string | undefined>;

if (error?.message?.includes("ENOENT")) {
result = window.showErrorMessage("No Discord client detected");
} else if ( error.name !== "RPC_COULD_NOT_CONNECT" ||
(error?.name === "RPC_COULD_NOT_CONNECT" && !config.get(CONFIG_KEYS.Behaviour.SuppressRpcCouldNotConnect))) {

result = window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.name}`, "Reconnect");
} else {
logInfo(`[002] Debug: Suppressed error notification: ${error.name}`);
return;
}

editor.statusBarItem.text = "$(search-refresh) Reconnect to Discord Gateway";4
editor.statusBarItem.command = "vscord.reconnect";
editor.statusBarItem.tooltip = "Reconnect to Discord Gateway";

if (result === "Reconnect") {
if (await result === "Reconnect") {
commands.executeCommand("vscord.reconnect");
}
}
Expand Down

0 comments on commit 69bf380

Please sign in to comment.