Add Don't show this again checkbox, Fix dismiss button, detect registered settings instead of saved settings

This commit is contained in:
Sqaaakoi 2024-10-12 07:14:49 +13:00
parent 1820dc001a
commit 9a02e43cfb
No known key found for this signature in database
3 changed files with 30 additions and 13 deletions

View file

@ -9,3 +9,7 @@
.vc-newPluginsManager-restart-list li { .vc-newPluginsManager-restart-list li {
list-style: disc; list-style: disc;
} }
.vc-newPluginsManager-close > div {
display: flex;
}

View file

@ -4,12 +4,16 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { useSettings } from "@api/Settings"; import "./NewPluginsModal.css";
import { Settings, useSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { PluginCard } from "@components/PluginSettings"; import { PluginCard } from "@components/PluginSettings";
import { ChangeList } from "@utils/ChangeList"; import { ChangeList } from "@utils/ChangeList";
import { classes, Margins } from "@utils/index";
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { useForceUpdater } from "@utils/react"; import { useForceUpdater } from "@utils/react";
import { findByPropsLazy } from "@webpack";
import { Button, Flex, Forms, React, Text, Tooltip, useMemo } from "@webpack/common"; import { Button, Flex, Forms, React, Text, Tooltip, useMemo } from "@webpack/common";
import { JSX } from "react"; import { JSX } from "react";
@ -19,9 +23,7 @@ import { getNewPlugins, getNewSettings, KnownPluginSettingsMap, writeKnownSettin
const cl = classNameFactory("vc-plugins-"); const cl = classNameFactory("vc-plugins-");
import "./NewPluginsModal.css"; const { Checkbox } = findByPropsLazy("FormItem", "Button");
import { Margins } from "@utils/index";
let hasSeen = false; let hasSeen = false;
@ -105,14 +107,15 @@ export function NewPluginsModal({ modalProps, newPlugins, newSettings }: { modal
return <ModalRoot {...modalProps} size={ModalSize.MEDIUM} > return <ModalRoot {...modalProps} size={ModalSize.MEDIUM} >
<ModalHeader> <ModalHeader>
<Text variant="heading-lg/semibold">New Plugins and Settings ({[...plugins, ...requiredPlugins].length})</Text> <Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>New Plugins and Settings ({[...plugins, ...requiredPlugins].length})</Text>
<Tooltip text="Dismiss for this session"> <Tooltip text="Dismiss for this session">
{tooltipProps => {tooltipProps =>
<ModalCloseButton <div {...tooltipProps}>
{...tooltipProps} <ModalCloseButton
onClick={modalProps.onClose} onClick={modalProps.onClose}
className={cl("close")} className={classes(cl("close"), "vc-newPluginsManager-close")}
/> />
</div>
} }
</Tooltip> </Tooltip>
</ModalHeader> </ModalHeader>
@ -129,6 +132,17 @@ export function NewPluginsModal({ modalProps, newPlugins, newSettings }: { modal
callback={(v: () => void) => updateContinueButton = v} callback={(v: () => void) => updateContinueButton = v}
/> />
</Flex> </Flex>
<Flex direction={Flex.Direction.HORIZONTAL}>
<Checkbox
type={Checkbox.Types.INVERTED}
value={!settings?.plugins?.NewPluginsManager?.enabled}
onChange={() => {
Settings.plugins.NewPluginsManager.enabled = !settings?.plugins?.NewPluginsManager?.enabled;
}}
>
<Text>Don't show this again</Text>
</Checkbox>
</Flex>
</ModalFooter> </ModalFooter>
</ModalRoot>; </ModalRoot>;
} }

View file

@ -5,7 +5,6 @@
*/ */
import { DataStore } from "@api/index"; import { DataStore } from "@api/index";
import { Settings } from "@api/Settings";
import plugins from "~plugins"; import plugins from "~plugins";
@ -15,7 +14,7 @@ export const KNOWN_PLUGINS_LEGACY_DATA_KEY = "NewPluginsManager_KnownPlugins";
export const KNOWN_SETTINGS_DATA_KEY = "NewPluginsManager_KnownSettings"; export const KNOWN_SETTINGS_DATA_KEY = "NewPluginsManager_KnownSettings";
function getSettingsSetForPlugin(plugin: string): Set<string> { function getSettingsSetForPlugin(plugin: string): Set<string> {
const settings = Settings.plugins[plugin] || {}; const settings = plugins[plugin]?.settings?.def || {};
return new Set(Object.keys(settings).filter(setting => setting !== "enabled")); return new Set(Object.keys(settings).filter(setting => setting !== "enabled"));
} }
@ -84,7 +83,7 @@ export async function debugWipeSomeData() {
await DataStore.set(KNOWN_SETTINGS_DATA_KEY, settings); await DataStore.set(KNOWN_SETTINGS_DATA_KEY, settings);
} }
export async function editRawData(patcher: (data: KnownPluginSettingsMap) => (Promise<KnownPluginSettingsMap> | KnownPluginSettingsMap)) { export async function editRawData(patcher: (data: KnownPluginSettingsMap) => (Promise<any> | any)) {
if (!patcher) return; if (!patcher) return;
const map = await DataStore.get(KNOWN_SETTINGS_DATA_KEY) as KnownPluginSettingsMap; const map = await DataStore.get(KNOWN_SETTINGS_DATA_KEY) as KnownPluginSettingsMap;
const newMap = new Map(map); const newMap = new Map(map);