mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: start plugins on every page, not only after the mail view opened
This commit is contained in:
@@ -18,7 +18,7 @@ function listen<T extends { register: (id: string, fn: (...a: unknown[]) => unkn
|
||||
beforeEach(() => {
|
||||
clearAllHooks();
|
||||
pathname = '/';
|
||||
usePluginStore.setState({ initialized: false });
|
||||
usePluginStore.setState({ initialized: false, initializePlugins: vi.fn().mockResolvedValue(undefined) });
|
||||
useAuthStore.setState({ isAuthenticated: false });
|
||||
});
|
||||
afterEach(() => {
|
||||
@@ -74,6 +74,15 @@ describe('app events for plugins', () => {
|
||||
expect(ready).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('starts the plugins once the user is signed in, on any page', () => {
|
||||
render(<PluginAppEvents />);
|
||||
expect(usePluginStore.getState().initializePlugins).not.toHaveBeenCalled();
|
||||
|
||||
act(() => { useAuthStore.setState({ isAuthenticated: true }); });
|
||||
|
||||
expect(usePluginStore.getState().initializePlugins).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('reports navigation between pages', () => {
|
||||
const navigate = listen(routerHooks.onNavigate);
|
||||
const { rerender } = render(<PluginAppEvents />);
|
||||
|
||||
@@ -122,6 +122,14 @@ export function PluginAppEvents() {
|
||||
// plugins have been started, so every plugin enabled at start hears it.
|
||||
const pluginsReady = usePluginStore((s) => s.initialized);
|
||||
const signedIn = useAuthStore((s) => s.isAuthenticated);
|
||||
|
||||
// Start the plugins on whichever page the user lands on. They used to start
|
||||
// only from the mail view, so a plugin's sidebar entry, page or reminders
|
||||
// were missing on Calendar, Contacts, Files or Settings opened directly.
|
||||
useEffect(() => {
|
||||
if (signedIn) void usePluginStore.getState().initializePlugins();
|
||||
}, [signedIn]);
|
||||
|
||||
const readyFired = useRef(false);
|
||||
useEffect(() => {
|
||||
if (readyFired.current || !pluginsReady || !signedIn) return;
|
||||
|
||||
Reference in New Issue
Block a user