Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/set jetkvm name #196

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
saving device name to settings store
added UI elements
  • Loading branch information
jackstown committed Feb 24, 2025
commit 86addd92c781087047f17b7ec7970c9b8ee975c7
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
EdidString string `json:"hdmi_edid_string"`
ActiveExtension string `json:"active_extension"`
DeviceName string `json:"device_name"`
DisplayMaxBrightness int `json:"display_max_brightness"`
DisplayDimAfterSec int `json:"display_dim_after_sec"`
DisplayOffAfterSec int `json:"display_off_after_sec"`
Expand All @@ -36,9 +37,11 @@ var defaultConfig = &Config{
CloudURL: "https://api.jetkvm.com",
AutoUpdateEnabled: true, // Set a default value
ActiveExtension: "",
DeviceName: "JetKVM",
DisplayMaxBrightness: 64,
DisplayDimAfterSec: 120, // 2 minutes
DisplayOffAfterSec: 1800, // 30 minutes

}

var (
Expand Down
20 changes: 20 additions & 0 deletions jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ type SSHKeyState struct {
SSHKey string `json:"sshKey"`
}

func rpcGetDeviceName() (string, error) {
LoadConfig()
return config.DeviceName, nil
}

func rpcSetDeviceName(deviceName string) error {
LoadConfig()
config.DeviceName = deviceName

err := SaveConfig()
if err != nil {
return fmt.Errorf("failed to save device name: %w", err)
}

log.Printf("[jsonrpc.go:rpcSetDeviceName] device name set to %s", deviceName)
return nil
}

func rpcGetDevModeState() (DevModeState, error) {
devModeEnabled := false
if _, err := os.Stat(devModeFile); err != nil {
Expand Down Expand Up @@ -755,6 +773,8 @@ var rpcHandlers = map[string]RPCHandler{
"setDevChannelState": {Func: rpcSetDevChannelState, Params: []string{"enabled"}},
"getUpdateStatus": {Func: rpcGetUpdateStatus},
"tryUpdate": {Func: rpcTryUpdate},
"getDeviceName": {Func: rpcGetDeviceName},
"setDeviceName": {Func: rpcSetDeviceName, Params: []string{"deviceName"}},
"getDevModeState": {Func: rpcGetDevModeState},
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
"getSSHKeyState": {Func: rpcGetSSHKeyState},
Expand Down
30 changes: 30 additions & 0 deletions ui/src/components/sidebar/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PointingFinger from "@/assets/pointing-finger.svg";
import MouseIcon from "@/assets/mouse-icon.svg";
import { useJsonRpc } from "@/hooks/useJsonRpc";
import { SelectMenuBasic } from "../SelectMenuBasic";
import { InputFieldWithLabel } from "@components/InputField";
import { SystemVersionInfo } from "@components/UpdateDialog";
import notifications from "@/notifications";
import api from "../../api";
Expand All @@ -28,6 +29,7 @@ import { useRevalidator } from "react-router-dom";
import { ShieldCheckIcon } from "@heroicons/react/20/solid";
import { CLOUD_APP, SIGNAL_API } from "@/ui.config";


export function SettingsItem({
title,
description,
Expand Down Expand Up @@ -97,6 +99,7 @@ export default function SettingsSidebar() {
const hideCursor = useSettingsStore(state => state.isCursorHidden);
const setHideCursor = useSettingsStore(state => state.setCursorVisibility);
const setDeveloperMode = useSettingsStore(state => state.setDeveloperMode);
const setDeviceName = useSettingsStore(state => state.setDeviceName);
const setBacklightSettings = useSettingsStore(state => state.setBacklightSettings);

const [currentVersions, setCurrentVersions] = useState<{
Expand Down Expand Up @@ -173,6 +176,18 @@ export default function SettingsSidebar() {
});
};

const handleDeviceNameChange = (deviceName: string) => {
send("setDeviceName", { deviceName }, resp => {
if ("error" in resp) {
notifications.error(
`Failed to set device name: ${resp.error.data || "Unknown error"}`,
);
return;
}
setDeviceName(deviceName);
});
};

const handleDevChannelChange = (enabled: boolean) => {
send("setDevChannelState", { enabled }, resp => {
if ("error" in resp) {
Expand Down Expand Up @@ -339,6 +354,12 @@ export default function SettingsSidebar() {
setBacklightSettings(result);
})

send("getDeviceName", {}, resp => {
if ("error" in resp) return;
const result = resp.result as { deviceName: string };
setDeviceName(result.deviceName);
});

send("getDevModeState", {}, resp => {
if ("error" in resp) return;
const result = resp.result as { enabled: boolean };
Expand Down Expand Up @@ -833,6 +854,15 @@ export default function SettingsSidebar() {
}}
/>
</SettingsItem>
<SettingsItem title="Device Name" description="Set your device name">
<InputFieldWithLabel
required
label="Device Name"
placeholder="Enter Device Name"
defaultValue={settings.deviceName}
onChange={e => handleDeviceNameChange(e.target.value)}
/>
</SettingsItem>
<div className="h-[1px] w-full bg-slate-800/10 dark:bg-slate-300/20" />
<div className="pb-2 space-y-4">
<SectionHeader
Expand Down
6 changes: 6 additions & 0 deletions ui/src/hooks/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ interface SettingsState {
developerMode: boolean;
setDeveloperMode: (enabled: boolean) => void;

deviceName: string;
setDeviceName: (deviceName: string) => void;

backlightSettings: BacklightSettings;
setBacklightSettings: (settings: BacklightSettings) => void;
}
Expand All @@ -298,6 +301,9 @@ export const useSettingsStore = create(
developerMode: false,
setDeveloperMode: enabled => set({ developerMode: enabled }),

deviceName: "JetKVM",
setDeviceName: deviceName => set({ deviceName: deviceName }),

backlightSettings: {
max_brightness: 100,
dim_after: 10000,
Expand Down