From 0d11292273a98ee092dce5d56231b6762e2fcde3 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 11 Jul 2026 08:26:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(ticketmachine):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=A6=E5=8F=91=E6=9D=A1=E4=BB=B6=E5=B9=B6?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除未使用的 expectedMachineVersion 变量 调整后台同步任务的更新触发逻辑,仅在主页且状态有效时执行机器更新 移动版本指示器绘制函数到更早作用域,避免重复声明 --- ticketmachine.lua | 67 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/ticketmachine.lua b/ticketmachine.lua index def9f5f..06e91a2 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -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