Skip to content

Commit 5ee2cd0

Browse files
feat(desktop): reload webview on Cmd/Ctrl+R (#785)
1 parent fa7febe commit 5ee2cd0

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎desktop/src/app/App.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "react";
1111

1212
import { router } from "@/app/router";
13+
import { useReloadShortcut } from "@/app/useReloadShortcut";
1314
import { useAppOnboardingState } from "@/features/onboarding/hooks";
1415
import { OnboardingFlow } from "@/features/onboarding/ui/OnboardingFlow";
1516
import { useWorkspaceInit } from "@/features/workspaces/useWorkspaceInit";
@@ -66,6 +67,10 @@ function AppReady({ isSharedIdentity }: { isSharedIdentity: boolean }) {
6667
}
6768

6869
export function App() {
70+
// Mounted at the root so Cmd/Ctrl+R reloads in every app state,
71+
// including the loading and first-run setup screens below.
72+
useReloadShortcut();
73+
6974
useLayoutEffect(() => {
7075
void getCurrentWindow().show();
7176
}, []);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from "react";
2+
3+
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
4+
5+
/**
6+
* Reloads the webview on the platform's reload shortcut (Cmd+R on macOS,
7+
* Ctrl+R elsewhere), matching browser behavior.
8+
*
9+
* `window.location.reload()` is the app's existing reload primitive (see
10+
* App.tsx, useWorkspaceInit.ts): it triggers a full reinit that re-reads
11+
* localStorage and reconnects relays.
12+
*/
13+
export function useReloadShortcut() {
14+
React.useEffect(() => {
15+
function handleKeyDown(event: KeyboardEvent) {
16+
if (
17+
!hasPrimaryShortcutModifier(event) ||
18+
event.altKey ||
19+
event.shiftKey
20+
) {
21+
return;
22+
}
23+
if (event.key.toLowerCase() !== "r") {
24+
return;
25+
}
26+
27+
event.preventDefault();
28+
window.location.reload();
29+
}
30+
31+
window.addEventListener("keydown", handleKeyDown);
32+
return () => {
33+
window.removeEventListener("keydown", handleKeyDown);
34+
};
35+
}, []);
36+
}

0 commit comments

Comments
 (0)