From ebfaf5426375fdab8e99f48278c1db673b30e21e Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Wed, 11 Sep 2024 02:55:53 -0400 Subject: [PATCH] Make aftersave void --- src/components/PluginSettings/PluginModal.tsx | 5 +++-- src/equicordplugins/customSounds/index.tsx | 15 ++++++++++++++- src/utils/types.ts | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/PluginSettings/PluginModal.tsx b/src/components/PluginSettings/PluginModal.tsx index 89c8f5fa..43558ef1 100644 --- a/src/components/PluginSettings/PluginModal.tsx +++ b/src/components/PluginSettings/PluginModal.tsx @@ -126,15 +126,16 @@ export default function PluginModal({ plugin, onRestartNeeded, onClose, transiti } let restartNeeded = false; - if (plugin.name === "CustomSounds") restartNeeded = true; for (const [key, value] of Object.entries(tempSettings)) { const option = plugin.options[key]; pluginSettings[key] = value; option?.onChange?.(value); if (option?.restartNeeded) restartNeeded = true; } + if (plugin.afterSave) { + plugin.afterSave(); + } if (restartNeeded) onRestartNeeded(); - plugin.afterSave = true; onClose(); } diff --git a/src/equicordplugins/customSounds/index.tsx b/src/equicordplugins/customSounds/index.tsx index 167d5eb4..816f078d 100644 --- a/src/equicordplugins/customSounds/index.tsx +++ b/src/equicordplugins/customSounds/index.tsx @@ -10,7 +10,7 @@ import { DataStore } from "@api/index"; import { definePluginSettings } from "@api/Settings"; import { Devs, EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { React } from "@webpack/common"; +import { Alerts, React } from "@webpack/common"; import { SoundOverrideComponent } from "./components/SoundOverrideComponent"; import { makeEmptyOverride, SoundOverride, soundTypes } from "./types"; @@ -81,6 +81,19 @@ export default definePlugin({ settings, findOverride, isOverriden, + afterSave() { + Alerts.show({ + title: "Restart required", + body: ( + <> +

CustomSounds requires a restart for settings to activate.

+ + ), + confirmText: "Restart now", + cancelText: "Later!", + onConfirm: () => location.reload() + }); + }, async start() { overrides = await DataStore.get(OVERRIDES_KEY) ?? {}; for (const type of soundTypes) diff --git a/src/utils/types.ts b/src/utils/types.ts index da9d3999..b8e3db93 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -121,7 +121,7 @@ export interface PluginDef { * Check that this returns true after allowing a save to complete. * 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 * plugin's settings page