feat(plugins/settings): show Reload required dialog immediately after flag update

This commit is contained in:
PalmDevs 2025-08-13 00:54:14 +07:00
parent d38a0394f6
commit 2b69e17d68
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 12 additions and 5 deletions

View file

@ -64,6 +64,7 @@ export interface InternalPluginMeta {
dependents: AnyPlugin[]
dependencies?: AnyPlugin[]
options: PluginOptions<any>
flags: number
}
export const pUnscopedApi = uapi
@ -76,6 +77,7 @@ export const pEmitter = new TypedEventEmitter<{
started: [AnyPlugin]
stopped: [AnyPlugin]
errored: [AnyPlugin, unknown]
flagUpdate: [AnyPlugin]
}>()
export const pList = new Map<PluginManifest['id'], AnyPlugin>()
@ -94,7 +96,7 @@ export function registerPlugin<O extends PluginApiExtensionsOptions>(
if (pList.has(manifest.id))
throw new Error(`Plugin with ID "${manifest.id}" already registered`)
const plugin: AnyPlugin = {
const plugin = {
errors: [],
manifest,
lifecycles: {
@ -105,10 +107,16 @@ export function registerPlugin<O extends PluginApiExtensionsOptions>(
},
SettingsComponent: options.SettingsComponent,
status: 0,
flags,
disable: () => disablePlugin(plugin),
stop: () => stopPlugin(plugin),
api: undefined,
set flags(flags: number) {
meta.flags = flags
pEmitter.emit('flagUpdate', this)
},
get flags() {
return meta.flags
},
}
const meta: InternalPluginMeta = {
@ -119,6 +127,7 @@ export function registerPlugin<O extends PluginApiExtensionsOptions>(
dependents: [],
handleError: e => handlePluginError(e, plugin),
options,
flags,
}
pMetadata.set(plugin, meta)

View file

@ -53,8 +53,7 @@ function useEnabledPluginCount() {
const { AlertActionButton, AlertModal, Text } = Design
pEmitter.on('started', showReloadRequiredAlertIfNeeded)
pEmitter.on('stopped', showReloadRequiredAlertIfNeeded)
pEmitter.on('flagUpdate', showReloadRequiredAlertIfNeeded)
function showReloadRequiredAlertIfNeeded(plugin: AnyPlugin) {
if (plugin.flags & PluginFlags.ReloadRequired) {
@ -87,7 +86,6 @@ function PluginReloadRequiredAlert({ plugins }: { plugins: AnyPlugin[] }) {
>
{plugin.manifest.name}
</Text>
{', '}
</>
))}
</Text>