Handle connecting/disconnecting states
This commit is contained in:
parent
1477d909b0
commit
02b93a3ef0
6 changed files with 176 additions and 41 deletions
|
|
@ -31,12 +31,13 @@ type App struct {
|
|||
func New(assets embed.FS) *App {
|
||||
return &App{
|
||||
Status: models.SystemStatus{
|
||||
Connected: false,
|
||||
ConnectedSSID: "",
|
||||
HotspotStatus: nil,
|
||||
ConnectedCount: 0,
|
||||
DataUsage: 0.0,
|
||||
Uptime: 0,
|
||||
Connected: false,
|
||||
ConnectionState: "disconnected",
|
||||
ConnectedSSID: "",
|
||||
HotspotStatus: nil,
|
||||
ConnectedCount: 0,
|
||||
DataUsage: 0.0,
|
||||
Uptime: 0,
|
||||
},
|
||||
StartTime: time.Now(),
|
||||
Assets: assets,
|
||||
|
|
@ -136,6 +137,7 @@ func (a *App) periodicStatusUpdate() {
|
|||
for range ticker.C {
|
||||
a.StatusMutex.Lock()
|
||||
a.Status.Connected = wifi.IsConnected()
|
||||
a.Status.ConnectionState = wifi.GetConnectionState()
|
||||
a.Status.ConnectedSSID = wifi.GetConnectedSSID()
|
||||
a.Status.Uptime = getSystemUptime()
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ type HotspotStatus struct {
|
|||
// SystemStatus represents overall system status
|
||||
type SystemStatus struct {
|
||||
Connected bool `json:"connected"`
|
||||
ConnectionState string `json:"connectionState"` // Connection state: connected, disconnected, connecting, disconnecting, roaming
|
||||
ConnectedSSID string `json:"connectedSSID"`
|
||||
HotspotStatus *HotspotStatus `json:"hotspotStatus,omitempty"` // Detailed hotspot status
|
||||
ConnectedCount int `json:"connectedCount"`
|
||||
|
|
|
|||
|
|
@ -241,6 +241,15 @@ func GetConnectedSSID() string {
|
|||
return props.Name
|
||||
}
|
||||
|
||||
// GetConnectionState returns the current WiFi connection state
|
||||
func GetConnectionState() string {
|
||||
state, err := station.GetState()
|
||||
if err != nil {
|
||||
return string(iwd.StateDisconnected)
|
||||
}
|
||||
return string(state)
|
||||
}
|
||||
|
||||
// StartEventMonitoring initializes D-Bus signal monitoring and WebSocket broadcasting
|
||||
func StartEventMonitoring() error {
|
||||
// Initialize broadcaster
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue