feat: button item + search storage reset

This commit is contained in:
SethBurkart123
2025-05-20 21:03:55 +10:00
parent 25623339f8
commit d8512e44cf
7 changed files with 79 additions and 16 deletions
+15 -10
View File
@@ -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];
},
);
+10
View File
@@ -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;
}
+9 -1
View File
@@ -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;