diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 2ebe5ba7..403d44d4 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -76,6 +76,8 @@ export interface Settings { settingsSyncVersion: number; }; + ignoreResetWarning: boolean; + userCssVars: { [themeId: string]: { [varName: string]: string; @@ -113,6 +115,8 @@ const DefaultSettings: Settings = { settingsSyncVersion: 0 }, + ignoreResetWarning: false, + userCssVars: {} }; diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index b96a5ea9..dce89df6 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -19,7 +19,7 @@ import "./PluginModal.css"; import { generateId } from "@api/Commands"; -import { useSettings } from "@api/Settings"; +import { Settings, useSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; @@ -397,6 +397,8 @@ function resetSettings(plugin: Plugin, warningModalProps?: ModalProps, pluginMod } export function openWarningModal(plugin: Plugin, pluginModalProps: ModalProps, onRestartNeeded?: (pluginName: string) => void) { + if (Settings.ignoreResetWarning) return resetSettings(plugin, pluginModalProps, pluginModalProps, onRestartNeeded); + openModal(warningModalProps => ( If you are certain you want to proceed, click Confirm Reset. Otherwise, click Cancel. + {!Settings.ignoreResetWarning && ( + + )} diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index 4114e42b..2405875b 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -328,6 +328,46 @@ export default function PluginSettings() { } } + function resetCheckAndDo() { + let restartNeeded = false; + + for (const plugin of enabledPlugins) { + const pluginSettings = settings.plugins[plugin]; + + if (Plugins[plugin].patches?.length) { + pluginSettings.enabled = false; + changes.handleChange(plugin); + restartNeeded = true; + continue; + } + + const result = stopPlugin(Plugins[plugin]); + + if (!result) { + logger.error(`Error while stopping plugin ${plugin}`); + showErrorToast(`Error while stopping plugin ${plugin}`); + continue; + } + + pluginSettings.enabled = false; + } + + if (restartNeeded) { + Alerts.show({ + title: "Restart Required", + body: ( + <> +

Some plugins require a restart to fully disable.

+

Would you like to restart now?

+ + ), + confirmText: "Restart Now", + cancelText: "Later", + onConfirm: () => location.reload() + }); + } + } + // Code directly taken from supportHelper.tsx const isApiPlugin = (plugin: string) => plugin.endsWith("API") || Plugins[plugin].required; @@ -391,10 +431,12 @@ export default function PluginSettings() { size={Button.Sizes.SMALL} style={{ backgroundColor: "var(--button-danger-background)", margin: "20px 0" }} onClick={() => { + if (Settings.ignoreResetWarning) return resetCheckAndDo(); + return Alerts.show({ title: "Disable All Plugins", body: ( - <> +
Warning Are you absolutely sure you want to proceed? You can always enable them back later.

- + {!Settings.ignoreResetWarning && ( + + )} +
), confirmText: "Disable All", cancelText: "Cancel", onConfirm: () => { - let restartNeeded = false; - - for (const plugin of enabledPlugins) { - const pluginSettings = settings.plugins[plugin]; - - if (Plugins[plugin].patches?.length) { - pluginSettings.enabled = false; - changes.handleChange(plugin); - restartNeeded = true; - continue; - } - - const result = stopPlugin(Plugins[plugin]); - - if (!result) { - logger.error(`Error while stopping plugin ${plugin}`); - showErrorToast(`Error while stopping plugin ${plugin}`); - continue; - } - - pluginSettings.enabled = false; - } - - if (restartNeeded) { - Alerts.show({ - title: "Restart Required", - body: ( - <> -

Some plugins require a restart to fully disable.

-

Would you like to restart now?

- - ), - confirmText: "Restart Now", - cancelText: "Later", - onConfirm: () => location.reload() - }); - } + resetCheckAndDo(); } }); }} @@ -456,7 +477,6 @@ export default function PluginSettings() { )} - {plugins.length || requiredPlugins.length ? (