fix: 修复票据详情设备ID缺失并优化自动更新逻辑

- 为票据详情接口添加设备字段兼容映射,支持从e.device/e.device_id/e.detail?.device获取值
- 更新设备ID缺失问题的调试文档,标记已验证的假设并补充最终结论
- 优化售票机和闸机的自动更新逻辑:缩短版本检查间隔至5秒,添加更新中状态标识,改为事件触发更新
This commit is contained in:
2026-07-10 21:32:17 +08:00
parent 5f184bf184
commit f1cdfe3a84
4 changed files with 64 additions and 28 deletions
+21 -14
View File
@@ -1,7 +1,7 @@
local CURRENT_STATION_CODE = 'Ticket-Machine'
local API_BASE = 'http://ticket.fse-media.group/api'
local VERSION = 'v1.5.12'
local UPDATE_CHECK_INTERVAL = 60
local UPDATE_CHECK_INTERVAL = 5
-- ###########################
-- Core HTTP & JSON Utilities
@@ -15,6 +15,7 @@ end
local serverConnected = nil
local versionMismatch = nil
local pendingMachineUpdate = false
local isUpdating = false
local state
local function normalizeVersionTag(v)
@@ -662,21 +663,23 @@ local function runSilentMachineUpdate()
end
local function backgroundSyncTask()
pcall(refreshConfigOnce)
while true do
sleep(UPDATE_CHECK_INTERVAL)
pcall(refreshConfigOnce)
if versionMismatch == true then
pendingMachineUpdate = true
elseif versionMismatch == false then
pendingMachineUpdate = false
end
if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
isUpdating = true
pcall(drawVersionIndicator)
sleep(0.5)
local ok, updated = pcall(runSilentMachineUpdate)
if ok and updated then
os.reboot()
return
end
isUpdating = false
pendingMachineUpdate = false
pcall(drawVersionIndicator)
end
sleep(UPDATE_CHECK_INTERVAL)
pcall(refreshConfigOnce)
end
end
@@ -961,15 +964,15 @@ local function waitButtons()
while true do
local ev, p1, p2, p3 = os.pullEvent()
if ev == 'mouse_click' or ev == 'monitor_touch' then
-- For mouse_click: p1=button, p2=x, p3=y
-- For monitor_touch: p1=side, p2=x, p3=y
for _, b in ipairs(Buttons) do
if inRect(b, p2, p3) then
clickSound(); if b.onClick then b.onClick() end; return
end
end
elseif ev == 'trigger_update' then
pendingMachineUpdate = true
elseif ev == 'config_updated' then
-- Ignore config_updated while waiting for buttons, to prevent interrupting user's selection
if state and state.page == 'home' then return end
end
end
end
@@ -1103,7 +1106,11 @@ end
local function drawVersionIndicator()
if w < 1 then return end
local markerColor = colors.yellow
if versionMismatch == true then
local markerText = '*'
if isUpdating then
markerColor = colors.yellow
markerText = '^ing'
elseif versionMismatch == true then
markerColor = colors.red
elseif versionMismatch == false then
markerColor = colors.lime
@@ -1112,9 +1119,9 @@ local function drawVersionIndicator()
termDev.setTextColor(colors.gray)
termDev.setCursorPos(1, 1)
termDev.write(tostring(VERSION))
if w >= (#tostring(VERSION) + 1) then
if w >= (#tostring(VERSION) + #markerText) then
termDev.setTextColor(markerColor)
termDev.write('*')
termDev.write(markerText)
end
termDev.setTextColor(colors.white)
end