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_BASE = "http://ticket.fse-media.group"
local DEFAULT_SERVER_PATH = "/api/tickets/check" local DEFAULT_SERVER_PATH = "/api/tickets/check"
local GATE_OPEN_SECONDS = 2 local GATE_OPEN_SECONDS = 2
local VERSION = "v1.5.12" local VERSION = "v1.5.13"
local VERSION_CHECK_INTERVAL = 5 local VERSION_CHECK_INTERVAL = 5
local CONFIG_PATH = "gate_config.json" local CONFIG_PATH = "gate_config.json"
@@ -90,6 +90,8 @@ local inspection = peripheral.find("ticket_inspection_machine")
local serverConnected = nil local serverConnected = nil
local versionMismatch = nil local versionMismatch = nil
local expectedGateVersion = nil
local failedUpdateVersion = nil
local pendingGateUpdate = false local pendingGateUpdate = false
local remoteForceUpdate = false local remoteForceUpdate = false
local isUpdating = false local isUpdating = false
@@ -163,23 +165,23 @@ local function drawVersionIndicator(w)
if #s == 0 then return end if #s == 0 then return end
if w < #s then return end if w < #s then return end
local markerColor = colors.yellow local markerColor = colors.yellow
local markerText = "*" local markerText = "* "
if isUpdating then if isUpdating then
markerColor = colors.yellow markerColor = colors.yellow
markerText = "^ing" markerText = "^ing"
elseif versionMismatch == true then elseif versionMismatch == true then
markerColor = colors.red markerColor = colors.red
markerText = "* "
elseif versionMismatch == false then elseif versionMismatch == false then
markerColor = colors.lime markerColor = colors.lime
markerText = " "
end end
termDev.setBackgroundColor(colors.black) termDev.setBackgroundColor(colors.black)
termDev.setTextColor(colors.gray) termDev.setTextColor(colors.gray)
termDev.setCursorPos(1, 1) termDev.setCursorPos(1, 1)
termDev.write(s) termDev.write(s)
if w >= (#s + #markerText) then termDev.setTextColor(markerColor)
termDev.setTextColor(markerColor) termDev.write(markerText)
termDev.write(markerText)
end
termDev.setTextColor(colors.white) termDev.setTextColor(colors.white)
end end
@@ -405,6 +407,7 @@ local function refreshRemoteLuaVersion(serverBase)
return true return true
end end
local function inferStationCodeFromName(name) local function inferStationCodeFromName(name)
local key = normKey(name or "") local key = normKey(name or "")
if #key == 0 then return "" end if #key == 0 then return "" end
@@ -1428,7 +1431,9 @@ while true do
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
end) end)
if remoteForceUpdate and versionMismatch == true then if remoteForceUpdate and versionMismatch == true then
pendingGateUpdate = true if expectedGateVersion ~= failedUpdateVersion then
pendingGateUpdate = true
end
end end
if pendingGateUpdate and isGateIdleForUpdate() then if pendingGateUpdate and isGateIdleForUpdate() then
@@ -1442,6 +1447,7 @@ while true do
end end
isUpdating = false isUpdating = false
pendingGateUpdate = false pendingGateUpdate = false
failedUpdateVersion = expectedGateVersion
end end
drawReadyScreen() drawReadyScreen()
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL) versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
+16 -11
View File
@@ -1,6 +1,6 @@
local CURRENT_STATION_CODE = 'Ticket-Machine' local CURRENT_STATION_CODE = 'Ticket-Machine'
local API_BASE = 'http://ticket.fse-media.group/api' 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 local UPDATE_CHECK_INTERVAL = 5
-- ########################### -- ###########################
@@ -13,10 +13,12 @@ local function jsonDecode(str)
end end
local serverConnected = nil local serverConnected = nil
local expectedMachineVersion = nil
local versionMismatch = nil local versionMismatch = nil
local failedUpdateVersion = nil
local pendingMachineUpdate = false local pendingMachineUpdate = false
local isUpdating = false local isUpdating = false
local state local state = {}
local function normalizeVersionTag(v) local function normalizeVersionTag(v)
local s = tostring(v or ''):gsub('^%s+', ''):gsub('%s+$', '') local s = tostring(v or ''):gsub('^%s+', ''):gsub('%s+$', '')
@@ -665,6 +667,12 @@ end
local function backgroundSyncTask() local function backgroundSyncTask()
pcall(refreshConfigOnce) pcall(refreshConfigOnce)
while true do 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 if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
isUpdating = true isUpdating = true
pcall(drawVersionIndicator) pcall(drawVersionIndicator)
@@ -676,14 +684,11 @@ local function backgroundSyncTask()
end end
isUpdating = false isUpdating = false
pendingMachineUpdate = false pendingMachineUpdate = false
failedUpdateVersion = expectedMachineVersion
pcall(drawVersionIndicator) pcall(drawVersionIndicator)
end end
sleep(UPDATE_CHECK_INTERVAL) sleep(UPDATE_CHECK_INTERVAL)
pcall(refreshConfigOnce) 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
end end
@@ -1110,23 +1115,23 @@ end
local function drawVersionIndicator() local function drawVersionIndicator()
if w < 1 then return end if w < 1 then return end
local markerColor = colors.yellow local markerColor = colors.yellow
local markerText = '*' local markerText = '* '
if isUpdating then if isUpdating then
markerColor = colors.yellow markerColor = colors.yellow
markerText = '^ing' markerText = '^ing'
elseif versionMismatch == true then elseif versionMismatch == true then
markerColor = colors.red markerColor = colors.red
markerText = '* '
elseif versionMismatch == false then elseif versionMismatch == false then
markerColor = colors.lime markerColor = colors.lime
markerText = ' '
end end
termDev.setBackgroundColor(colors.black) termDev.setBackgroundColor(colors.black)
termDev.setTextColor(colors.gray) termDev.setTextColor(colors.gray)
termDev.setCursorPos(1, 1) termDev.setCursorPos(1, 1)
termDev.write(tostring(VERSION)) termDev.write(tostring(VERSION))
if w >= (#tostring(VERSION) + #markerText) then termDev.setTextColor(markerColor)
termDev.setTextColor(markerColor) termDev.write(markerText)
termDev.write(markerText)
end
termDev.setTextColor(colors.white) termDev.setTextColor(colors.white)
end end