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:
parent
ff95a51dd7
commit
c3a51cc21b
5 changed files with 13 additions and 9 deletions
|
@ -144,6 +144,10 @@ export const SettingsStore = new SettingsStoreClass(settings, {
|
|||
// normal setting with a default value
|
||||
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) {
|
||||
const def = setting.options.find(o => o.default);
|
||||
if (def)
|
||||
|
|
|
@ -95,7 +95,7 @@ export default definePlugin({
|
|||
async start() {
|
||||
if (!settings.store.migrated) {
|
||||
const data = await DataStore.get(DATA_KEY);
|
||||
if (!!data) settings.store.data = data;
|
||||
if (data !== undefined) settings.store.data = data;
|
||||
settings.store.migrated = true;
|
||||
}
|
||||
for (const tag of settings.store.data) createTagCommand(tag);
|
||||
|
|
|
@ -39,7 +39,7 @@ export async function init() {
|
|||
}
|
||||
|
||||
export async function initCategories() {
|
||||
categories = settings.store.data;
|
||||
categories = settings.store.data ?? [];
|
||||
}
|
||||
|
||||
export function getCategory(id: string) {
|
||||
|
|
|
@ -49,7 +49,6 @@ export const settings = definePluginSettings({
|
|||
],
|
||||
onChange: () => forceUpdate()
|
||||
},
|
||||
|
||||
dmSectioncollapsed: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Collapse DM sections",
|
||||
|
|
|
@ -197,7 +197,7 @@ export type PluginSettingDef = (
|
|||
| PluginSettingSliderDef
|
||||
| PluginSettingComponentDef
|
||||
| PluginSettingBigIntDef
|
||||
| PluginSettingListDef
|
||||
| PluginSettingArrayDef
|
||||
) & PluginSettingCommon;
|
||||
|
||||
export interface PluginSettingCommon {
|
||||
|
@ -274,7 +274,7 @@ export interface PluginSettingSliderDef {
|
|||
stickToMarkers?: boolean;
|
||||
}
|
||||
|
||||
export interface PluginSettingListDef {
|
||||
export interface PluginSettingArrayDef {
|
||||
type: OptionType.ARRAY | OptionType.CHANNELS | OptionType.GUILDS | OptionType.USERS;
|
||||
popoutText?: string;
|
||||
hidePopout?: boolean;
|
||||
|
@ -314,9 +314,9 @@ type PluginSettingType<O extends PluginSettingDef> = O extends PluginSettingStri
|
|||
O extends PluginSettingSelectDef ? O["options"][number]["value"] :
|
||||
O extends PluginSettingSliderDef ? number :
|
||||
O extends PluginSettingComponentDef ? any :
|
||||
O extends PluginSettingListDef ? any[] :
|
||||
O extends PluginSettingArrayDef ? any[] :
|
||||
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 extends { default: infer T; } ? T : undefined;
|
||||
|
||||
|
@ -367,14 +367,15 @@ export type PluginOptionsItem =
|
|||
| PluginOptionBoolean
|
||||
| PluginOptionSelect
|
||||
| PluginOptionSlider
|
||||
| PluginOptionComponent;
|
||||
| PluginOptionComponent
|
||||
| PluginOptionArray;
|
||||
export type PluginOptionString = PluginSettingStringDef & PluginSettingCommon & IsDisabled & IsValid<string>;
|
||||
export type PluginOptionNumber = (PluginSettingNumberDef | PluginSettingBigIntDef) & PluginSettingCommon & IsDisabled & IsValid<number | BigInt>;
|
||||
export type PluginOptionBoolean = PluginSettingBooleanDef & PluginSettingCommon & IsDisabled & IsValid<boolean>;
|
||||
export type PluginOptionSelect = PluginSettingSelectDef & PluginSettingCommon & IsDisabled & IsValid<PluginSettingSelectOption>;
|
||||
export type PluginOptionSlider = PluginSettingSliderDef & PluginSettingCommon & IsDisabled & IsValid<number>;
|
||||
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>> = {
|
||||
[key in keyof PluginExports]:
|
||||
|
|
Loading…
Reference in a new issue