From b528a3ae56ab527c9443ca9c5849a3cf5dc9b6c8 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 11 Jul 2026 11:02:08 +0800 Subject: [PATCH] refactor: remove unused update functions and variables --- gate.lua | 74 ++--------------------------------------------- ticketmachine.lua | 25 ---------------- 2 files changed, 3 insertions(+), 96 deletions(-) diff --git a/gate.lua b/gate.lua index fef270b..976ce7f 100644 --- a/gate.lua +++ b/gate.lua @@ -90,42 +90,14 @@ 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 -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 getLastUpdateVersion() - if not fs.exists(".last_update_version") then return nil end - local f = fs.open(".last_update_version", "r") - if not f then return nil end - local v = f.readAll() - f.close() - return v -end - -local function setLastUpdateVersion(v) - local f = fs.open(".last_update_version", "w") - if f then f.write(tostring(v)); f.close() end -end local function checkAndApplyUpdate() if type(CFG) ~= 'table' then return end @@ -463,13 +435,10 @@ local function refreshRemoteLuaVersion(serverBase) if not ok or type(parsed) ~= "table" then return false end _G.CFG = parsed local remote = normalizeVersionTag(type(parsed.lua_versions) == "table" and parsed.lua_versions.gate or nil) - remoteForceUpdate = (parsed.force_update == true) if #remote == 0 then - expectedGateVersion = nil versionMismatch = nil return true end - expectedGateVersion = remote versionMismatch = (remote ~= normalizeVersionTag(VERSION)) return true end @@ -1470,56 +1439,19 @@ end local versionTimer = os.startTimer(VERSION_CHECK_INTERVAL) --- 启动时不再自动触发更新检查逻辑,等待事件触发 --- if pendingGateUpdate and isGateIdleForUpdate() then --- isUpdating = true --- drawReadyScreen() --- os.sleep(0.5) --- local ok, updated = pcall(runSilentGateUpdate) --- if ok and updated then --- os.reboot() --- return --- end --- isUpdating = false --- drawReadyScreen() --- end + 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() - elseif ev[1] == "trigger_update" then - pendingGateUpdate = true elseif ev[1] == "timer" and ev[2] == versionTimer then pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) - if remoteForceUpdate then - if expectedGateVersion and expectedGateVersion ~= getLastUpdateVersion() and expectedGateVersion ~= failedUpdateVersion then - pendingGateUpdate = true - end - end - - if pendingGateUpdate and isGateIdleForUpdate() then - isUpdating = true - lastUpdateError = nil - drawReadyScreen() - os.sleep(0.5) - local ok, updated = pcall(runSilentGateUpdate) - if ok and updated == true then - if expectedGateVersion then setLastUpdateVersion(expectedGateVersion) end - os.reboot() - return - end - isUpdating = false - pendingGateUpdate = false - lastUpdateError = tostring(updated) - failedUpdateVersion = expectedGateVersion - end - drawReadyScreen() + pcall(checkAndApplyUpdate) versionTimer = os.startTimer(VERSION_CHECK_INTERVAL) end end diff --git a/ticketmachine.lua b/ticketmachine.lua index a8bebe6..4d67648 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -655,32 +655,7 @@ local function clickSound() end -- ########################### -- Background Tasks -- ########################### -local function getLastUpdateVersion() - if not fs.exists(".last_update_version") then return nil end - local f = fs.open(".last_update_version", "r") - if not f then return nil end - local v = f.readAll() - f.close() - return v -end -local function setLastUpdateVersion(v) - local f = fs.open(".last_update_version", "w") - if f then f.write(tostring(v)); f.close() end -end - -local function runSilentMachineUpdate() - if not fs.exists('update_machine.lua') then - return false, "update_machine.lua not found" - end - local baseEnv = (getfenv and getfenv()) or _ENV or _G - local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv }) - local fn, err = loadfile('update_machine.lua', env) - if not fn then return false, err end - local ok, res = pcall(fn, '--silent') - if not ok then return false, tostring(res) end - return true, true -end local lastUpdateError = nil