mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
feat(desktop): reload webview on Cmd/Ctrl+R (#785)
This commit is contained in:
@@ -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();
|
||||
}, []);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user