diff --git a/package.json b/package.json index 88a6bf2..285acb3 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/config.ts b/src/config.ts index 884e3c9..de6e6cf 100644 --- a/src/config.ts +++ b/src/config.ts @@ -109,6 +109,7 @@ export interface ExtensionConfigurationType { "file.size.spacer": string; "behaviour.additionalFileMapping": Record; "behaviour.suppressNotifications": boolean; + "behaviour.supressRpcCouldNotConnect": boolean; "behaviour.prioritizeLanguagesOverExtensions": boolean; "behaviour.statusBarAlignment": "Left" | "Right"; "behaviour.debug": boolean; diff --git a/src/constants.ts b/src/constants.ts index d04efc1..2cb2bce 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 diff --git a/src/controller.ts b/src/controller.ts index 8d67d2f..80c03bc 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -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; + + 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"); } }