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 configuration option to suppress RPC connection error notifications #357

Open
wants to merge 1 commit 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
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