fix(update): 优化更新逻辑,添加错误提示并清理冗余代码
移除所有脚本文件的头部注释模板 删除installer.lua中未使用的splitCsv函数 重构静默更新逻辑,改用loadfile替代os.run以正确捕获执行错误 添加更新错误追踪机制,在界面版本指示器处显示失败提示 修复更新成功的判断条件
This commit is contained in:
@@ -128,9 +128,16 @@ local function setLastUpdateVersion(v)
|
||||
end
|
||||
|
||||
local function runSilentGateUpdate()
|
||||
if not fs.exists("update_gate.lua") then
|
||||
return false, "update_gate.lua not found"
|
||||
end
|
||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||
return os.run(env, "update_gate.lua", "--silent")
|
||||
local fn, err = loadfile("update_gate.lua", env)
|
||||
if not fn then return false, err end
|
||||
local ok, res = pcall(fn, "--silent")
|
||||
if not ok then return false, tostring(res) end
|
||||
return true, true
|
||||
end
|
||||
|
||||
local function setServerConnected(ok)
|
||||
@@ -174,6 +181,8 @@ local function drawServerStatusIndicator(w)
|
||||
termDev.setTextColor(colors.white)
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator(w)
|
||||
local s = tostring(VERSION or "")
|
||||
if #s == 0 then return end
|
||||
@@ -196,6 +205,13 @@ local function drawVersionIndicator(w)
|
||||
termDev.write(s)
|
||||
termDev.setTextColor(markerColor)
|
||||
termDev.write(markerText)
|
||||
|
||||
if lastUpdateError then
|
||||
termDev.setCursorPos(1, 2)
|
||||
termDev.setTextColor(colors.red)
|
||||
termDev.write(string.sub(tostring(lastUpdateError), 1, w))
|
||||
end
|
||||
|
||||
termDev.setTextColor(colors.white)
|
||||
end
|
||||
|
||||
@@ -1452,16 +1468,18 @@ while true do
|
||||
|
||||
if pendingGateUpdate and isGateIdleForUpdate() then
|
||||
isUpdating = true
|
||||
lastUpdateError = nil
|
||||
drawReadyScreen()
|
||||
os.sleep(0.5)
|
||||
local ok, updated = pcall(runSilentGateUpdate)
|
||||
if ok and updated then
|
||||
if ok and updated == true then
|
||||
if expectedGateVersion then setLastUpdateVersion(expectedGateVersion) end
|
||||
os.reboot()
|
||||
return
|
||||
end
|
||||
isUpdating = false
|
||||
pendingGateUpdate = false
|
||||
lastUpdateError = tostring(updated)
|
||||
failedUpdateVersion = expectedGateVersion
|
||||
end
|
||||
drawReadyScreen()
|
||||
|
||||
Reference in New Issue
Block a user