import { useEffect, useState } from "react"; import { UserGroupIcon, } from "@heroicons/react/16/solid"; import { useJsonRpc, JsonRpcResponse } from "@/hooks/useJsonRpc"; import { usePermissions } from "@/hooks/usePermissions"; import { Permission } from "@/types/permissions"; import { useSettingsStore } from "@/hooks/stores"; import { notify } from "@/notifications"; import Card from "@/components/Card"; import Checkbox from "@/components/Checkbox"; import { SettingsPageHeader } from "@/components/SettingsPageheader"; import { SettingsItem } from "@/components/SettingsItem"; export default function SessionsSettings() { const { send } = useJsonRpc(); const { hasPermission } = usePermissions(); const canModifySettings = hasPermission(Permission.SETTINGS_WRITE); const { requireSessionNickname, setRequireSessionNickname, requireSessionApproval, setRequireSessionApproval, maxRejectionAttempts, setMaxRejectionAttempts } = useSettingsStore(); const [reconnectGrace, setReconnectGrace] = useState(10); const [primaryTimeout, setPrimaryTimeout] = useState(300); const [privateKeystrokes, setPrivateKeystrokes] = useState(false); const [maxSessions, setMaxSessions] = useState(10); const [observerTimeout, setObserverTimeout] = useState(120); useEffect(() => { send("getSessionSettings", {}, (response: JsonRpcResponse) => { if ("error" in response) { console.error("Failed to get session settings:", response.error); } else { const settings = response.result as { requireApproval: boolean; requireNickname: boolean; reconnectGrace?: number; primaryTimeout?: number; privateKeystrokes?: boolean; maxRejectionAttempts?: number; maxSessions?: number; observerTimeout?: number; }; setRequireSessionApproval(settings.requireApproval); setRequireSessionNickname(settings.requireNickname); if (settings.reconnectGrace !== undefined) { setReconnectGrace(settings.reconnectGrace); } if (settings.primaryTimeout !== undefined) { setPrimaryTimeout(settings.primaryTimeout); } if (settings.privateKeystrokes !== undefined) { setPrivateKeystrokes(settings.privateKeystrokes); } if (settings.maxRejectionAttempts !== undefined) { setMaxRejectionAttempts(settings.maxRejectionAttempts); } if (settings.maxSessions !== undefined) { setMaxSessions(settings.maxSessions); } if (settings.observerTimeout !== undefined) { setObserverTimeout(settings.observerTimeout); } } }); }, [send, setRequireSessionApproval, setRequireSessionNickname, setMaxRejectionAttempts]); const updateSessionSettings = (updates: Partial<{ requireApproval: boolean; requireNickname: boolean; reconnectGrace: number; primaryTimeout: number; privateKeystrokes: boolean; maxRejectionAttempts: number; maxSessions: number; observerTimeout: number; }>) => { if (!canModifySettings) { notify.error("Only the primary session can change this setting"); return; } send("setSessionSettings", { settings: { requireApproval: requireSessionApproval, requireNickname: requireSessionNickname, reconnectGrace: reconnectGrace, primaryTimeout: primaryTimeout, privateKeystrokes: privateKeystrokes, maxRejectionAttempts: maxRejectionAttempts, maxSessions: maxSessions, observerTimeout: observerTimeout, ...updates } }, (response: JsonRpcResponse) => { if ("error" in response) { console.error("Failed to update session settings:", response.error); notify.error("Failed to update session settings"); } }); }; return (