mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 14:43:03 -04:00
feat(settings): disable warning forever (#58)
* add disable warning forever for thororen * Update PluginModal.tsx * Update index.tsx
This commit is contained in:
parent
5e39370fac
commit
b6a0659965
3 changed files with 82 additions and 41 deletions
|
@ -76,6 +76,8 @@ export interface Settings {
|
||||||
settingsSyncVersion: number;
|
settingsSyncVersion: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ignoreResetWarning: boolean;
|
||||||
|
|
||||||
userCssVars: {
|
userCssVars: {
|
||||||
[themeId: string]: {
|
[themeId: string]: {
|
||||||
[varName: string]: string;
|
[varName: string]: string;
|
||||||
|
@ -113,6 +115,8 @@ const DefaultSettings: Settings = {
|
||||||
settingsSyncVersion: 0
|
settingsSyncVersion: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ignoreResetWarning: false,
|
||||||
|
|
||||||
userCssVars: {}
|
userCssVars: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
import "./PluginModal.css";
|
import "./PluginModal.css";
|
||||||
|
|
||||||
import { generateId } from "@api/Commands";
|
import { generateId } from "@api/Commands";
|
||||||
import { useSettings } from "@api/Settings";
|
import { Settings, useSettings } from "@api/Settings";
|
||||||
import { classNameFactory } from "@api/Styles";
|
import { classNameFactory } from "@api/Styles";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Flex } from "@components/Flex";
|
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) {
|
export function openWarningModal(plugin: Plugin, pluginModalProps: ModalProps, onRestartNeeded?: (pluginName: string) => void) {
|
||||||
|
if (Settings.ignoreResetWarning) return resetSettings(plugin, pluginModalProps, pluginModalProps, onRestartNeeded);
|
||||||
|
|
||||||
openModal(warningModalProps => (
|
openModal(warningModalProps => (
|
||||||
<ModalRoot
|
<ModalRoot
|
||||||
{...warningModalProps}
|
{...warningModalProps}
|
||||||
|
@ -425,6 +427,21 @@ export function openWarningModal(plugin: Plugin, pluginModalProps: ModalProps, o
|
||||||
<Text style={{ fontSize: "1.2rem", color: "var(--text-normal)", marginBottom: "10px" }}>
|
<Text style={{ fontSize: "1.2rem", color: "var(--text-normal)", marginBottom: "10px" }}>
|
||||||
If you are certain you want to proceed, click <strong>Confirm Reset</strong>. Otherwise, click <strong>Cancel</strong>.
|
If you are certain you want to proceed, click <strong>Confirm Reset</strong>. Otherwise, click <strong>Cancel</strong>.
|
||||||
</Text>
|
</Text>
|
||||||
|
{!Settings.ignoreResetWarning && (
|
||||||
|
<Button style={{
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
color: "red",
|
||||||
|
cursor: "pointer",
|
||||||
|
margin: "0 auto",
|
||||||
|
width: "fit-content",
|
||||||
|
textDecoration: "underline"
|
||||||
|
}} onClick={() => {
|
||||||
|
Settings.ignoreResetWarning = true;
|
||||||
|
}}>
|
||||||
|
Disable this warning forever
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Forms.FormSection>
|
</Forms.FormSection>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
|
@ -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: (
|
||||||
|
<>
|
||||||
|
<p style={{ textAlign: "center" }}>Some plugins require a restart to fully disable.</p>
|
||||||
|
<p style={{ textAlign: "center" }}>Would you like to restart now?</p>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
confirmText: "Restart Now",
|
||||||
|
cancelText: "Later",
|
||||||
|
onConfirm: () => location.reload()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Code directly taken from supportHelper.tsx
|
// Code directly taken from supportHelper.tsx
|
||||||
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || Plugins[plugin].required;
|
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || Plugins[plugin].required;
|
||||||
|
|
||||||
|
@ -391,10 +431,12 @@ export default function PluginSettings() {
|
||||||
size={Button.Sizes.SMALL}
|
size={Button.Sizes.SMALL}
|
||||||
style={{ backgroundColor: "var(--button-danger-background)", margin: "20px 0" }}
|
style={{ backgroundColor: "var(--button-danger-background)", margin: "20px 0" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (Settings.ignoreResetWarning) return resetCheckAndDo();
|
||||||
|
|
||||||
return Alerts.show({
|
return Alerts.show({
|
||||||
title: "Disable All Plugins",
|
title: "Disable All Plugins",
|
||||||
body: (
|
body: (
|
||||||
<>
|
<div style={{ textAlign: "center" }}>
|
||||||
<img
|
<img
|
||||||
src="https://media.tenor.com/Y6DXKZiBCs8AAAAi/stavario-josefbenes.gif"
|
src="https://media.tenor.com/Y6DXKZiBCs8AAAAi/stavario-josefbenes.gif"
|
||||||
alt="Warning"
|
alt="Warning"
|
||||||
|
@ -406,48 +448,27 @@ export default function PluginSettings() {
|
||||||
<p style={{ fontSize: "1rem" }}>
|
<p style={{ fontSize: "1rem" }}>
|
||||||
Are you absolutely sure you want to proceed? You can always enable them back later.
|
Are you absolutely sure you want to proceed? You can always enable them back later.
|
||||||
</p>
|
</p>
|
||||||
</>
|
{!Settings.ignoreResetWarning && (
|
||||||
|
<Button style={{
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
color: "red",
|
||||||
|
cursor: "pointer",
|
||||||
|
margin: "0 auto",
|
||||||
|
width: "fit-content",
|
||||||
|
textDecoration: "underline"
|
||||||
|
}} onClick={() => {
|
||||||
|
Settings.ignoreResetWarning = true;
|
||||||
|
}}>
|
||||||
|
Disable this warning forever
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
),
|
),
|
||||||
confirmText: "Disable All",
|
confirmText: "Disable All",
|
||||||
cancelText: "Cancel",
|
cancelText: "Cancel",
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
let restartNeeded = false;
|
resetCheckAndDo();
|
||||||
|
|
||||||
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: (
|
|
||||||
<>
|
|
||||||
<p>Some plugins require a restart to fully disable.</p>
|
|
||||||
<p>Would you like to restart now?</p>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
confirmText: "Restart Now",
|
|
||||||
cancelText: "Later",
|
|
||||||
onConfirm: () => location.reload()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -456,7 +477,6 @@ export default function PluginSettings() {
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{plugins.length || requiredPlugins.length
|
{plugins.length || requiredPlugins.length
|
||||||
? (
|
? (
|
||||||
<div className={cl("grid")}>
|
<div className={cl("grid")}>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue