feat(desktop): reload webview on Cmd/Ctrl+R (#785)

This commit is contained in:
tlongwell-block
2026-05-29 10:24:56 -04:00
committed by GitHub
parent fa7febe40f
commit 5ee2cd0517
2 changed files with 41 additions and 0 deletions
+5
View File
@@ -10,6 +10,7 @@ import {
} from "react";
import { router } from "@/app/router";
import { useReloadShortcut } from "@/app/useReloadShortcut";
import { useAppOnboardingState } from "@/features/onboarding/hooks";
import { OnboardingFlow } from "@/features/onboarding/ui/OnboardingFlow";
import { useWorkspaceInit } from "@/features/workspaces/useWorkspaceInit";
@@ -66,6 +67,10 @@ function AppReady({ isSharedIdentity }: { isSharedIdentity: boolean }) {
}
export function App() {
// Mounted at the root so Cmd/Ctrl+R reloads in every app state,
// including the loading and first-run setup screens below.
useReloadShortcut();
useLayoutEffect(() => {
void getCurrentWindow().show();
}, []);
+36
View File
@@ -0,0 +1,36 @@
import * as React from "react";
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
/**
* Reloads the webview on the platform's reload shortcut (Cmd+R on macOS,
* Ctrl+R elsewhere), matching browser behavior.
*
* `window.location.reload()` is the app's existing reload primitive (see
* App.tsx, useWorkspaceInit.ts): it triggers a full reinit that re-reads
* localStorage and reconnects relays.
*/
export function useReloadShortcut() {
React.useEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
if (
!hasPrimaryShortcutModifier(event) ||
event.altKey ||
event.shiftKey
) {
return;
}
if (event.key.toLowerCase() !== "r") {
return;
}
event.preventDefault();
window.location.reload();
}
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, []);
}