feat: improved hotkey support and controls

This commit is contained in:
SethBurkart123
2025-05-25 18:15:06 +10:00
parent f66340cb63
commit 991f80d316
10 changed files with 570 additions and 112 deletions
+3 -1
View File
@@ -6,6 +6,7 @@ import type {
SelectSetting,
StringSetting,
ButtonSetting,
HotkeySetting,
} from "./types";
import { createPluginAPI } from "./createAPI";
import browser from "webextension-polyfill";
@@ -193,7 +194,8 @@ export class PluginManager {
id: string;
options: Array<{ value: string; label: string }>;
})
| (Omit<ButtonSetting, "type"> & { type: "button"; id: string; trigger?: () => void | Promise<void> });
| (Omit<ButtonSetting, "type"> & { type: "button"; id: string; trigger?: () => void | Promise<void> })
| (Omit<HotkeySetting, "type"> & { type: "hotkey"; id: string });
};
}> {
return Array.from(this.plugins.entries()).map(([id, plugin]) => {
+10
View File
@@ -4,6 +4,7 @@ import type {
NumberSetting,
SelectSetting,
StringSetting,
HotkeySetting,
} from "./types";
export function numberSetting(
@@ -51,6 +52,15 @@ export function buttonSetting(
};
}
export function hotkeySetting(
options: Omit<HotkeySetting, "type">,
): HotkeySetting {
return {
type: "hotkey",
...options,
};
}
export function defineSettings<T extends Record<string, any>>(settings: T): T {
return settings;
}
+12 -2
View File
@@ -41,12 +41,20 @@ export interface ButtonSetting {
trigger?: () => void | Promise<void>;
}
export interface HotkeySetting {
type: "hotkey";
default: string;
title: string;
description?: string;
}
export type PluginSetting =
| BooleanSetting
| StringSetting
| NumberSetting
| SelectSetting<string>
| ButtonSetting;
| ButtonSetting
| HotkeySetting;
export type PluginSettings = {
[key: string]: PluginSetting;
@@ -61,7 +69,9 @@ export type SettingValue<T extends PluginSetting> = T extends BooleanSetting
? number
: T extends SelectSetting<infer O>
? O
: never;
: T extends HotkeySetting
? string
: never;
export type SettingsAPI<T extends PluginSettings> = {
[K in keyof T]: SettingValue<T[K]>;