mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 19:37:01 -04:00
Settings API: add support for custom objects / arrays (#3154)
This commit is contained in:
parent
317121fc08
commit
5c8ba6e542
13 changed files with 420 additions and 355 deletions
|
@ -189,6 +189,7 @@ export const enum OptionType {
|
|||
SELECT,
|
||||
SLIDER,
|
||||
COMPONENT,
|
||||
CUSTOM
|
||||
}
|
||||
|
||||
export type SettingsDefinition = Record<string, PluginSettingDef>;
|
||||
|
@ -197,7 +198,7 @@ export type SettingsChecks<D extends SettingsDefinition> = {
|
|||
(IsDisabled<DefinedSettings<D>> & IsValid<PluginSettingType<D[K]>, DefinedSettings<D>>);
|
||||
};
|
||||
|
||||
export type PluginSettingDef = (
|
||||
export type PluginSettingDef = (PluginSettingCustomDef & Pick<PluginSettingCommon, "onChange">) | ((
|
||||
| PluginSettingStringDef
|
||||
| PluginSettingNumberDef
|
||||
| PluginSettingBooleanDef
|
||||
|
@ -205,7 +206,7 @@ export type PluginSettingDef = (
|
|||
| PluginSettingSliderDef
|
||||
| PluginSettingComponentDef
|
||||
| PluginSettingBigIntDef
|
||||
) & PluginSettingCommon;
|
||||
) & PluginSettingCommon);
|
||||
|
||||
export interface PluginSettingCommon {
|
||||
description: string;
|
||||
|
@ -259,12 +260,18 @@ export interface PluginSettingSelectDef {
|
|||
type: OptionType.SELECT;
|
||||
options: readonly PluginSettingSelectOption[];
|
||||
}
|
||||
|
||||
export interface PluginSettingSelectOption {
|
||||
label: string;
|
||||
value: string | number | boolean;
|
||||
default?: boolean;
|
||||
}
|
||||
|
||||
export interface PluginSettingCustomDef {
|
||||
type: OptionType.CUSTOM;
|
||||
default?: any;
|
||||
}
|
||||
|
||||
export interface PluginSettingSliderDef {
|
||||
type: OptionType.SLIDER;
|
||||
/**
|
||||
|
@ -314,7 +321,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 PluginSettingCustomDef ? O extends { default: infer Default; } ? Default : any :
|
||||
never;
|
||||
|
||||
type PluginSettingDefaultType<O extends PluginSettingDef> = O extends PluginSettingSelectDef ? (
|
||||
O["options"] extends { default?: boolean; }[] ? O["options"][number]["value"] : undefined
|
||||
) : O extends { default: infer T; } ? T : undefined;
|
||||
|
@ -366,13 +375,15 @@ export type PluginOptionsItem =
|
|||
| PluginOptionBoolean
|
||||
| PluginOptionSelect
|
||||
| PluginOptionSlider
|
||||
| PluginOptionComponent;
|
||||
| PluginOptionComponent
|
||||
| PluginOptionCustom;
|
||||
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 PluginOptionCustom = PluginSettingCustomDef & Pick<PluginSettingCommon, "onChange">;
|
||||
|
||||
export type PluginNative<PluginExports extends Record<string, (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any>> = {
|
||||
[key in keyof PluginExports]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue