From 82e444e19635a72d2e1c4d043840bdfd358fa120 Mon Sep 17 00:00:00 2001 From: Ven Date: Mon, 14 Nov 2022 18:05:41 +0100 Subject: Less confusing plugin names (bulk plugin rename) (#214) Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> --- src/api/settings.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/api/settings.ts') diff --git a/src/api/settings.ts b/src/api/settings.ts index 9e518c6..dd8692a 100644 --- a/src/api/settings.ts +++ b/src/api/settings.ts @@ -19,10 +19,12 @@ import plugins from "~plugins"; import IpcEvents from "../utils/IpcEvents"; +import Logger from "../utils/Logger"; import { mergeDefaults } from "../utils/misc"; import { OptionType } from "../utils/types"; import { React } from "../webpack/common"; +const logger = new Logger("Settings"); export interface Settings { notifyAboutUpdates: boolean; useQuickCss: boolean; @@ -169,3 +171,21 @@ export function addSettingsListener(path: string, onUpdate: (newValue: any, path (onUpdate as SubscriptionCallback)._path = path; subscriptions.add(onUpdate); } + +export function migratePluginSettings(name: string, ...oldNames: string[]) { + const { plugins } = settings; + if (name in plugins) return; + + for (const oldName of oldNames) { + if (oldName in plugins) { + logger.info(`Migrating settings from old name ${oldName} to ${name}`); + plugins[name] = plugins[oldName]; + delete plugins[oldName]; + VencordNative.ipc.invoke( + IpcEvents.SET_SETTINGS, + JSON.stringify(settings, null, 4) + ); + break; + } + } +} -- cgit