Skip to content

Commit 141550c

Browse files
fixed hotkeys
1 parent c030d55 commit 141550c

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

apps/desktop/src/components/main/body/index.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
1+
import { Button } from "@hypr/ui/components/ui/button";
2+
import { cn } from "@hypr/utils";
3+
24
import { ArrowLeftIcon, ArrowRightIcon, PanelLeftOpenIcon, PlusIcon } from "lucide-react";
35
import { Reorder } from "motion/react";
46
import { useCallback, useEffect, useRef } from "react";
57
import { useHotkeys } from "react-hotkeys-hook";
68
import { useShallow } from "zustand/shallow";
79

8-
import { Button } from "@hypr/ui/components/ui/button";
9-
import { cn } from "@hypr/utils";
1010
import { useShell } from "../../../contexts/shell";
1111
import { type Tab, uniqueIdfromTab, useTabs } from "../../../store/zustand/tabs";
1212
import { ChatFloatingButton } from "../../chat";
@@ -376,16 +376,12 @@ function useTabsShortcuts() {
376376
() => {
377377
if (currentTab?.type === "empty") {
378378
newNoteCurrent();
379-
return;
380-
}
381-
382-
if (currentTab) {
383-
close(currentTab);
379+
} else {
380+
newNote();
384381
}
385-
newNote();
386382
},
387383
{ preventDefault: true, enableOnFormTags: true, enableOnContentEditable: true },
388-
[currentTab, close, newNote, newNoteCurrent],
384+
[currentTab, newNote, newNoteCurrent],
389385
);
390386

391387
useHotkeys(
@@ -398,15 +394,12 @@ function useTabsShortcuts() {
398394
useHotkeys(
399395
"mod+w",
400396
async () => {
401-
if (currentTab && tabs.length > 1) {
397+
if (currentTab) {
402398
close(currentTab);
403-
} else {
404-
const appWindow = getCurrentWebviewWindow();
405-
await appWindow.close();
406399
}
407400
},
408401
{ preventDefault: true, enableOnFormTags: true, enableOnContentEditable: true },
409-
[tabs, currentTab, close],
402+
[currentTab, close],
410403
);
411404

412405
useHotkeys(

apps/desktop/src/routes/app/main/_layout.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createFileRoute, Outlet, useRouteContext } from "@tanstack/react-router";
2-
import { useCallback, useEffect } from "react";
2+
import { useCallback, useEffect, useRef } from "react";
33

44
import { buildChatTools } from "../../../chat/tools";
55
import { AITaskProvider } from "../../../contexts/ai-task";
@@ -17,21 +17,22 @@ export const Route = createFileRoute("/app/main/_layout")({
1717

1818
function Component() {
1919
const { persistedStore, aiTaskStore, toolRegistry } = useRouteContext({ from: "__root__" });
20-
const { registerOnEmpty, currentTab, openNew } = useTabs();
20+
const { registerOnEmpty, openNew, tabs } = useTabs();
21+
const hasOpenedInitialTab = useRef(false);
2122

2223
const openDefaultEmptyTab = useCallback(() => {
2324
openNew({ type: "empty" });
2425
}, [openNew]);
2526

2627
useEffect(() => {
27-
if (!currentTab) {
28+
// Use ref to prevent double-opening in React Strict Mode
29+
if (tabs.length === 0 && !hasOpenedInitialTab.current) {
30+
hasOpenedInitialTab.current = true;
2831
openDefaultEmptyTab();
2932
}
30-
}, [currentTab, openDefaultEmptyTab]);
3133

32-
useEffect(() => {
3334
registerOnEmpty(openDefaultEmptyTab);
34-
}, [openDefaultEmptyTab, registerOnEmpty]);
35+
}, [tabs.length, openDefaultEmptyTab, registerOnEmpty]);
3536

3637
if (!aiTaskStore) {
3738
return null;

0 commit comments

Comments
 (0)