feat: 优化自动更新逻辑,移除单程票购票并升级版本至1.0.18
升级package.json版本至1.0.18;重构update_gate.lua和update_machine.lua,支持--silent静默运行参数,统一日志输出逻辑;优化ticketmachine.lua和gate.lua的自动更新触发逻辑,新增设备空闲检测,避免打断用户操作,仅在空闲时执行静默更新后重启设备;修复ticketmachine.lua中state变量重复声明的问题;移除Web端ticket-order相关的单程票购票UI与业务逻辑,简化购票流程;将gate.lua中的版本检查间隔从5秒调整为60秒,优化设备ID显示格式。
This commit is contained in:
@@ -2,7 +2,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.10"
|
||||
local VERSION_CHECK_INTERVAL = 5
|
||||
local VERSION_CHECK_INTERVAL = 60
|
||||
|
||||
local CONFIG_PATH = "gate_config.json"
|
||||
|
||||
@@ -92,6 +92,30 @@ local serverConnected = nil
|
||||
local serverLastChangeTs = 0
|
||||
local expectedGateVersion = nil
|
||||
local versionMismatch = nil
|
||||
local pendingGateUpdate = false
|
||||
local gateBusyUntilTs = 0
|
||||
|
||||
local function nowMs()
|
||||
return (os.epoch and os.epoch("utc")) or (os.time() * 1000)
|
||||
end
|
||||
|
||||
local function markGateBusy(seconds)
|
||||
local secondsNum = tonumber(seconds) or 0
|
||||
local untilTs = nowMs() + math.max(1000, math.floor(secondsNum * 1000))
|
||||
if untilTs > gateBusyUntilTs then
|
||||
gateBusyUntilTs = untilTs
|
||||
end
|
||||
end
|
||||
|
||||
local function isGateIdleForUpdate()
|
||||
return nowMs() >= gateBusyUntilTs
|
||||
end
|
||||
|
||||
local function runSilentGateUpdate()
|
||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||
return os.run(env, "update_gate.lua", "--silent")
|
||||
end
|
||||
|
||||
local function setServerConnected(ok)
|
||||
if serverConnected == ok then return end
|
||||
@@ -997,7 +1021,7 @@ local function currentDeviceId()
|
||||
if label and label ~= "" then
|
||||
return label
|
||||
end
|
||||
return "闸机#" .. tostring(os.getComputerID())
|
||||
return "#" .. tostring(os.getComputerID())
|
||||
end
|
||||
|
||||
local function syncICCardState(cardId, payload)
|
||||
@@ -1353,6 +1377,7 @@ local versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
|
||||
while true do
|
||||
local ev = pack(os.pullEvent())
|
||||
if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then
|
||||
markGateBusy(GATE_OPEN_SECONDS + 2)
|
||||
processInspectionEvent(ev[1], ev)
|
||||
os.sleep(0.35)
|
||||
drawReadyScreen()
|
||||
@@ -1361,19 +1386,16 @@ while true do
|
||||
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
||||
end)
|
||||
if versionMismatch == true then
|
||||
pcall(function()
|
||||
clear()
|
||||
local w, h = termDev.getSize()
|
||||
centerText(math.floor(h / 2), "Auto Updating...", colors.yellow)
|
||||
end)
|
||||
pcall(function()
|
||||
if shell and type(shell.run) == "function" then
|
||||
shell.run("update_gate.lua")
|
||||
else
|
||||
os.run(getfenv and getfenv() or _ENV, "update_gate.lua")
|
||||
end
|
||||
end)
|
||||
os.reboot()
|
||||
pendingGateUpdate = true
|
||||
elseif versionMismatch == false then
|
||||
pendingGateUpdate = false
|
||||
end
|
||||
if pendingGateUpdate and isGateIdleForUpdate() then
|
||||
local ok, updated = pcall(runSilentGateUpdate)
|
||||
if ok and updated then
|
||||
os.reboot()
|
||||
return
|
||||
end
|
||||
end
|
||||
drawReadyScreen()
|
||||
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
|
||||
|
||||
Reference in New Issue
Block a user