fix: 修复更新逻辑,调整版本显示并同步版本号

- 新增失败更新版本跟踪变量,避免重复触发同一失败版本的更新
- 调整版本指示器的绘制逻辑,优化标记文本的显示效果
- 修复强制更新的触发校验条件,完善整体更新流程
- 初始化缺失的state变量并同步两个文件的程序版本号
This commit is contained in:
2026-07-10 23:55:47 +08:00
parent 565f0008dd
commit f0b8db1662
2 changed files with 29 additions and 18 deletions
+13 -7
View File
@@ -1,7 +1,7 @@
local DEFAULT_SERVER_BASE = "http://ticket.fse-media.group"
local DEFAULT_SERVER_PATH = "/api/tickets/check"
local GATE_OPEN_SECONDS = 2
local VERSION = "v1.5.12"
local VERSION = "v1.5.13"
local VERSION_CHECK_INTERVAL = 5
local CONFIG_PATH = "gate_config.json"
@@ -90,6 +90,8 @@ local inspection = peripheral.find("ticket_inspection_machine")
local serverConnected = nil
local versionMismatch = nil
local expectedGateVersion = nil
local failedUpdateVersion = nil
local pendingGateUpdate = false
local remoteForceUpdate = false
local isUpdating = false
@@ -163,23 +165,23 @@ local function drawVersionIndicator(w)
if #s == 0 then return end
if w < #s then return end
local markerColor = colors.yellow
local markerText = "*"
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(s)
if w >= (#s + #markerText) then
termDev.setTextColor(markerColor)
termDev.write(markerText)
end
termDev.setTextColor(markerColor)
termDev.write(markerText)
termDev.setTextColor(colors.white)
end
@@ -405,6 +407,7 @@ local function refreshRemoteLuaVersion(serverBase)
return true
end
local function inferStationCodeFromName(name)
local key = normKey(name or "")
if #key == 0 then return "" end
@@ -1428,7 +1431,9 @@ while true do
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
end)
if remoteForceUpdate and versionMismatch == true then
pendingGateUpdate = true
if expectedGateVersion ~= failedUpdateVersion then
pendingGateUpdate = true
end
end
if pendingGateUpdate and isGateIdleForUpdate() then
@@ -1442,6 +1447,7 @@ while true do
end
isUpdating = false
pendingGateUpdate = false
failedUpdateVersion = expectedGateVersion
end
drawReadyScreen()
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
+16 -11
View File
@@ -1,6 +1,6 @@
local CURRENT_STATION_CODE = 'Ticket-Machine'
local API_BASE = 'http://ticket.fse-media.group/api'
local VERSION = 'v1.5.13.1'
local VERSION = 'v1.5.13'
local UPDATE_CHECK_INTERVAL = 5
-- ###########################
@@ -13,10 +13,12 @@ local function jsonDecode(str)
end
local serverConnected = nil
local expectedMachineVersion = nil
local versionMismatch = nil
local failedUpdateVersion = nil
local pendingMachineUpdate = false
local isUpdating = false
local state
local state = {}
local function normalizeVersionTag(v)
local s = tostring(v or ''):gsub('^%s+', ''):gsub('%s+$', '')
@@ -665,6 +667,12 @@ end
local function backgroundSyncTask()
pcall(refreshConfigOnce)
while true do
if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then
if expectedMachineVersion ~= failedUpdateVersion then
pendingMachineUpdate = true
end
end
if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
isUpdating = true
pcall(drawVersionIndicator)
@@ -676,14 +684,11 @@ local function backgroundSyncTask()
end
isUpdating = false
pendingMachineUpdate = false
failedUpdateVersion = expectedMachineVersion
pcall(drawVersionIndicator)
end
sleep(UPDATE_CHECK_INTERVAL)
pcall(refreshConfigOnce)
if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then
pendingMachineUpdate = true
end
end
end
@@ -1110,23 +1115,23 @@ end
local function drawVersionIndicator()
if w < 1 then return end
local markerColor = colors.yellow
local markerText = '*'
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))
if w >= (#tostring(VERSION) + #markerText) then
termDev.setTextColor(markerColor)
termDev.write(markerText)
end
termDev.setTextColor(markerColor)
termDev.write(markerText)
termDev.setTextColor(colors.white)
end