diff --git a/apps/desktop/src/components/left-sidebar/events-list.tsx b/apps/desktop/src/components/left-sidebar/events-list.tsx index b578cce35..1ad06daaf 100644 --- a/apps/desktop/src/components/left-sidebar/events-list.tsx +++ b/apps/desktop/src/components/left-sidebar/events-list.tsx @@ -19,7 +19,6 @@ import { SplashLoader } from "@hypr/ui/components/ui/splash"; import { cn } from "@hypr/ui/lib/utils"; import { useSession } from "@hypr/utils/contexts"; import { formatUpcomingTime } from "@hypr/utils/datetime"; -import { safeNavigate } from "@hypr/utils/navigation"; type EventWithSession = Event & { session: Session | null }; @@ -128,14 +127,12 @@ function EventItem({ const handleOpenCalendar = () => { const date = new Date(event.start_date); + const formattedDate = format(date, "yyyy-MM-dd"); + const url = `/app/finder?view=calendar&date=${formattedDate}`; - const params = { - to: "/app/calendar", - search: { date: format(date, "yyyy-MM-dd") }, - } as const satisfies LinkProps; - - const url = `${params.to}?date=${params.search.date}`; - safeNavigate({ type: "calendar" }, url); + windowsCommands.windowShow({ type: "main" }).then(() => { + windowsCommands.windowEmitNavigate({ type: "main" }, url); + }); }; const isActive = activeSessionId diff --git a/apps/desktop/src/components/left-sidebar/notes-list.tsx b/apps/desktop/src/components/left-sidebar/notes-list.tsx index 9b8127de2..883883b4d 100644 --- a/apps/desktop/src/components/left-sidebar/notes-list.tsx +++ b/apps/desktop/src/components/left-sidebar/notes-list.tsx @@ -24,7 +24,6 @@ import { SplashLoader } from "@hypr/ui/components/ui/splash"; import { cn } from "@hypr/ui/lib/utils"; import { useSession, useSessions } from "@hypr/utils/contexts"; import { format, formatDate, formatRelative } from "@hypr/utils/datetime"; -import { safeNavigate } from "@hypr/utils/navigation"; interface NotesListProps { filter: (session: Session) => boolean; @@ -235,14 +234,12 @@ function NoteItem({ }; const handleOpenCalendar = () => { - const params = { - to: "/app/calendar", - search: { date: format(currentSession.created_at, "yyyy-MM-dd") }, - } as const satisfies LinkProps; + const formattedDate = format(currentSession.created_at, "yyyy-MM-dd"); + const url = `/app/finder?view=calendar&date=${formattedDate}`; - const url = `${params.to}?date=${params.search.date}`; - - safeNavigate({ type: "calendar" }, url); + windowsCommands.windowShow({ type: "main" }).then(() => { + windowsCommands.windowEmitNavigate({ type: "main" }, url); + }); }; const buttonRef = useRef(null); diff --git a/apps/desktop/src/components/workspace-calendar/event-card.tsx b/apps/desktop/src/components/workspace-calendar/event-card.tsx index cbf7f55b8..0db0c05c4 100644 --- a/apps/desktop/src/components/workspace-calendar/event-card.tsx +++ b/apps/desktop/src/components/workspace-calendar/event-card.tsx @@ -8,9 +8,9 @@ import { useMemo, useState } from "react"; import { useHypr } from "@/contexts"; import type { Event } from "@hypr/plugin-db"; import { commands as dbCommands } from "@hypr/plugin-db"; +import { commands as windowsCommands } from "@hypr/plugin-windows"; import { Button } from "@hypr/ui/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/popover"; -import { safeNavigate } from "@hypr/utils/navigation"; export function EventCard({ event, @@ -72,7 +72,9 @@ export function EventCard({ const url = props.to.replace("$id", props.params.id); - safeNavigate({ type: "main" }, url); + windowsCommands.windowShow({ type: "main" }).then(() => { + windowsCommands.windowEmitNavigate({ type: "main" }, url); + }); } else { const props = { to: "/app/new", @@ -83,7 +85,9 @@ export function EventCard({ `?calendarEventId=${props.search.calendarEventId}`, ); - safeNavigate({ type: "main" }, url); + windowsCommands.windowShow({ type: "main" }).then(() => { + windowsCommands.windowEmitNavigate({ type: "main" }, url); + }); } }; diff --git a/apps/desktop/src/components/workspace-calendar/note-card.tsx b/apps/desktop/src/components/workspace-calendar/note-card.tsx index 19dafa461..d2de11dbc 100644 --- a/apps/desktop/src/components/workspace-calendar/note-card.tsx +++ b/apps/desktop/src/components/workspace-calendar/note-card.tsx @@ -8,9 +8,9 @@ import { useMemo, useState } from "react"; import { useHypr } from "@/contexts"; import { type Session } from "@hypr/plugin-db"; import { commands as dbCommands } from "@hypr/plugin-db"; +import { commands as windowsCommands } from "@hypr/plugin-windows"; import { Button } from "@hypr/ui/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/popover"; -import { safeNavigate } from "@hypr/utils/navigation"; export function NoteCard({ session, @@ -62,7 +62,9 @@ export function NoteCard({ const url = props.to.replace("$id", props.params.id); - safeNavigate({ type: "main" }, url); + windowsCommands.windowShow({ type: "main" }).then(() => { + windowsCommands.windowEmitNavigate({ type: "main" }, url); + }); }; const getStartDate = () => { diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 177f16dea..bd29bb6c6 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,6 +1,5 @@ export * from "./ai"; export * from "./datetime"; export * from "./fetch"; -export * from "./navigation"; export * from "./organization"; export * from "./string"; diff --git a/packages/utils/src/navigation.ts b/packages/utils/src/navigation.ts deleted file mode 100644 index cc871ffd7..000000000 --- a/packages/utils/src/navigation.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { commands as windowsCommands } from "@hypr/plugin-windows"; -import type { HyprWindow } from "@hypr/plugin-windows"; - -/** - * Safely navigate to a URL in a specific window type - * This ensures the window is visible before attempting navigation - * to prevent potential crashes in the URL scheme handler - */ -export const safeNavigate = async ( - window: HyprWindow, - url: string, - maxAttempts = 50, -): Promise => { - // First ensure the window is shown - await windowsCommands.windowShow(window); - - // Then check visibility before navigating - let attempts = 0; - - const checkAndNavigate = async (): Promise => { - try { - const isVisible = await windowsCommands.windowIsVisible(window); - - if (isVisible) { - await windowsCommands.windowEmitNavigate(window, url); - return; - } else if (attempts < maxAttempts) { - attempts++; - // If not visible yet, check again after a short delay - setTimeout(checkAndNavigate, 100); - } else { - console.error("Max attempts reached waiting for window visibility"); - } - } catch (err) { - console.error("Error during safe navigation:", err); - } - }; - - // Start checking after a short initial delay - setTimeout(checkAndNavigate, 200); -};