fix(ticketmachine): 修复更新触发条件并重构代码
移除未使用的 expectedMachineVersion 变量 调整后台同步任务的更新触发逻辑,仅在主页且状态有效时执行机器更新 移动版本指示器绘制函数到更早作用域,避免重复声明
This commit is contained in:
+33
-34
@@ -13,7 +13,6 @@ local function jsonDecode(str)
|
||||
end
|
||||
|
||||
local serverConnected = nil
|
||||
local expectedMachineVersion = nil
|
||||
local versionMismatch = nil
|
||||
local failedUpdateVersion = nil
|
||||
local pendingMachineUpdate = false
|
||||
@@ -685,6 +684,38 @@ local function runSilentMachineUpdate()
|
||||
return true, true
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator()
|
||||
if w < 1 then return end
|
||||
local markerColor = colors.yellow
|
||||
local markerText = '* '
|
||||
if isUpdating then
|
||||
markerColor = colors.yellow
|
||||
markerText = '^ing'
|
||||
elseif versionMismatch == true then
|
||||
markerColor = colors.red
|
||||
markerText = '* '
|
||||
elseif versionMismatch == false then
|
||||
markerColor = colors.lime
|
||||
markerText = ' '
|
||||
end
|
||||
termDev.setBackgroundColor(colors.black)
|
||||
termDev.setTextColor(colors.gray)
|
||||
termDev.setCursorPos(1, 1)
|
||||
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
|
||||
|
||||
local function backgroundSyncTask()
|
||||
pcall(refreshConfigOnce)
|
||||
while true do
|
||||
@@ -695,7 +726,7 @@ local function backgroundSyncTask()
|
||||
end
|
||||
end
|
||||
|
||||
if pendingMachineUpdate then
|
||||
if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
|
||||
isUpdating = true
|
||||
lastUpdateError = nil
|
||||
pcall(drawVersionIndicator)
|
||||
@@ -1138,38 +1169,6 @@ local function stationDisplay(code)
|
||||
return code
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator()
|
||||
if w < 1 then return end
|
||||
local markerColor = colors.yellow
|
||||
local markerText = '* '
|
||||
if isUpdating then
|
||||
markerColor = colors.yellow
|
||||
markerText = '^ing'
|
||||
elseif versionMismatch == true then
|
||||
markerColor = colors.red
|
||||
markerText = '* '
|
||||
elseif versionMismatch == false then
|
||||
markerColor = colors.lime
|
||||
markerText = ' '
|
||||
end
|
||||
termDev.setBackgroundColor(colors.black)
|
||||
termDev.setTextColor(colors.gray)
|
||||
termDev.setCursorPos(1, 1)
|
||||
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
|
||||
|
||||
local function drawServerStatusIndicator()
|
||||
if w < 2 then return end
|
||||
local col = colors.yellow
|
||||
|
||||
Reference in New Issue
Block a user