From ddc39fe84d8b382bf2b5aa93b52c21fc4636330b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 25 Oct 2023 18:15:12 +0200 Subject: [PATCH] Fix SettingStores, GameActivityToggle --- src/api/SettingsStore.ts | 69 ------------------------ src/api/index.ts | 5 -- src/plugins/_api/settingsStore.ts | 38 ------------- src/plugins/gameActivityToggle/index.tsx | 10 ++-- src/plugins/gameActivityToggle/style.css | 2 +- src/plugins/ignoreActivities/index.tsx | 7 +-- src/webpack/common/settingsStores.ts | 1 + 7 files changed, 8 insertions(+), 124 deletions(-) delete mode 100644 src/api/SettingsStore.ts delete mode 100644 src/plugins/_api/settingsStore.ts diff --git a/src/api/SettingsStore.ts b/src/api/SettingsStore.ts deleted file mode 100644 index d9369a95..00000000 --- a/src/api/SettingsStore.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2023 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { proxyLazy } from "@utils/lazy"; -import { Logger } from "@utils/Logger"; -import { findModuleId, wreq } from "@webpack"; - -import { Settings } from "./Settings"; - -interface Setting { - /** - * Get the setting value - */ - getSetting(): T; - /** - * Update the setting value - * @param value The new value - */ - updateSetting(value: T | ((old: T) => T)): Promise; - /** - * React hook for automatically updating components when the setting is updated - */ - useSetting(): T; - settingsStoreApiGroup: string; - settingsStoreApiName: string; -} - -const SettingsStores: Array> | undefined = proxyLazy(() => { - const modId = findModuleId('"textAndImages","renderSpoilers"'); - if (modId == null) return new Logger("SettingsStoreAPI").error("Didn't find stores module."); - - const mod = wreq(modId); - if (mod == null) return; - - return Object.values(mod).filter((s: any) => s?.settingsStoreApiGroup) as any; -}); - -/** - * Get the store for a setting - * @param group The setting group - * @param name The name of the setting - */ -export function getSettingStore(group: string, name: string): Setting | undefined { - if (!Settings.plugins.SettingsStoreAPI.enabled) throw new Error("Cannot use SettingsStoreAPI without setting as dependency."); - - return SettingsStores?.find(s => s?.settingsStoreApiGroup === group && s?.settingsStoreApiName === name); -} - -/** - * getSettingStore but lazy - */ -export function getSettingStoreLazy(group: string, name: string) { - return proxyLazy(() => getSettingStore(group, name)); -} diff --git a/src/api/index.ts b/src/api/index.ts index f2c47e55..08f23810 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -29,7 +29,6 @@ import * as $Notices from "./Notices"; import * as $Notifications from "./Notifications"; import * as $ServerList from "./ServerList"; import * as $Settings from "./Settings"; -import * as $SettingsStore from "./SettingsStore"; import * as $Styles from "./Styles"; /** @@ -91,10 +90,6 @@ export const MemberListDecorators = $MemberListDecorators; * An API allowing you to persist data */ export const Settings = $Settings; -/** - * An API allowing you to read, manipulate and automatically update components based on Discord settings - */ -export const SettingsStore = $SettingsStore; /** * An API allowing you to dynamically load styles * a diff --git a/src/plugins/_api/settingsStore.ts b/src/plugins/_api/settingsStore.ts deleted file mode 100644 index ca1dc65b..00000000 --- a/src/plugins/_api/settingsStore.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; - -export default definePlugin({ - name: "SettingsStoreAPI", - description: "Patches Discord's SettingsStores to expose their group and name", - authors: [Devs.Nuckyz], - - patches: [ - { - find: '"textAndImages","renderSpoilers"', - replacement: [ - { - match: /(?<=INFREQUENT_USER_ACTION.{0,20}),useSetting:function/, - replace: ",settingsStoreApiGroup:arguments[0],settingsStoreApiName:arguments[1]$&" - } - ] - } - ] -}); diff --git a/src/plugins/gameActivityToggle/index.tsx b/src/plugins/gameActivityToggle/index.tsx index 40318c02..735f124c 100644 --- a/src/plugins/gameActivityToggle/index.tsx +++ b/src/plugins/gameActivityToggle/index.tsx @@ -16,16 +16,15 @@ * along with this program. If not, see . */ -import { getSettingStoreLazy } from "@api/SettingsStore"; import { disableStyle, enableStyle } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; import { findByCodeLazy } from "@webpack"; +import { StatusSettingsStores } from "@webpack/common"; import style from "./style.css?managed"; -const ShowCurrentGame = getSettingStoreLazy("status", "showCurrentGame"); const Button = findByCodeLazy("Button.Sizes.NONE,disabled:"); function makeIcon(showCurrentGame?: boolean) { @@ -40,7 +39,7 @@ function makeIcon(showCurrentGame?: boolean) { {!showCurrentGame && <> - + } @@ -50,7 +49,7 @@ function makeIcon(showCurrentGame?: boolean) { } function GameActivityToggleButton() { - const showCurrentGame = ShowCurrentGame?.useSetting(); + const showCurrentGame = StatusSettingsStores.ShowCurrentGame.useSetting(); return (