diff --git a/gate.lua b/gate.lua index 2aa0295..365825d 100644 --- a/gate.lua +++ b/gate.lua @@ -1,7 +1,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.12" +local VERSION = "v1.5.13" local VERSION_CHECK_INTERVAL = 5 local CONFIG_PATH = "gate_config.json" @@ -90,6 +90,8 @@ 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 @@ -163,23 +165,23 @@ local function drawVersionIndicator(w) if #s == 0 then return end if w < #s then return end local markerColor = colors.yellow - local markerText = "*" + local markerText = "* " if isUpdating then markerColor = colors.yellow markerText = "^ing" elseif versionMismatch == true then markerColor = colors.red + markerText = "* " elseif versionMismatch == false then markerColor = colors.lime + markerText = " " end termDev.setBackgroundColor(colors.black) termDev.setTextColor(colors.gray) termDev.setCursorPos(1, 1) termDev.write(s) - if w >= (#s + #markerText) then - termDev.setTextColor(markerColor) - termDev.write(markerText) - end + termDev.setTextColor(markerColor) + termDev.write(markerText) termDev.setTextColor(colors.white) end @@ -405,6 +407,7 @@ local function refreshRemoteLuaVersion(serverBase) return true end + local function inferStationCodeFromName(name) local key = normKey(name or "") if #key == 0 then return "" end @@ -1428,7 +1431,9 @@ while true do refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) if remoteForceUpdate and versionMismatch == true then - pendingGateUpdate = true + if expectedGateVersion ~= failedUpdateVersion then + pendingGateUpdate = true + end end if pendingGateUpdate and isGateIdleForUpdate() then @@ -1442,6 +1447,7 @@ while true do end isUpdating = false pendingGateUpdate = false + failedUpdateVersion = expectedGateVersion end drawReadyScreen() versionTimer = os.startTimer(VERSION_CHECK_INTERVAL) diff --git a/ticketmachine.lua b/ticketmachine.lua index 9de1599..f5cd22a 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -1,6 +1,6 @@ local CURRENT_STATION_CODE = 'Ticket-Machine' local API_BASE = 'http://ticket.fse-media.group/api' -local VERSION = 'v1.5.13.1' +local VERSION = 'v1.5.13' local UPDATE_CHECK_INTERVAL = 5 -- ########################### @@ -13,10 +13,12 @@ local function jsonDecode(str) end local serverConnected = nil +local expectedMachineVersion = nil local versionMismatch = nil +local failedUpdateVersion = nil local pendingMachineUpdate = false local isUpdating = false -local state +local state = {} local function normalizeVersionTag(v) local s = tostring(v or ''):gsub('^%s+', ''):gsub('%s+$', '') @@ -665,6 +667,12 @@ end local function backgroundSyncTask() pcall(refreshConfigOnce) while true do + if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then + if expectedMachineVersion ~= failedUpdateVersion then + pendingMachineUpdate = true + end + end + if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then isUpdating = true pcall(drawVersionIndicator) @@ -676,14 +684,11 @@ local function backgroundSyncTask() end isUpdating = false pendingMachineUpdate = false + failedUpdateVersion = expectedMachineVersion pcall(drawVersionIndicator) end sleep(UPDATE_CHECK_INTERVAL) pcall(refreshConfigOnce) - - if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then - pendingMachineUpdate = true - end end end @@ -1110,23 +1115,23 @@ end local function drawVersionIndicator() if w < 1 then return end local markerColor = colors.yellow - local markerText = '*' + local markerText = '* ' if isUpdating then markerColor = colors.yellow markerText = '^ing' elseif versionMismatch == true then markerColor = colors.red + markerText = '* ' elseif versionMismatch == false then markerColor = colors.lime + markerText = ' ' end termDev.setBackgroundColor(colors.black) termDev.setTextColor(colors.gray) termDev.setCursorPos(1, 1) termDev.write(tostring(VERSION)) - if w >= (#tostring(VERSION) + #markerText) then - termDev.setTextColor(markerColor) - termDev.write(markerText) - end + termDev.setTextColor(markerColor) + termDev.write(markerText) termDev.setTextColor(colors.white) end