Skip to content
TypeScript

fix(desktop): Ctrl+R on macOS reaches the preview page instead of reloading it (#29893)

Alex Southwella50fe102fb6d
diff --git a/apps/desktop/src/preview/Manager.test.ts b/apps/desktop/src/preview/Manager.test.ts
index d917af72d38..32b9ad23f9c 100644
--- a/apps/desktop/src/preview/Manager.test.ts
+++ b/apps/desktop/src/preview/Manager.test.ts
@@ -615,6 +615,33 @@ describe("PreviewManager", () => {
),
);
+ effectIt.effect.each([
+ ["darwin", true, false, true],
+ ["darwin", false, true, false],
+ ["linux", false, true, true],
+ ["win32", true, false, false],
+ ] as const)(
+ "reloads the preview only on the platform refresh chord: %s meta=%s ctrl=%s",
+ ([platform, meta, control, expected]) =>
+ withManager(
+ (manager) =>
+ Effect.gen(function* () {
+ const preview = makeFaviconWebContents();
+ fromId.mockReturnValue(preview.webContents);
+ yield* manager.createTab("tab_refresh");
+ yield* manager.registerWebview("tab_refresh", 42);
+ const preventDefault = vi.fn();
+ preview.listeners.get("before-input-event")!(
+ { preventDefault } as never,
+ { type: "keyDown", key: "r", meta, control, shift: false, alt: false } as never,
+ );
+ expect(preventDefault).toHaveBeenCalledTimes(expected ? 1 : 0);
+ expect(preview.reload).toHaveBeenCalledTimes(expected ? 1 : 0);
+ }),
+ platform,
+ ),
+ );
+
effectIt.effect("keeps editing and forwarded shortcuts in whichever tab holds focus", () =>
withManager((manager) =>
Effect.gen(function* () {
diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts
index c83eae8d835..18eb4b2b759 100644
--- a/apps/desktop/src/preview/Manager.ts
+++ b/apps/desktop/src/preview/Manager.ts
@@ -464,10 +464,10 @@ export const previewWindowOpenAction = (details: {
: "navigate";
};
-const isPreviewRefreshShortcut = (input: Electron.Input): boolean =>
+const isPreviewRefreshShortcut = (input: Electron.Input, platform: NodeJS.Platform): boolean =>
input.type === "keyDown" &&
input.key.toLowerCase() === "r" &&
- (input.meta || input.control) &&
+ (platform === "darwin" ? input.meta && !input.control : input.control && !input.meta) &&
!input.shift &&
!input.alt;
@@ -1488,7 +1488,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
}
return;
}
- if (isPreviewRefreshShortcut(input)) {
+ if (isPreviewRefreshShortcut(input, hostPlatform)) {
event.preventDefault();
runFork(
attempt({ operation: "shortcut.refresh", tabId, webContentsId: wc.id }, () =>