mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 16:02:17 +00:00
fix: only restart software phone when mode actually changes
Compare previous phone_mode/data_strategy before RestartVoWiFi so a repeat enable does not bounce an already-running stack. Cellular enable no longer claims the device entered airplane mode.
This commit is contained in:
1 parent
99e278a154
commit
f45264f8ce
2 files changed
+17
-2
No files matched your search
@@ -94,7 +94,16 @@ func (s *Server) handleDeviceVoWiFiPatch(c *gin.Context) {
|
||||
}
|
||||
// 同步 w.Config,使概览即时切到 VoWiFi 模式面板(EnableVoWiFi 不碰 Config)。
|
||||
w := s.pool.GetWorker(deviceID)
|
||||
prevMode, prevStrategy := "", ""
|
||||
if w != nil {
|
||||
prevMode = w.Config.PhoneMode
|
||||
if prevMode == "" {
|
||||
prevMode = "wifi"
|
||||
}
|
||||
prevStrategy = w.Config.DataStrategy
|
||||
if prevStrategy == "" {
|
||||
prevStrategy = "on_demand"
|
||||
}
|
||||
if req.Mode != nil {
|
||||
w.Config.PhoneMode = mode
|
||||
}
|
||||
@@ -103,7 +112,9 @@ func (s *Server) handleDeviceVoWiFiPatch(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
s.pool.SetWorkerVoWiFiPolicy(deviceID, true)
|
||||
if s.pool.IsVoWiFiActive(deviceID) && (req.Mode != nil || req.DataStrategy != nil) {
|
||||
modeChanged := req.Mode != nil && mode != prevMode
|
||||
strategyChanged := req.DataStrategy != nil && strategy != prevStrategy
|
||||
if s.pool.IsVoWiFiActive(deviceID) && (modeChanged || strategyChanged) {
|
||||
if err := s.pool.RestartVoWiFi(deviceID); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"status": "error",
|
||||
|
||||
@@ -1269,9 +1269,13 @@ func (s *Server) handleVoWiFiEnable(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
message := "VoWiFi 已启用,设备已进入飞行模式"
|
||||
if worker := s.pool.GetWorker(deviceID); worker != nil && worker.Config.PhoneMode == "cellular" {
|
||||
message = "蜂窝数据通话已启用"
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"message": "VoWiFi 已启用,设备已进入飞行模式",
|
||||
"message": message,
|
||||
"device": deviceID,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user