mirror of https://github.com/jetkvm/kvm.git
now storing name config settings in store
removed extra LoadConfig calls
This commit is contained in:
parent
ee1c8eb424
commit
9cc18ee9ff
|
@ -300,12 +300,10 @@ type SSHKeyState struct {
|
|||
}
|
||||
|
||||
func rpcGetNameConfig() (NameConfig, error) {
|
||||
LoadConfig()
|
||||
return config.NameConfig, nil
|
||||
}
|
||||
|
||||
func rpcSetNameConfig(deviceName string) (NameConfig, error) {
|
||||
LoadConfig()
|
||||
config.NameConfig = NameConfig{
|
||||
Name: deviceName,
|
||||
DNS: slug.Make(deviceName) + ".local",
|
||||
|
|
|
@ -131,7 +131,6 @@ func startMDNS() error {
|
|||
}
|
||||
|
||||
// Start a new server
|
||||
LoadConfig()
|
||||
fmt.Printf("Starting mDNS server on %v\n", config.NameConfig.DNS)
|
||||
addr4, err := net.ResolveUDPAddr("udp4", mdns.DefaultAddressIPv4)
|
||||
if err != nil {
|
||||
|
|
|
@ -278,6 +278,9 @@ interface SettingsState {
|
|||
|
||||
backlightSettings: BacklightSettings;
|
||||
setBacklightSettings: (settings: BacklightSettings) => void;
|
||||
|
||||
nameConfig: NameConfig;
|
||||
setNameConfig: (config: NameConfig) => void;
|
||||
}
|
||||
|
||||
export const useSettingsStore = create(
|
||||
|
@ -303,6 +306,12 @@ export const useSettingsStore = create(
|
|||
},
|
||||
setBacklightSettings: (settings: BacklightSettings) =>
|
||||
set({ backlightSettings: settings }),
|
||||
|
||||
nameConfig: {
|
||||
name: "JetKVM",
|
||||
dns: "jetkvm.local"
|
||||
},
|
||||
setNameConfig: (config: NameConfig) => set({ nameConfig: config }),
|
||||
}),
|
||||
{
|
||||
name: "settings",
|
||||
|
|
|
@ -4,7 +4,7 @@ import { InputFieldWithLabel } from "@components/InputField";
|
|||
import { SettingsPageHeader } from "../components/SettingsPageheader";
|
||||
import { SelectMenuBasic } from "../components/SelectMenuBasic";
|
||||
import { SettingsItem } from "./devices.$id.settings";
|
||||
import { NameConfig } from "@/hooks/stores";
|
||||
import {NameConfig, useSettingsStore} from "@/hooks/stores";
|
||||
import { useJsonRpc } from "@/hooks/useJsonRpc";
|
||||
import notifications from "@/notifications";
|
||||
|
||||
|
@ -12,18 +12,11 @@ export default function SettingsAppearanceRoute() {
|
|||
const [currentTheme, setCurrentTheme] = useState(() => {
|
||||
return localStorage.theme || "system";
|
||||
});
|
||||
const [nameConfig, setNameConfig] = useState<NameConfig>({
|
||||
name: '',
|
||||
dns: '',
|
||||
});
|
||||
const [send] = useJsonRpc();
|
||||
const [name, setName] = useState("");
|
||||
|
||||
send("getNameConfig", {}, resp => {
|
||||
if ("error" in resp) return;
|
||||
const results = resp.result as NameConfig;
|
||||
setNameConfig(results);
|
||||
document.title = results.name;
|
||||
});
|
||||
const nameConfigSettings = useSettingsStore(state => state.nameConfig);
|
||||
const setNameConfigSettings = useSettingsStore(state => state.setNameConfig);
|
||||
|
||||
const handleThemeChange = useCallback((value: string) => {
|
||||
const root = document.documentElement;
|
||||
|
@ -43,24 +36,24 @@ export default function SettingsAppearanceRoute() {
|
|||
}
|
||||
}, []);
|
||||
|
||||
const handleDeviceNameChange = (deviceName: string) => {
|
||||
setNameConfig({... nameConfig, name: deviceName})
|
||||
const handleNameChange = (value: string) => {
|
||||
setName(value);
|
||||
};
|
||||
|
||||
const handleUpdateNameConfig = useCallback(() => {
|
||||
send("setNameConfig", { deviceName: nameConfig.name }, resp => {
|
||||
const handleNameSave = useCallback(() => {
|
||||
send("setNameConfig", { deviceName: name }, resp => {
|
||||
if ("error" in resp) {
|
||||
notifications.error(
|
||||
`Failed to set name config: ${resp.error.data || "Unknown error"}`,
|
||||
);
|
||||
notifications.error(`Failed to set name config: ${resp.error.data || "Unknown error"}`);
|
||||
return;
|
||||
}
|
||||
const rNameConfig = resp.result as NameConfig;
|
||||
setNameConfig(rNameConfig);
|
||||
document.title = rNameConfig.name;
|
||||
notifications.success(`Device name set to "${rNameConfig.name}" successfully.\nDNS Name set to "${rNameConfig.dns}"`);
|
||||
const nameConfig = resp.result as NameConfig;
|
||||
setNameConfigSettings(nameConfig);
|
||||
document.title = nameConfig.name;
|
||||
notifications.success(
|
||||
`Device name set to "${nameConfig.name}" successfully.\nDNS Name set to "${nameConfig.dns}"`
|
||||
);
|
||||
});
|
||||
}, [send, nameConfig]);
|
||||
}, [send, name, setNameConfigSettings]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
|
@ -89,9 +82,9 @@ export default function SettingsAppearanceRoute() {
|
|||
required
|
||||
label=""
|
||||
placeholder="Enter Device Name"
|
||||
description={`DNS: ${nameConfig.dns}`}
|
||||
defaultValue={nameConfig.name}
|
||||
onChange={e => handleDeviceNameChange(e.target.value)}
|
||||
description={`DNS: ${nameConfigSettings.dns}`}
|
||||
defaultValue={nameConfigSettings.name}
|
||||
onChange={e => handleNameChange(e.target.value)}
|
||||
/>
|
||||
</SettingsItem>
|
||||
<div className="flex items-center gap-x-2">
|
||||
|
@ -99,7 +92,7 @@ export default function SettingsAppearanceRoute() {
|
|||
size="SM"
|
||||
theme="primary"
|
||||
text="Update Device Name"
|
||||
onClick={handleUpdateNameConfig}
|
||||
onClick={() => {handleNameSave()}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
useMountMediaStore,
|
||||
User,
|
||||
useRTCStore,
|
||||
useSettingsStore,
|
||||
useUiStore,
|
||||
useUpdateStore,
|
||||
useVideoStore,
|
||||
|
@ -129,6 +130,7 @@ export default function KvmIdRoute() {
|
|||
const setRpcDataChannel = useRTCStore(state => state.setRpcDataChannel);
|
||||
const setTransceiver = useRTCStore(state => state.setTransceiver);
|
||||
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { otaState, setOtaState, setModalView } = useUpdateStore();
|
||||
|
||||
|
@ -378,14 +380,17 @@ export default function KvmIdRoute() {
|
|||
});
|
||||
}, [rpcDataChannel?.readyState, send, setHdmiState]);
|
||||
|
||||
const setNameConfig = useSettingsStore(state => state.setNameConfig);
|
||||
|
||||
useEffect(() => {
|
||||
send("getNameConfig", {}, resp => {
|
||||
if ("error" in resp) return;
|
||||
const results = resp.result as NameConfig;
|
||||
console.log(`getNameConfig# name: ${results.name}, dns: ${results.dns}`);
|
||||
setNameConfig(results)
|
||||
document.title = results.name;
|
||||
});
|
||||
}, [send]);
|
||||
|
||||
}, [send, setNameConfig])
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
|
|
Loading…
Reference in New Issue