fix(update): 优化更新逻辑,添加错误提示并清理冗余代码
移除所有脚本文件的头部注释模板 删除installer.lua中未使用的splitCsv函数 重构静默更新逻辑,改用loadfile替代os.run以正确捕获执行错误 添加更新错误追踪机制,在界面版本指示器处显示失败提示 修复更新成功的判断条件
This commit is contained in:
+21
-3
@@ -673,9 +673,16 @@ local function setLastUpdateVersion(v)
|
||||
end
|
||||
|
||||
local function runSilentMachineUpdate()
|
||||
if not fs.exists('update_machine.lua') then
|
||||
return false, "update_machine.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_machine.lua', '--silent')
|
||||
local fn, err = loadfile('update_machine.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 backgroundSyncTask()
|
||||
@@ -690,17 +697,19 @@ local function backgroundSyncTask()
|
||||
|
||||
if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
|
||||
isUpdating = true
|
||||
lastUpdateError = nil
|
||||
pcall(drawVersionIndicator)
|
||||
sleep(0.5)
|
||||
local ok, updated = pcall(runSilentMachineUpdate)
|
||||
if ok and updated then
|
||||
local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||
if ok and updated == true then
|
||||
local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||
if expected then setLastUpdateVersion(expected) end
|
||||
os.reboot()
|
||||
return
|
||||
end
|
||||
isUpdating = false
|
||||
pendingMachineUpdate = false
|
||||
lastUpdateError = tostring(updated)
|
||||
failedUpdateVersion = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||
pcall(drawVersionIndicator)
|
||||
end
|
||||
@@ -1129,6 +1138,8 @@ local function stationDisplay(code)
|
||||
return code
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator()
|
||||
if w < 1 then return end
|
||||
local markerColor = colors.yellow
|
||||
@@ -1149,6 +1160,13 @@ local function drawVersionIndicator()
|
||||
termDev.write(tostring(VERSION))
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user