Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add Cmd/Ctrl+W shortcut to close windows

Richie McIlroy6bf4852dcadc
diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsx
index 95fde7a10..7ab785b37 100644
--- a/apps/desktop/src/routes/(window-chrome).tsx
+++ b/apps/desktop/src/routes/(window-chrome).tsx
@@ -35,8 +35,25 @@ export default function (props: RouteSectionProps) {
}
});
+ const handleKeyDown = (e: KeyboardEvent) => {
+ const isMac = ostype() === "macos";
+ const closeShortcut = isMac
+ ? e.metaKey && e.key === "w"
+ : e.ctrlKey && e.key === "w";
+
+ if (closeShortcut) {
+ e.preventDefault();
+ getCurrentWindow().close();
+ }
+ };
+
+ onMount(() => {
+ window.addEventListener("keydown", handleKeyDown);
+ });
+
onCleanup(() => {
unlistenResize?.();
+ window.removeEventListener("keydown", handleKeyDown);
});
const isMacOS = ostype() === "macos";