Added deeplinks, added qr code login, added settings, other stuff
This commit is contained in:
parent
462fc19591
commit
8ff8bd9528
32 changed files with 917 additions and 78 deletions
71
apps/tauri/src/deeplinkHandler.tsx
Normal file
71
apps/tauri/src/deeplinkHandler.tsx
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link";
|
||||
|
||||
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[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
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?.();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(deeplinks);
|
||||
}, [deeplinks]);
|
||||
|
||||
return (
|
||||
<deeplinkContext.Provider
|
||||
value={{
|
||||
deeplinks,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</deeplinkContext.Provider>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue