mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
feat: add default enabled toggle
This commit is contained in:
@@ -84,7 +84,7 @@ export class PluginManager {
|
||||
if (plugin.disableToggle) {
|
||||
const settings = await browser.storage.local.get(`plugin.${pluginId}.settings`);
|
||||
const pluginSettings = settings[`plugin.${pluginId}.settings`] as PluginSettingsStorage | undefined;
|
||||
const enabled = pluginSettings?.enabled ?? true;
|
||||
const enabled = pluginSettings?.enabled ?? plugin.defaultEnabled ?? true;
|
||||
if (!enabled) {
|
||||
console.info(`Plugin "${pluginId}" is disabled, skipping initialization`);
|
||||
return;
|
||||
@@ -185,6 +185,7 @@ export class PluginManager {
|
||||
result.id = key;
|
||||
result.title = result.title || key;
|
||||
result.description = result.description || '';
|
||||
result.defaultEnabled = plugin.defaultEnabled ?? true;
|
||||
|
||||
return [key, result];
|
||||
});
|
||||
@@ -196,7 +197,7 @@ export class PluginManager {
|
||||
title: plugin.name,
|
||||
description: plugin.description,
|
||||
type: 'boolean',
|
||||
default: true
|
||||
default: plugin.defaultEnabled ?? true
|
||||
}
|
||||
])
|
||||
}
|
||||
@@ -205,7 +206,7 @@ export class PluginManager {
|
||||
name: plugin.name,
|
||||
description: plugin.description,
|
||||
settings: Object.fromEntries(settingsEntries),
|
||||
disableToggle: plugin.disableToggle
|
||||
disableToggle: plugin.disableToggle,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -258,7 +259,7 @@ export class PluginManager {
|
||||
if (!plugin?.disableToggle) continue;
|
||||
|
||||
const enabled = (change.newValue as PluginSettingsStorage)?.enabled ?? true;
|
||||
const wasEnabled = (change.oldValue as PluginSettingsStorage)?.enabled ?? true;
|
||||
const wasEnabled = (change.oldValue as PluginSettingsStorage)?.enabled ?? plugin.defaultEnabled ?? true;
|
||||
|
||||
if (enabled !== wasEnabled) {
|
||||
this.handlePluginStateChange(pluginId, enabled);
|
||||
|
||||
@@ -98,5 +98,6 @@ export interface Plugin<T extends PluginSettings = PluginSettings, S = any> {
|
||||
settings: T;
|
||||
styles?: string; // Optional CSS styles for the plugin
|
||||
disableToggle?: boolean; // Optional flag to show/hide the plugin's enable/disable toggle in settings
|
||||
defaultEnabled?: boolean; // Optional flag to set the plugin's default enabled state
|
||||
run: (api: PluginAPI<T, S>) => void | Promise<void> | (() => void) | Promise<(() => void)>;
|
||||
}
|
||||
Reference in New Issue
Block a user