Refresh UI when receiving deep link

This commit is contained in:
Will Chen
2025-04-22 21:56:43 -07:00
parent ae2cb0fc6b
commit 42b759d85c
7 changed files with 90 additions and 10 deletions

View File

@@ -0,0 +1,34 @@
import React, { createContext, useContext, useEffect, useState } from "react";
import { IpcClient, DeepLinkData } from "../ipc/ipc_client";
type DeepLinkContextType = {
lastDeepLink: (DeepLinkData & { timestamp: number }) | null;
};
const DeepLinkContext = createContext<DeepLinkContextType>({
lastDeepLink: null,
});
export function DeepLinkProvider({ children }: { children: React.ReactNode }) {
const [lastDeepLink, setLastDeepLink] = useState<
(DeepLinkData & { timestamp: number }) | null
>(null);
useEffect(() => {
const ipcClient = IpcClient.getInstance();
const unsubscribe = ipcClient.onDeepLinkReceived((data) => {
// Update with timestamp to ensure state change even if same type comes twice
setLastDeepLink({ ...data, timestamp: Date.now() });
});
return unsubscribe;
}, []);
return (
<DeepLinkContext.Provider value={{ lastDeepLink }}>
{children}
</DeepLinkContext.Provider>
);
}
export const useDeepLink = () => useContext(DeepLinkContext);