Make aftersave void

This commit is contained in:
thororen1234 2024-09-11 02:55:53 -04:00
parent 7c95d3a729
commit ebfaf54263
3 changed files with 18 additions and 4 deletions

View file

@ -126,15 +126,16 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti
} }
let restartNeeded = false; let restartNeeded = false;
if (plugin.name === "CustomSounds") restartNeeded = true;
for (const [key, value] of Object.entries(tempSettings)) { for (const [key, value] of Object.entries(tempSettings)) {
const option = plugin.options[key]; const option = plugin.options[key];
pluginSettings[key] = value; pluginSettings[key] = value;
option?.onChange?.(value); option?.onChange?.(value);
if (option?.restartNeeded) restartNeeded = true; if (option?.restartNeeded) restartNeeded = true;
} }
if (plugin.afterSave) {
plugin.afterSave();
}
if (restartNeeded) onRestartNeeded(); if (restartNeeded) onRestartNeeded();
plugin.afterSave = true;
onClose(); onClose();
} }

View file

@ -10,7 +10,7 @@ import { DataStore } from "@api/index";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs, EquicordDevs } from "@utils/constants"; import { Devs, EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { React } from "@webpack/common"; import { Alerts, React } from "@webpack/common";
import { SoundOverrideComponent } from "./components/SoundOverrideComponent"; import { SoundOverrideComponent } from "./components/SoundOverrideComponent";
import { makeEmptyOverride, SoundOverride, soundTypes } from "./types"; import { makeEmptyOverride, SoundOverride, soundTypes } from "./types";
@ -81,6 +81,19 @@ export default definePlugin({
settings, settings,
findOverride, findOverride,
isOverriden, isOverriden,
afterSave() {
Alerts.show({
title: "Restart required",
body: (
<>
<p>CustomSounds requires a restart for settings to activate.</p>
</>
),
confirmText: "Restart now",
cancelText: "Later!",
onConfirm: () => location.reload()
});
},
async start() { async start() {
overrides = await DataStore.get(OVERRIDES_KEY) ?? {}; overrides = await DataStore.get(OVERRIDES_KEY) ?? {};
for (const type of soundTypes) for (const type of soundTypes)

View file

@ -121,7 +121,7 @@ export interface PluginDef {
* Check that this returns true after allowing a save to complete. * Check that this returns true after allowing a save to complete.
* If a string is returned, show the error to the user. * If a string is returned, show the error to the user.
*/ */
afterSave?: boolean; afterSave?(): void;
/** /**
* Allows you to specify a custom Component that will be rendered in your * Allows you to specify a custom Component that will be rendered in your
* plugin's settings page * plugin's settings page