Skip to content

Commit 87989fa

Browse files
author
MargeBot
committed
Merge branch 'fix/event-loop-call-desktop-app' into 'main'
feat(desktop): refresh event loop when returning from settings to mail or calendar See merge request web/clients!25468
2 parents 98fab7b + 3dee5e1 commit 87989fa

5 files changed

Lines changed: 45 additions & 0 deletions

File tree

applications/calendar/src/app/containers/calendar/MainContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import KeyTransparencyManager from '@proton/components/containers/keyTransparenc
1111
import SubscriptionModalProvider from '@proton/components/containers/payments/subscription/SubscriptionModalProvider';
1212
import useDrawerParent from '@proton/components/hooks/drawer/useDrawerParent';
1313
import { QuickSettingsRemindersProvider } from '@proton/components/hooks/drawer/useQuickSettingsReminders';
14+
import { useInboxDesktopEventLoopRefresh } from '@proton/components/hooks/useInboxDesktopEventLoopRefresh';
1415
import { usePreventWasmLoading } from '@proton/components/hooks/usePreventWasmLoading';
1516
import { FeatureCode, useFeatures } from '@proton/features';
1617
import { useInstance } from '@proton/hooks';
@@ -35,6 +36,7 @@ import NotificationManagerInjector from './notifications/NotificationManagerInje
3536
const MainContainer = () => {
3637
useCalendarFavicon();
3738
usePreventWasmLoading();
39+
useInboxDesktopEventLoopRefresh();
3840

3941
const hasReactivatedCalendarsRef = useRef<boolean>(false);
4042
const [addresses] = useAddresses();

applications/inbox-desktop/src/utils/view/viewManagement.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ export async function showView(viewID: CHANGE_VIEW_TARGET, url: string = "") {
365365
return;
366366
}
367367

368+
const previousViewID = currentViewID;
368369
currentViewID = viewID;
369370

370371
mainWindow!.title = viewTitleMap[viewID];
@@ -397,6 +398,19 @@ export async function showView(viewID: CHANGE_VIEW_TARGET, url: string = "") {
397398
viewLogger(viewID).info("showView showing view for ", url);
398399
mainWindow!.setContentView(view);
399400
}
401+
402+
if (previousViewID === "account" && (viewID === "mail" || viewID === "calendar")) {
403+
try {
404+
viewLogger(viewID).info("Refreshing event loop after returning from account view");
405+
view.webContents.send("hostUpdate", { type: "refreshEventLoop" });
406+
} catch (e) {
407+
viewLogger(viewID).error("Refreshing event loop", e);
408+
sentryReport.reportMessage("Failed to refresh event loop after returning from account view", {
409+
level: "error",
410+
error: e instanceof Error ? e : undefined,
411+
});
412+
}
413+
}
400414
}
401415

402416
/**

applications/mail/src/app/MainContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SubscriptionModalProvider from '@proton/components/containers/payments/su
1111
import { DrawerThemeInjector } from '@proton/components/containers/themes/ThemeInjector';
1212
import { QuickSettingsRemindersProvider } from '@proton/components/hooks/drawer/useQuickSettingsReminders';
1313
import useConfig from '@proton/components/hooks/useConfig';
14+
import { useInboxDesktopEventLoopRefresh } from '@proton/components/hooks/useInboxDesktopEventLoopRefresh';
1415
import { useInboxDesktopMetrics } from '@proton/components/hooks/useInboxDesktopMetrics';
1516
import { usePreventWasmLoading } from '@proton/components/hooks/usePreventWasmLoading.ts';
1617
import AssistantProvider from '@proton/llm/lib/providers/AssistantProvider';
@@ -33,6 +34,7 @@ const MainContainer: FunctionComponent = () => {
3334

3435
useInboxDesktopHeartbeat();
3536
useInboxDesktopMetrics();
37+
useInboxDesktopEventLoopRefresh();
3638

3739
usePreventWasmLoading();
3840

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useEffect } from 'react';
2+
3+
import { addIPCHostUpdateListener, canListenInboxDesktopHostMessages } from '@proton/shared/lib/desktop/ipcHelpers';
4+
5+
import useEventManager from './useEventManager';
6+
7+
export const useInboxDesktopEventLoopRefresh = () => {
8+
const { call } = useEventManager();
9+
10+
useEffect(() => {
11+
if (!canListenInboxDesktopHostMessages) {
12+
return;
13+
}
14+
15+
const listener = addIPCHostUpdateListener('refreshEventLoop', () => {
16+
void call();
17+
});
18+
19+
return () => {
20+
listener.removeListener();
21+
};
22+
}, [call]);
23+
};

packages/shared/lib/desktop/desktopTypes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export const IPCInboxHostUpdateMessageSchema = z.discriminatedUnion('type', [
114114
type: z.literal('sentHeartbeatMetrics'),
115115
payload: z.custom<HttpsProtonMeDesktopInboxHeartbeatTotalV1SchemaJson>(),
116116
}),
117+
z.object({
118+
type: z.literal('refreshEventLoop'),
119+
payload: z.undefined().optional(),
120+
}),
117121
]);
118122

119123
export type IPCInboxHostUpdateMessage = z.infer<typeof IPCInboxHostUpdateMessageSchema>;

0 commit comments

Comments
 (0)