Skip to content

Commit d12d362

Browse files
committed
style: 删除无用代码
1 parent c584e41 commit d12d362

File tree

2 files changed

+0
-151
lines changed

2 files changed

+0
-151
lines changed

battery_checker.go

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -52,153 +52,3 @@ func StartBatteryCheckByCmd() {
5252
}
5353
}()
5454
}
55-
56-
//// ResponseData 定义响应结构体
57-
//type ResponseData struct {
58-
// DeviceBatteryChargeStatus string `json:"device_battery_charge_status"`
59-
// DeviceBatteryLevelPercent string `json:"device_battery_level_percent"`
60-
//}
61-
//
62-
//type ResponsePayload struct {
63-
// Retcode int `json:"retcode"`
64-
// Data ResponseData `json:"data"`
65-
//}
66-
//
67-
//// StartBatteryCheck 启动电量检测任务
68-
//func StartBatteryCheck(cookie string, cookieManager *CookieManager) {
69-
// go func() {
70-
// for {
71-
// // 调用统一方法获取并解析电量状态
72-
// batteryLevel, isLow, err := fetchBatteryStatus(cookie, cookieManager)
73-
// if err != nil {
74-
// continue
75-
// }
76-
//
77-
// var interval = Yaml.BatteryCheckInterval
78-
// if isLow {
79-
// text := fmt.Sprintf("R106随身WiFi电量%d%%过低,请充电", batteryLevel)
80-
// slog.Warn(text)
81-
// DingDingNotify(text)
82-
// interval = 10 * time.Minute
83-
// } else {
84-
// interval = Yaml.BatteryCheckInterval
85-
// }
86-
// time.Sleep(interval)
87-
// }
88-
// }()
89-
//}
90-
//
91-
//// Deprecated
92-
//func sendPostRequest(url string, cookie string, body []byte) ([]byte, error) {
93-
// req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
94-
// if err != nil {
95-
// return nil, fmt.Errorf("failed to create HTTP request: %w", err)
96-
// }
97-
//
98-
// req.Header.Set("Content-Type", "application/json")
99-
// req.Header.Set("Cookie", cookie)
100-
//
101-
// client := &http.Client{}
102-
// resp, err := client.Do(req)
103-
// if err != nil {
104-
// return nil, fmt.Errorf("failed to send HTTP request: %w", err)
105-
// }
106-
// defer resp.Body.Close()
107-
//
108-
// respBody, err := ioutil.ReadAll(resp.Body)
109-
// if err != nil {
110-
// return nil, fmt.Errorf("failed to read response body: %w", err)
111-
// }
112-
//
113-
// return respBody, nil
114-
//}
115-
//
116-
//// Deprecated
117-
//// 解析响应数据
118-
//func parseResponse(body []byte) (ResponsePayload, error) {
119-
// var responsePayload ResponsePayload
120-
// err := json.Unmarshal(body, &responsePayload)
121-
// if err != nil {
122-
// return ResponsePayload{}, fmt.Errorf("failed to unmarshal response: %w", err)
123-
// }
124-
// return responsePayload, nil
125-
//}
126-
//
127-
//// Deprecated
128-
//// 检查电池状态是否低
129-
//func isBatteryLow(responsePayload ResponsePayload) (int, bool, error) {
130-
// if responsePayload.Retcode != 0 {
131-
// return -1, false, fmt.Errorf("error in response: retcode = %d", responsePayload.Retcode)
132-
// }
133-
//
134-
// chargeStatus := responsePayload.Data.DeviceBatteryChargeStatus
135-
// batteryLevel := responsePayload.Data.DeviceBatteryLevelPercent
136-
//
137-
// batteryLevelInt, err := strconv.Atoi(batteryLevel)
138-
// if err != nil {
139-
// return -1, false, fmt.Errorf("failed to parse battery level: %v", err)
140-
// }
141-
//
142-
// // 检查条件
143-
// if chargeStatus == "none" && batteryLevelInt <= Yaml.LowBatteryValue {
144-
// return batteryLevelInt, true, nil
145-
// }
146-
//
147-
// return batteryLevelInt, false, nil
148-
//}
149-
//
150-
//// StartBatteryStatusAPI 对外提供查询电量状态的API
151-
//func StartBatteryStatusAPI(cookie string, cookieManager *CookieManager) {
152-
// http.HandleFunc("/api/battery-status", func(w http.ResponseWriter, r *http.Request) {
153-
// if r.Method != http.MethodGet {
154-
// http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
155-
// return
156-
// }
157-
// batteryLevel, _, err := fetchBatteryStatus(cookie, cookieManager)
158-
// if err != nil {
159-
// return
160-
// }
161-
// w.Header().Set("Content-Type", "text/plain")
162-
// fmt.Fprintf(w, "%d", batteryLevel)
163-
// })
164-
// http.ListenAndServe(":8686", nil)
165-
//}
166-
//
167-
//// Deprecated
168-
//// fetchBatteryStatus 获取并解析电量状态数据
169-
//func fetchBatteryStatus(cookie string, cookieManager *CookieManager) (int, bool, error) {
170-
// body := []byte(`{
171-
// "keys": [
172-
// "device_battery_charge_status",
173-
// "device_battery_level_percent"
174-
// ]
175-
// }`)
176-
// respBody, err := sendPostRequest(Yaml.GetMgdbParamsURL, cookie, body)
177-
//
178-
// // 检查响应是否有效
179-
// if !json.Valid(respBody) {
180-
// time.Sleep(5 * time.Second)
181-
// cookieTmp := cookie
182-
// cookie, _ = cookieManager.Load()
183-
// slog.Warnf("电量检测,cookie失效,%s,尝试从本地文件加载Cookie:%s", cookieTmp, cookie)
184-
// // 重新发送请求
185-
// respBody, _ = sendPostRequest(Yaml.GetMgdbParamsURL, cookie, body)
186-
// }
187-
// if err != nil {
188-
// return -1, false, err
189-
// }
190-
//
191-
// // 解析并校验响应
192-
// responsePayload, err := parseResponse(respBody)
193-
// if err != nil {
194-
// return -1, false, err
195-
// }
196-
//
197-
// // 检查电量状态
198-
// batteryLevel, isLow, err := isBatteryLow(responsePayload)
199-
// if err != nil {
200-
// return -1, false, err
201-
// }
202-
//
203-
// return batteryLevel, isLow, nil
204-
//}

script/r106-enhance-monitor.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ while true; do
2323
$PROGRAM >/dev/null 2>&1 &
2424
PROGRAM_PID=$!
2525
echo "$(date): $PROGRAM程序没有在运行,开始启动(PID: $PROGRAM_PID)..." >>"$LOG_FILE"
26-
# 启动程序
2726
fi
2827

2928
# 检查日志文件大小

0 commit comments

Comments
 (0)