refactor: remove unused update functions and variables
This commit is contained in:
@@ -90,42 +90,14 @@ 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 remoteForceUpdate = false
|
|
||||||
local isUpdating = false
|
local isUpdating = false
|
||||||
local gateBusyUntilTs = 0
|
|
||||||
|
|
||||||
local function nowMs()
|
local function nowMs()
|
||||||
return (os.epoch and os.epoch("utc")) or (os.time() * 1000)
|
return (os.epoch and os.epoch("utc")) or (os.time() * 1000)
|
||||||
end
|
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()
|
local function checkAndApplyUpdate()
|
||||||
if type(CFG) ~= 'table' then return end
|
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
|
if not ok or type(parsed) ~= "table" then return false end
|
||||||
_G.CFG = parsed
|
_G.CFG = parsed
|
||||||
local remote = normalizeVersionTag(type(parsed.lua_versions) == "table" and parsed.lua_versions.gate or nil)
|
local remote = normalizeVersionTag(type(parsed.lua_versions) == "table" and parsed.lua_versions.gate or nil)
|
||||||
remoteForceUpdate = (parsed.force_update == true)
|
|
||||||
if #remote == 0 then
|
if #remote == 0 then
|
||||||
expectedGateVersion = nil
|
|
||||||
versionMismatch = nil
|
versionMismatch = nil
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
expectedGateVersion = remote
|
|
||||||
versionMismatch = (remote ~= normalizeVersionTag(VERSION))
|
versionMismatch = (remote ~= normalizeVersionTag(VERSION))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -1470,56 +1439,19 @@ end
|
|||||||
|
|
||||||
local versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
|
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
|
while true do
|
||||||
local ev = pack(os.pullEvent())
|
local ev = pack(os.pullEvent())
|
||||||
if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then
|
if ev[1] == "ticket_scanned" or ev[1] == "ic_card_scanned" then
|
||||||
markGateBusy(GATE_OPEN_SECONDS + 2)
|
|
||||||
processInspectionEvent(ev[1], ev)
|
processInspectionEvent(ev[1], ev)
|
||||||
os.sleep(0.35)
|
os.sleep(0.35)
|
||||||
drawReadyScreen()
|
drawReadyScreen()
|
||||||
elseif ev[1] == "trigger_update" then
|
|
||||||
pendingGateUpdate = true
|
|
||||||
elseif ev[1] == "timer" and ev[2] == versionTimer then
|
elseif ev[1] == "timer" and ev[2] == versionTimer then
|
||||||
pcall(function()
|
pcall(function()
|
||||||
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
||||||
end)
|
end)
|
||||||
if remoteForceUpdate then
|
pcall(checkAndApplyUpdate)
|
||||||
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()
|
|
||||||
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
|
versionTimer = os.startTimer(VERSION_CHECK_INTERVAL)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -655,32 +655,7 @@ local function clickSound() end
|
|||||||
-- ###########################
|
-- ###########################
|
||||||
-- Background Tasks
|
-- 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
|
local lastUpdateError = nil
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user