fix(gate): use parallel background sync task for updates exactly like ticketmachine

This commit is contained in:
2026-07-11 16:26:09 +08:00
parent c5cd4b6a95
commit a228c24b33
3 changed files with 30 additions and 21 deletions
+28 -19
View File
@@ -1,9 +1,11 @@
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.18"
local VERSION = "v1.5.20"
local VERSION_CHECK_INTERVAL = 5
local serverURL = nil
local CONFIG_PATH = "gate_config.json"
local function readFile(path)
@@ -164,7 +166,7 @@ local function checkAndApplyUpdate()
if not remoteTs or remoteTs <= 0 then return end
local attemptFile = ".last_update_ts"
local attemptFile = ".last_update_ts_gate"
if fs.exists(attemptFile) then
local f = fs.open(attemptFile, "r")
local tried = tonumber(f and f.readAll() or "0") or 0
@@ -175,7 +177,9 @@ local function checkAndApplyUpdate()
end
isUpdating = true
pcall(drawReadyScreen)
if type(drawReadyScreen) == "function" then
pcall(drawReadyScreen)
end
sleep(0.5)
local f = fs.open(attemptFile, "w")
@@ -203,7 +207,7 @@ local function checkAndApplyUpdate()
end
isUpdating = false
if pcall then
if type(drawReadyScreen) == "function" then
pcall(drawReadyScreen)
end
@@ -784,7 +788,7 @@ end
local cfg = loadConfig()
local stationSet = stationSetFromList(cfg.station_codes)
local serverURL = resolveServerURL(cfg)
serverURL = resolveServerURL(cfg)
local cardServerURL = resolveCardServerURL(cfg, serverURL)
local cardSyncBaseURL = resolveCardSyncBaseURL(cfg, serverURL, cardServerURL)
local fareQueryURL = resolveFareQueryURL(serverURL)
@@ -1500,19 +1504,24 @@ end
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
processInspectionEvent(ev[1], ev)
os.sleep(0.35)
drawReadyScreen()
elseif ev[1] == "timer" and ev[2] == versionTimer then
pcall(function()
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
end)
pcall(checkAndApplyUpdate)
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
local function mainLoop()
while true do
local ev = pack(os.pullEvent())
if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then
processInspectionEvent(ev[1], ev)
os.sleep(0.35)
drawReadyScreen()
end
end
end
local function backgroundSyncTask()
pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end)
while true do
sleep(VERSION_CHECK_INTERVAL)
pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end)
pcall(checkAndApplyUpdate)
end
end
parallel.waitForAny(mainLoop, backgroundSyncTask)
+1 -1
View File
@@ -1,4 +1,4 @@
local VERSION = "v1.5.18"
local VERSION = "v1.5.20"
local MACHINE_SIDE = "bottom"
local PAYMENT_SIDE = "right"
local PRESET_AMOUNTS = { 5, 10, 15, 20 }
+1 -1
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.18'
local VERSION = 'v1.5.20'
local UPDATE_CHECK_INTERVAL = 5
-- ###########################