Added deeplinks, added qr code login, added settings, other stuff

This commit is contained in:
Alois 2026-04-10 19:44:08 +02:00
commit 8ff8bd9528
32 changed files with 917 additions and 78 deletions

View 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>
);
}

View file

@ -0,0 +1,38 @@
import {
scan,
Format,
requestPermissions,
} from "@tauri-apps/plugin-barcode-scanner";
import { Button } from "@tensamin/ui/cmp/button";
import { toast } from "@tensamin/shared/log";
export default function QrCodeScanner({
onData,
}: {
onData: (data: string) => void;
}) {
return (
<Button
onClick={() => {
requestPermissions()
.catch((err) => {
toast("error", err.message);
})
.then(() =>
scan({ windowed: false, formats: [Format.QRCode] })
.catch((err) => {
toast("error", err.message);
})
.then((data) => {
if (data) {
onData(data.content);
}
}),
);
}}
>
Open QR Code Scanner
</Button>
);
}