142 lines
3.0 KiB
Go
142 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/charmbracelet/huh"
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
// --- [상수 및 Enum] ---
|
|
type AppState int
|
|
|
|
const (
|
|
StateLogin AppState = iota
|
|
StateDashboard
|
|
StateTerminal
|
|
StateSettings
|
|
)
|
|
|
|
type SettingSubState int
|
|
|
|
const (
|
|
SubMenu SettingSubState = iota
|
|
SubWifiScanList
|
|
SubWifiConnect
|
|
SubIPConfig
|
|
SubAPMode
|
|
SubSystem
|
|
SubSafety
|
|
SubAccount
|
|
)
|
|
|
|
// --- [데이터 구조체] ---
|
|
type ConnectionDetails struct {
|
|
IP, Username, Password, Token string
|
|
}
|
|
|
|
type PowerMetrics struct {
|
|
Voltage, Current, Power float64
|
|
}
|
|
|
|
type WifiInfo struct {
|
|
SSID string
|
|
RSSI int
|
|
}
|
|
|
|
type SwitchInfo struct {
|
|
MainOn, UsbOn bool
|
|
}
|
|
|
|
type DeviceStatus struct {
|
|
Vin PowerMetrics
|
|
Main PowerMetrics
|
|
Usb PowerMetrics
|
|
Wifi WifiInfo
|
|
Sw SwitchInfo
|
|
}
|
|
|
|
type InitApiResponse struct {
|
|
Load12vOn bool `json:"load_12v_on"`
|
|
Load5vOn bool `json:"load_5v_on"`
|
|
}
|
|
|
|
type WifiAP struct {
|
|
SSID string `json:"ssid"`
|
|
RSSI int `json:"rssi"`
|
|
AuthMode string `json:"authmode"`
|
|
}
|
|
|
|
type SettingsPayload struct {
|
|
Connected bool `json:"connected,omitempty"`
|
|
CurSSID string `json:"ssid,omitempty"`
|
|
CurIP struct {
|
|
IP string `json:"ip"`
|
|
Gateway string `json:"gateway"`
|
|
Subnet string `json:"subnet"`
|
|
DNS1 string `json:"dns1"`
|
|
DNS2 string `json:"dns2"`
|
|
} `json:"ip,omitempty"`
|
|
|
|
WifiSSID string `json:"ssid,omitempty"`
|
|
WifiPass string `json:"password,omitempty"`
|
|
|
|
NetType string `json:"net_type,omitempty"`
|
|
IP string `json:"ip,omitempty"`
|
|
Gateway string `json:"gateway,omitempty"`
|
|
Subnet string `json:"subnet,omitempty"`
|
|
DNS1 string `json:"dns1,omitempty"`
|
|
DNS2 string `json:"dns2,omitempty"`
|
|
|
|
Mode string `json:"mode,omitempty"`
|
|
APSSID string `json:"ap_ssid,omitempty"`
|
|
APPass string `json:"ap_password,omitempty"`
|
|
|
|
Baudrate string `json:"baudrate,omitempty"`
|
|
Period string `json:"period,omitempty"`
|
|
|
|
VinLimit float64 `json:"vin_current_limit,omitempty"`
|
|
MainLimit float64 `json:"main_current_limit,omitempty"`
|
|
UsbLimit float64 `json:"usb_current_limit,omitempty"`
|
|
|
|
NewUser string `json:"new_username,omitempty"`
|
|
NewPass string `json:"new_password,omitempty"`
|
|
}
|
|
|
|
// --- [메인 모델] ---
|
|
type model struct {
|
|
state AppState
|
|
connDetails *ConnectionDetails
|
|
formData *ConnectionDetails
|
|
|
|
status DeviceStatus
|
|
width int
|
|
height int
|
|
|
|
// Settings State
|
|
settingSubState SettingSubState
|
|
menuSelection *string // [수정] 포인터로 변경 (메뉴 선택 버그 해결 핵심)
|
|
scanning bool // [추가] Wi-Fi 스캔 중 상태 표시
|
|
settingsData SettingsPayload
|
|
wifiScanList []WifiAP
|
|
|
|
// Forms
|
|
loginForm *huh.Form
|
|
settingsForm *huh.Form
|
|
|
|
err error
|
|
}
|
|
|
|
// --- [Tea Messages] ---
|
|
type TerminalFinishedMsg struct{}
|
|
type LoginSuccessMsg string
|
|
type InitStateMsg SwitchInfo
|
|
type SettingsFetchedMsg SettingsPayload
|
|
type ActionDoneMsg struct{}
|
|
type WifiScanListMsg []WifiAP
|
|
|
|
type WsPartialMsg struct {
|
|
Vin, Main, Usb *PowerMetrics
|
|
Wifi *WifiInfo
|
|
Sw *SwitchInfo
|
|
Conn *websocket.Conn
|
|
}
|