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