import { type ReactNode, useEffect, useRef, useState } from "react"; import { useApp } from "~/hooks/useApp"; const SddmActionButton = (props: { icon: ReactNode; text: string; onClick?: () => void; }) => ( {props.icon} {props.text} ); const PASSWORD_LENGTH = 12; export const Sddm = () => { const { setState } = useApp(); const passwordInputRef = useRef(null); const [password, setPassword] = useState(0); const [showPassword, setShowPassword] = useState(false); const [now, setNow] = useState(new Date()); useEffect(() => { const interval = setInterval(() => { setNow(new Date()); }, 1000); return () => clearInterval(interval); }, []); useEffect(() => { if (password >= PASSWORD_LENGTH) { passwordInputRef.current?.blur(); return; } const timeout = setTimeout( () => { passwordInputRef.current?.focus(); const canType = password < 4 || password === PASSWORD_LENGTH - 1 || Math.random() > 0.15; setPassword(Math.max(0, password + (canType ? 1 : -1))); }, password === 0 ? 3000 : Math.random() * 250 + 100, ); return () => clearTimeout(timeout); }, [password]); return ( <> Welcome! {now.toLocaleTimeString("en-us", { hour: "2-digit", minute: "2-digit", })} {now.toLocaleDateString("en-us", { dateStyle: "long" })} 0 ? "no." : "" : "•".repeat(password) } placeholder="Password" spellCheck={false} maxLength={PASSWORD_LENGTH} /> setShowPassword((show) => !show)} /> Show Password setState("desktop")} className="w-full select-none rounded-full bg-neutral-800 p-2 hover:bg-zinc-800 disabled:cursor-default disabled:bg-white disabled:bg-opacity-30" > Login Session: Hyprland setState("suspend")} icon={ } text="Suspend" /> setState("reboot")} icon={ } text="Reboot" /> setState("off")} icon={ } text="Shutdown" /> > ); };
Welcome!
{now.toLocaleTimeString("en-us", { hour: "2-digit", minute: "2-digit", })}
{now.toLocaleDateString("en-us", { dateStyle: "long" })}
Show Password
Session: Hyprland