(feat): update licenses (feat): update livekit logging (feat): add basic grid layout (fix): remove deeplink log message
71 lines
1.4 KiB
TypeScript
71 lines
1.4 KiB
TypeScript
import {
|
|
createContext,
|
|
useContext,
|
|
useEffect,
|
|
useState,
|
|
type ReactNode,
|
|
} from "react";
|
|
import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link";
|
|
import { isTauri } from "@tauri-apps/api/core";
|
|
|
|
type DeeplinkContextValue = {
|
|
deeplinks: readonly string[];
|
|
};
|
|
|
|
export const deeplinkContext = createContext<DeeplinkContextValue | undefined>(
|
|
undefined,
|
|
);
|
|
|
|
export function useDeeplinks() {
|
|
const value = useContext(deeplinkContext);
|
|
if (!value) {
|
|
throw new Error("useDeeplinks must be used within DeeplinkProvider");
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
export default function DeeplinkProvider({
|
|
children,
|
|
}: {
|
|
children: ReactNode;
|
|
}) {
|
|
const [deeplinks, setDeeplinks] = useState<string[]>([]);
|
|
const isTauriEnv = isTauri();
|
|
|
|
useEffect(() => {
|
|
if (!isTauriEnv) return;
|
|
|
|
let mounted = true;
|
|
let unlisten: (() => void) | undefined;
|
|
|
|
getCurrent().then((links) => {
|
|
if (mounted && links) {
|
|
setDeeplinks((prev) => [...prev, ...links]);
|
|
}
|
|
});
|
|
|
|
onOpenUrl((links) => {
|
|
if (mounted) {
|
|
setDeeplinks((prev) => [...prev, ...links]);
|
|
}
|
|
}).then((fn) => {
|
|
unlisten = fn;
|
|
});
|
|
|
|
return () => {
|
|
mounted = false;
|
|
unlisten?.();
|
|
};
|
|
}, [isTauriEnv]);
|
|
|
|
return (
|
|
<deeplinkContext.Provider
|
|
value={{
|
|
deeplinks,
|
|
}}
|
|
>
|
|
{children}
|
|
</deeplinkContext.Provider>
|
|
);
|
|
}
|