mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: button item + search storage reset
This commit is contained in:
+15
-10
@@ -5,6 +5,7 @@ import type {
|
||||
PluginSettings,
|
||||
SelectSetting,
|
||||
StringSetting,
|
||||
ButtonSetting,
|
||||
} from "./types";
|
||||
import { createPluginAPI } from "./createAPI";
|
||||
import browser from "webextension-polyfill";
|
||||
@@ -190,26 +191,30 @@ export class PluginManager {
|
||||
type: "select";
|
||||
id: string;
|
||||
options: Array<{ value: string; label: string }>;
|
||||
});
|
||||
})
|
||||
| (Omit<ButtonSetting, "type"> & { type: "button"; id: string; trigger?: () => void | Promise<void> });
|
||||
};
|
||||
}> {
|
||||
return Array.from(this.plugins.entries()).map(([id, plugin]) => {
|
||||
const settingsEntries = Object.entries(plugin.settings).map(
|
||||
([key, setting]) => {
|
||||
const settingObj = setting as any;
|
||||
// Create a copy of the setting object without any functions
|
||||
const result: any = Object.fromEntries(
|
||||
Object.entries(settingObj).filter(
|
||||
([_, value]) => typeof value !== "function",
|
||||
),
|
||||
);
|
||||
|
||||
// Ensure required properties are present
|
||||
let result: any;
|
||||
if (settingObj.type === "button") {
|
||||
// For button, keep the trigger function
|
||||
result = { ...settingObj };
|
||||
} else {
|
||||
// For others, strip functions
|
||||
result = Object.fromEntries(
|
||||
Object.entries(settingObj).filter(
|
||||
([_, value]) => typeof value !== "function",
|
||||
),
|
||||
);
|
||||
}
|
||||
result.id = key;
|
||||
result.title = result.title || key;
|
||||
result.description = result.description || "";
|
||||
result.defaultEnabled = plugin.defaultEnabled ?? true;
|
||||
|
||||
return [key, result];
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
BooleanSetting,
|
||||
ButtonSetting,
|
||||
NumberSetting,
|
||||
SelectSetting,
|
||||
StringSetting,
|
||||
@@ -41,6 +42,15 @@ export function selectSetting<T extends string>(
|
||||
};
|
||||
}
|
||||
|
||||
export function buttonSetting(
|
||||
options: Omit<ButtonSetting, "type">,
|
||||
): ButtonSetting {
|
||||
return {
|
||||
type: "button",
|
||||
...options,
|
||||
};
|
||||
}
|
||||
|
||||
export function defineSettings<T extends Record<string, any>>(settings: T): T {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -34,11 +34,19 @@ export interface SelectSetting<T extends string> {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface ButtonSetting {
|
||||
type: "button";
|
||||
title: string;
|
||||
description?: string;
|
||||
trigger?: () => void | Promise<void>;
|
||||
}
|
||||
|
||||
export type PluginSetting =
|
||||
| BooleanSetting
|
||||
| StringSetting
|
||||
| NumberSetting
|
||||
| SelectSetting<string>;
|
||||
| SelectSetting<string>
|
||||
| ButtonSetting;
|
||||
|
||||
export type PluginSettings = {
|
||||
[key: string]: PluginSetting;
|
||||
|
||||
Reference in New Issue
Block a user