mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-25 01:41:40 +00:00
[PhotonClient] Vite and Typescript complete refactor (#884)
This commit is contained in:
111
photon-client/src/stores/settings/GeneralSettingsStore.ts
Normal file
111
photon-client/src/stores/settings/GeneralSettingsStore.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type {
|
||||
GeneralSettings,
|
||||
LightingSettings,
|
||||
MetricData,
|
||||
NetworkSettings
|
||||
} from "@/types/SettingTypes";
|
||||
import { NetworkConnectionType } from "@/types/SettingTypes";
|
||||
import { useStateStore } from "@/stores/StateStore";
|
||||
import axios from "axios";
|
||||
import type { WebsocketSettingsUpdate } from "@/types/WebsocketDataTypes";
|
||||
|
||||
interface GeneralSettingsStore {
|
||||
general: GeneralSettings,
|
||||
network: NetworkSettings,
|
||||
lighting: LightingSettings,
|
||||
metrics: MetricData
|
||||
}
|
||||
|
||||
export const useSettingsStore = defineStore("settings", {
|
||||
state: (): GeneralSettingsStore => ({
|
||||
general: {
|
||||
version: undefined,
|
||||
gpuAcceleration: undefined,
|
||||
hardwareModel: undefined,
|
||||
hardwarePlatform: undefined
|
||||
},
|
||||
network: {
|
||||
ntServerAddress: "",
|
||||
shouldMange: true,
|
||||
connectionType: NetworkConnectionType.DHCP,
|
||||
staticIp: "",
|
||||
hostname: "photonvision",
|
||||
runNTServer: false
|
||||
},
|
||||
lighting: {
|
||||
supported: true,
|
||||
brightness: 0
|
||||
},
|
||||
metrics: {
|
||||
cpuTemp: undefined,
|
||||
cpuUtil: undefined,
|
||||
cpuMem: undefined,
|
||||
gpuMem: undefined,
|
||||
ramUtil: undefined,
|
||||
gpuMemUtil: undefined,
|
||||
cpuThr: undefined,
|
||||
cpuUptime: undefined,
|
||||
diskUtilPct: undefined
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
gpuAccelerationEnabled(): boolean {
|
||||
return this.general.gpuAcceleration !== undefined;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
requestMetricsUpdate() {
|
||||
return axios.post("/utils/publishMetrics");
|
||||
},
|
||||
updateMetricsFromWebsocket(data: Required<MetricData>) {
|
||||
this.metrics = {
|
||||
cpuTemp: data.cpuTemp || undefined,
|
||||
cpuUtil: data.cpuUtil || undefined,
|
||||
cpuMem: data.cpuMem || undefined,
|
||||
gpuMem: data.gpuMem || undefined,
|
||||
ramUtil: data.ramUtil || undefined,
|
||||
gpuMemUtil: data.gpuMemUtil || undefined,
|
||||
cpuThr: data.cpuThr || undefined,
|
||||
cpuUptime: data.cpuUptime || undefined,
|
||||
diskUtilPct: data.diskUtilPct || undefined
|
||||
};
|
||||
},
|
||||
updateGeneralSettingsFromWebsocket(data: WebsocketSettingsUpdate) {
|
||||
this.general = {
|
||||
version: data.general.version || undefined,
|
||||
hardwareModel: data.general.hardwareModel || undefined,
|
||||
hardwarePlatform: data.general.hardwarePlatform || undefined,
|
||||
gpuAcceleration: data.general.gpuAcceleration || undefined
|
||||
};
|
||||
this.lighting = data.lighting;
|
||||
this.network = data.networkSettings;
|
||||
},
|
||||
saveGeneralSettings() {
|
||||
const payload: Required<NetworkSettings> = {
|
||||
connectionType: this.network.connectionType,
|
||||
hostname: this.network.hostname,
|
||||
networkManagerIface: this.network.networkManagerIface || "",
|
||||
ntServerAddress: this.network.ntServerAddress,
|
||||
physicalInterface: this.network.physicalInterface || "",
|
||||
runNTServer: this.network.runNTServer,
|
||||
setDHCPcommand: this.network.setDHCPcommand || "",
|
||||
setStaticCommand: this.network.setStaticCommand || "",
|
||||
shouldMange: this.network.shouldMange,
|
||||
staticIp: this.network.staticIp
|
||||
};
|
||||
return axios.post("/settings/general", payload);
|
||||
},
|
||||
/**
|
||||
* Modify the brightness of the LEDs.
|
||||
*
|
||||
* @param brightness brightness to set [0, 100]
|
||||
*/
|
||||
changeLEDBrightness(brightness: number) {
|
||||
const payload = {
|
||||
enabledLEDPercentage: brightness
|
||||
};
|
||||
useStateStore().websocket?.send(payload, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user