1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 09:56:24 +00:00

fix names & give arrays a default value

This commit is contained in:
Elvyra 2025-01-05 22:35:20 +01:00
parent ff95a51dd7
commit c3a51cc21b
5 changed files with 13 additions and 9 deletions

View file

@ -144,6 +144,10 @@ export const SettingsStore = new SettingsStoreClass(settings, {
// normal setting with a default value // normal setting with a default value
return (target[key] = setting.default); return (target[key] = setting.default);
else if (setting.type === OptionType.ARRAY || setting.type === OptionType.USERS || setting.type === OptionType.GUILDS || setting.type === OptionType.CHANNELS)
// if there is no default value we initialize it as an empty array
return (target[key] = []);
if (setting.type === OptionType.SELECT) { if (setting.type === OptionType.SELECT) {
const def = setting.options.find(o => o.default); const def = setting.options.find(o => o.default);
if (def) if (def)

View file

@ -95,7 +95,7 @@ export default definePlugin({
async start() { async start() {
if (!settings.store.migrated) { if (!settings.store.migrated) {
const data = await DataStore.get(DATA_KEY); const data = await DataStore.get(DATA_KEY);
if (!!data) settings.store.data = data; if (data !== undefined) settings.store.data = data;
settings.store.migrated = true; settings.store.migrated = true;
} }
for (const tag of settings.store.data) createTagCommand(tag); for (const tag of settings.store.data) createTagCommand(tag);

View file

@ -39,7 +39,7 @@ export async function init() {
} }
export async function initCategories() { export async function initCategories() {
categories = settings.store.data; categories = settings.store.data ?? [];
} }
export function getCategory(id: string) { export function getCategory(id: string) {

View file

@ -49,7 +49,6 @@ export const settings = definePluginSettings({
], ],
onChange: () => forceUpdate() onChange: () => forceUpdate()
}, },
dmSectioncollapsed: { dmSectioncollapsed: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
description: "Collapse DM sections", description: "Collapse DM sections",

View file

@ -197,7 +197,7 @@ export type PluginSettingDef = (
| PluginSettingSliderDef | PluginSettingSliderDef
| PluginSettingComponentDef | PluginSettingComponentDef
| PluginSettingBigIntDef | PluginSettingBigIntDef
| PluginSettingListDef | PluginSettingArrayDef
) & PluginSettingCommon; ) & PluginSettingCommon;
export interface PluginSettingCommon { export interface PluginSettingCommon {
@ -274,7 +274,7 @@ export interface PluginSettingSliderDef {
stickToMarkers?: boolean; stickToMarkers?: boolean;
} }
export interface PluginSettingListDef { export interface PluginSettingArrayDef {
type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS; type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS;
popoutText?: string; popoutText?: string;
hidePopout?: boolean; hidePopout?: boolean;
@ -314,9 +314,9 @@ type PluginSettingType<O extends PluginSettingDef> = O extends PluginSettingStri
O extends PluginSettingSelectDef ? O["options"][number]["value"] : O extends PluginSettingSelectDef ? O["options"][number]["value"] :
O extends PluginSettingSliderDef ? number : O extends PluginSettingSliderDef ? number :
O extends PluginSettingComponentDef ? any : O extends PluginSettingComponentDef ? any :
O extends PluginSettingListDef ? any[] : O extends PluginSettingArrayDef ? any[] :
never; never;
type PluginSettingDefaultType<O extends PluginSettingDef> = O extends PluginSettingListDef ? any[] : O extends PluginSettingSelectDef ? ( type PluginSettingDefaultType<O extends PluginSettingDef> = O extends PluginSettingArrayDef ? any[] : O extends PluginSettingSelectDef ? (
O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined
) : O extends { default: infer T; } ? T : undefined; ) : O extends { default: infer T; } ? T : undefined;
@ -367,14 +367,15 @@ export type PluginOptionsItem =
| PluginOptionBoolean | PluginOptionBoolean
| PluginOptionSelect | PluginOptionSelect
| PluginOptionSlider | PluginOptionSlider
| PluginOptionComponent; | PluginOptionComponent
| PluginOptionArray;
export type PluginOptionString = PluginSettingStringDef & PluginSettingCommon & IsDisabled & IsValid<string>; export type PluginOptionString = PluginSettingStringDef & PluginSettingCommon & IsDisabled & IsValid<string>;
export type PluginOptionNumber = (PluginSettingNumberDef | PluginSettingBigIntDef) & PluginSettingCommon & IsDisabled & IsValid<number | BigInt>; export type PluginOptionNumber = (PluginSettingNumberDef | PluginSettingBigIntDef) & PluginSettingCommon & IsDisabled & IsValid<number | BigInt>;
export type PluginOptionBoolean = PluginSettingBooleanDef & PluginSettingCommon & IsDisabled & IsValid<boolean>; export type PluginOptionBoolean = PluginSettingBooleanDef & PluginSettingCommon & IsDisabled & IsValid<boolean>;
export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon & IsDisabled & IsValid<PluginSettingSelectOption>; export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon & IsDisabled & IsValid<PluginSettingSelectOption>;
export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>; export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>;
export type PluginOptionComponent = PluginSettingComponentDef & PluginSettingCommon; export type PluginOptionComponent = PluginSettingComponentDef & PluginSettingCommon;
export type PluginOptionList = PluginSettingListDef & PluginSettingCommon; export type PluginOptionArray = PluginSettingArrayDef & PluginSettingCommon;
export type PluginNative<PluginExports extends Record<string, (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any>> = { export type PluginNative<PluginExports extends Record<string, (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any>> = {
[key in keyof PluginExports]: [key in keyof PluginExports]: