fix: preserve plugin dialogs and isolate event delivery
This commit is contained in:
1 parent
36486a0850
commit
fe0c014e60
3 files changed
+15
-6
No files matched your search
@@ -330,10 +330,12 @@ test('closing a page retries cleanup of a late task after rate limiting', async
|
||||
assert.equal(attempts, 2)
|
||||
})
|
||||
|
||||
test('pruning removes a view and dialogs when their conditions stop matching', () => {
|
||||
test('pruning removes an unavailable page but keeps open dialogs until their VM disappears', () => {
|
||||
const page = { pluginId: 'demo', viewId: 'vm', location: 'vm.tab', vm: 'vm-1' }
|
||||
const dialog = { ...page, viewId: 'dialog', location: 'dialog' }
|
||||
let state = openPluginView(emptyPluginViewState, page)
|
||||
state = openPluginView(state, dialog)
|
||||
assert.deepEqual(prunePluginViews(state, new Set(['demo/vm', 'demo/dialog']), () => true, () => false), emptyPluginViewState)
|
||||
const views = new Set(['demo/vm', 'demo/dialog'])
|
||||
assert.deepEqual(prunePluginViews(state, views, () => true, () => false), { ...emptyPluginViewState, dialogs: [dialog] })
|
||||
assert.deepEqual(prunePluginViews(state, views, () => false), emptyPluginViewState)
|
||||
})
|
||||
@@ -4,7 +4,13 @@ export type PluginHostEventListener = (event: PluginHostEvent, data: unknown) =>
|
||||
const listeners = new Set<PluginHostEventListener>()
|
||||
|
||||
export function publishPluginHostEvent(event: PluginHostEvent, data: unknown): void {
|
||||
for (const listener of [...listeners]) listener(event, data)
|
||||
for (const listener of [...listeners]) {
|
||||
try {
|
||||
listener(event, data)
|
||||
} catch (error) {
|
||||
console.warn('[plugin] could not deliver host event:', event, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function subscribePluginHostEvents(listener: PluginHostEventListener): () => void {
|
||||
|
||||
@@ -67,11 +67,12 @@ export function prunePluginViews(
|
||||
validVM: (vm: string | undefined) => boolean,
|
||||
available: (route: PluginViewRoute) => boolean = () => true,
|
||||
): PluginViewState {
|
||||
const valid = (route: PluginViewRoute) => validViews.has(pluginViewKey(route)) && (route.location !== 'vm.tab' || validVM(route.vm)) && available(route)
|
||||
const route = state.route && valid(state.route) ? state.route : null
|
||||
const valid = (route: PluginViewRoute) => validViews.has(pluginViewKey(route)) && (!route.vm || validVM(route.vm))
|
||||
const usable = (route: PluginViewRoute) => valid(route) && available(route)
|
||||
const route = state.route && usable(state.route) ? state.route : null
|
||||
return {
|
||||
route,
|
||||
dialogs: state.dialogs.filter(valid),
|
||||
returnStack: route ? state.returnStack.filter(valid) : [],
|
||||
returnStack: route ? state.returnStack.filter(usable) : [],
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user