feat: Windows compatibility (#836)

* feat: win compatibility

* fix

* fix: uptime parse

* opt.: linux uptime accuracy

* fix: windows temperature fetching

* opt.

* opt.: powershell exec

* refactor: address PR review feedback and improve code quality

### Major Improvements:
- **Refactored Windows status parsing**: Broke down large `_getWindowsStatus` method into 13 smaller, focused helper methods for better maintainability and readability
- **Extracted system detection logic**: Created dedicated `SystemDetector` helper class to separate OS detection concerns from ServerProvider
- **Improved concurrency handling**: Implemented proper synchronization for server updates using Future-based locks to prevent race conditions

### Bug Fixes:
- **Fixed CPU percentage parsing**: Removed incorrect '*100' multiplication in BSD CPU parsing (values were already percentages)
- **Enhanced memory parsing**: Added validation and error handling to BSD memory fallback parsing with proper logging
- **Improved uptime parsing**: Added support for multiple Windows date formats and robust error handling with validation
- **Fixed division by zero**: Added safety checks in Swap.usedPercent getter

### Code Quality Enhancements:
- **Added comprehensive documentation**: Documented Windows CPU counter limitations and approach
- **Strengthened error handling**: Added detailed logging and validation throughout parsing methods
- **Improved robustness**: Enhanced BSD CPU parsing with percentage validation and warnings
- **Better separation of concerns**: Each parsing method now has single responsibility

### Files Changed:
- `lib/data/helper/system_detector.dart` (new): System detection helper
- `lib/data/model/server/cpu.dart`: Fixed percentage parsing and added validation
- `lib/data/model/server/memory.dart`: Enhanced fallback parsing and division-by-zero protection
- `lib/data/model/server/server_status_update_req.dart`: Refactored into 13 focused parsing methods
- `lib/data/provider/server.dart`: Improved synchronization and extracted system detection

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: parse & shell fn struct

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
lollipopkit🏳️‍⚧️
2025-08-08 16:56:36 +08:00
committed by GitHub
parent 46a12bc844
commit 3a615449e3
103 changed files with 9591 additions and 1906 deletions

View File

@@ -2,17 +2,17 @@
"@@locale": "zh_TW",
"aboutThanks": "感謝以下參與的各位。",
"acceptBeta": "接受測試版更新推送",
"addSystemPrivateKeyTip": "目前沒有任何私鑰,是否新增系統原有的 (~/.ssh/id_rsa)",
"addSystemPrivateKeyTip": "偵測到尚無私鑰,是否要加入系統預設的私鑰(~/.ssh/id_rsa",
"added2List": "已新增至任務清單",
"addr": "位址",
"alreadyLastDir": "已經是最上層目錄",
"authFailTip": "認證失敗,請檢查密碼/金鑰/主機/使用者等是否錯誤。",
"autoBackupConflict": "只能同時開啓一個自動備份",
"alreadyLastDir": "已是頂層目錄",
"authFailTip": "認證失敗,請檢查連線資訊是否正確",
"autoBackupConflict": "僅能啟用一項自動備份任務",
"autoConnect": "自動連線",
"autoRun": "自動執行",
"autoUpdateHomeWidget": "自動更新桌面小工具",
"backupTip": "匯出的資料可以使用密碼加密。 \n請妥善保管。",
"backupVersionNotMatch": "備份版本不相,無法還原",
"backupTip": "匯出的資料可透過密碼加密請妥善保管。",
"backupVersionNotMatch": "備份版本不相,無法還原",
"backupPassword": "備份密碼",
"backupPasswordTip": "設定密碼來加密備份檔案。留空則停用加密。",
"backupPasswordWrong": "備份密碼錯誤",
@@ -22,7 +22,7 @@
"backupPasswordRemoved": "備份密碼已移除",
"battery": "電池",
"bgRun": "背景執行",
"bgRunTip": "此開關代表程式會嘗試背景執行,具體能否在後臺執行取決於是否開啟了權限。 原生 Android 請關閉本 App 的“電池最佳化”,MIUI / HyperOS 請修改省電策略為“無限制。",
"bgRunTip": "此開關代表程式會嘗試背景執行,能否成功取決於系統權限。原生 Android 上,請關閉本應用的「電池最佳化」;在 MIUI / HyperOS 上,請將省電策略調整為「無限制。",
"closeAfterSave": "儲存後關閉",
"cmd": "指令",
"collapseUITip": "是否預設折疊 UI 中存在的長列表",
@@ -40,23 +40,23 @@
"decompress": "解壓縮",
"deleteServers": "大量刪除伺服器",
"desktopTerminalTip": "啟動 SSH 連線時用於打開終端機模擬器的指令。",
"dirEmpty": "請確保資料夾為空",
"disconnected": "連線中斷",
"dirEmpty": "請確保目錄為空",
"disconnected": "已中斷連線",
"disk": "磁碟",
"diskHealth": "磁碟健康",
"diskIgnorePath": "忽略的磁碟路徑",
"displayCpuIndex": "顯示 CPU 索引",
"dl2Local": "下載 {fileName} 到本地?",
"dockerEmptyRunningItems": "沒有正在執行的容器。\n這可能是因為\n- Docker 安裝使用者與 App 內配置的使用者名稱不同\n- 環境變數 DOCKER_HOST 沒有被正確讀取。你可以通過在終端機內執行 `echo $DOCKER_HOST` 來獲取。",
"dockerImagesFmt": "{count} 個映像檔",
"dockerNotInstalled": "Docker 未安裝",
"dockerImagesFmt": "{count} 個映像檔",
"dockerNotInstalled": "未安裝 Docker",
"dockerStatusRunningAndStoppedFmt": "{runningCount} 個正在執行, {stoppedCount} 個已停止",
"dockerStatusRunningFmt": "{count} 個容器正在執行",
"doubleColumnMode": "雙列模式",
"doubleColumnTip": "此選項僅開啟功能,實際是否能開啟還取決於設備的頻寬",
"doubleColumnTip": "此選項僅用於啟用此功能,是否生效取決於裝置寬度",
"editVirtKeys": "編輯虛擬按鍵",
"editor": "編輯器",
"editorHighlightTip": "目前的程式碼標記效能較為糟糕,可選擇關閉以改善。",
"editorHighlightTip": "程式碼高亮功能可能影響效能,可選擇關閉。",
"emulator": "模擬器",
"encode": "編碼",
"envVars": "環境變數",
@@ -73,7 +73,7 @@
"force": "強制",
"fullScreen": "全螢幕模式",
"fullScreenJitter": "全螢幕模式抖動",
"fullScreenJitterHelp": "防止烙印",
"fullScreenJitterHelp": "防止螢幕烙印",
"fullScreenTip": "當設備旋轉為橫向時,是否開啟全螢幕模式?此選項僅適用於伺服器分頁。",
"goBackQ": "返回?",
"goto": "前往",
@@ -81,17 +81,17 @@
"highlight": "程式碼標記",
"homeWidgetUrlConfig": "桌面小工具連結配置",
"host": "主機",
"httpFailedWithCode": "請求失敗, 狀態碼: {code}",
"httpFailedWithCode": "請求失敗狀態碼{code}",
"ignoreCert": "忽略憑證",
"image": "映像檔",
"imagesList": "映像檔列表",
"init": "初始化",
"inner": "內建",
"install": "安裝",
"installDockerWithUrl": "請先 https://docs.docker.com/engine/install docker",
"installDockerWithUrl": "請先前往 https://docs.docker.com/engine/install 安裝 Docker",
"invalid": "無效",
"jumpServer": "跳板伺服器",
"keepForeground": "請保持App處於前端!",
"keepForeground": "請App 保持在前景執行",
"keepStatusWhenErr": "保留上次的伺服器狀態",
"keepStatusWhenErrTip": "僅在執行腳本出錯時",
"keyAuth": "金鑰認證",
@@ -104,7 +104,7 @@
"manual": "手動",
"max": "最大",
"maxRetryCount": "伺服器嘗試重連次數",
"maxRetryCountEqual0": "無限重試",
"maxRetryCountEqual0": "無限重試",
"min": "最小",
"mission": "任務",
"more": "更多",
@@ -125,7 +125,7 @@
"onlyOneLine": "僅顯示為一行(可捲動)",
"onlyWhenCoreBiggerThan8": "僅當核心數大於 8 時生效",
"openLastPath": "打開上次的路徑",
"openLastPathTip": "不同的伺服器會有不同的記錄,且記錄的是退出時的路徑",
"openLastPathTip": "將為每台伺服器紀錄其最後存取路徑",
"parseContainerStatsTip": "Docker 解析消耗狀態較為緩慢",
"percentOfSize": "{size} 的 {percent}%",
"permission": "權限",
@@ -142,7 +142,7 @@
"prune": "修剪",
"pushToken": "消息推送 Token",
"pveIgnoreCertTip": "不建議啟用,請注意安全風險!如果您使用的是 PVE 的預設憑證,則需要啟用此選項。",
"pveLoginFailed": "登失敗。無法使用伺服器配置中的使用者名稱/密碼 Linux PAM 方式登錄。",
"pveLoginFailed": "登失敗。無法使用伺服器設定中的使用者名稱密碼透過 Linux PAM 方式認證。",
"pveVersionLow": "此功能目前處於測試階段,僅在 PVE 8+ 上進行過測試。請謹慎使用。",
"read": "讀取",
"reboot": "重開",
@@ -169,7 +169,7 @@
"sftpDlPrepare": "準備連線至伺服器...",
"sftpEditorTip": "如果為空, 使用App內建的檔案編輯器。如果有值, 則使用遠端伺服器的編輯器, 例如 `vim`(建議根據 `EDITOR` 自動獲取)。",
"sftpRmrDirSummary": "在 SFTP 中使用 `rm -r` 來刪除檔案夾",
"sftpSSHConnected": "SFTP 已連線...",
"sftpSSHConnected": "SFTP 已連線",
"sftpShowFoldersFirst": "資料夾顯示在前",
"showDistLogo": "顯示發行版 Logo",
"shutdown": "關機",
@@ -179,7 +179,7 @@
"specifyDev": "指定裝置",
"specifyDevTip": "例如網路流量統計預設是所有裝置,你可以在這裡指定特定的裝置。",
"speed": "速度",
"spentTime": "耗時: {time}",
"spentTime": "耗時{time}",
"sshTermHelp": "在終端機可捲動時,橫向拖動可以選中文字。點擊鍵盤按鈕可以開啟/關閉鍵盤。檔案圖示會打開目前路徑 SFTP。剪貼簿按鈕會在有選中文字時複製內容在未選中並且剪貼簿有內容時貼上內容到終端機。程式碼圖示會貼上程式碼片段到終端機並執行。",
"sshTip": "該功能目前處於測試階段。\n\n請在 {url} 回饋問題,或者加入我們開發。",
"sshVirtualKeyAutoOff": "虛擬按鍵自動切換",
@@ -213,7 +213,7 @@
"unknown": "未知",
"unkownConvertMode": "未知轉換模式",
"update": "更新",
"updateIntervalEqual0": "設定為 0,伺服器狀態不會自動更新。\n且不能計算CPU使用情況。",
"updateIntervalEqual0": "設定為 0 將不自動刷新伺服器狀態,\n也無法計算 CPU 使用。",
"updateServerStatusInterval": "伺服器狀態更新間隔",
"upload": "上傳",
"upsideDown": "上下交換",
@@ -233,7 +233,7 @@
"watchNotPaired": "沒有已配對的 Apple Watch",
"webdavSettingEmpty": "WebDav 設定項爲空",
"whenOpenApp": "當打開 App 時",
"wolTip": "在配置 WOL(網絡喚醒)後,每次連線伺服器都會先發送一次 WOL 請求",
"wolTip": "設定 WOL 後,每次連線伺服器時將自動發送喚醒請求",
"write": "寫入",
"writeScriptFailTip": "寫入腳本失敗,可能是沒有權限/目錄不存在等。",
"writeScriptTip": "連線到伺服器後,將會在 `~/.config/server_box` \n | `/tmp/server_box` 中寫入一個腳本來監測系統狀態。你可以審查腳本內容。"