diff --git a/ticketmachine.lua b/ticketmachine.lua index def9f5f..06e91a2 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -13,7 +13,6 @@ local function jsonDecode(str) end local serverConnected = nil -local expectedMachineVersion = nil local versionMismatch = nil local failedUpdateVersion = nil local pendingMachineUpdate = false @@ -685,6 +684,38 @@ local function runSilentMachineUpdate() return true, true end +local lastUpdateError = nil + +local function drawVersionIndicator() + if w < 1 then return end + local markerColor = colors.yellow + 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)) + termDev.setTextColor(markerColor) + termDev.write(markerText) + + if lastUpdateError then + termDev.setCursorPos(1, 2) + termDev.setTextColor(colors.red) + termDev.write(string.sub(tostring(lastUpdateError), 1, w)) + end + + termDev.setTextColor(colors.white) +end + local function backgroundSyncTask() pcall(refreshConfigOnce) while true do @@ -695,7 +726,7 @@ local function backgroundSyncTask() end end - if pendingMachineUpdate then + if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then isUpdating = true lastUpdateError = nil pcall(drawVersionIndicator) @@ -1138,38 +1169,6 @@ local function stationDisplay(code) return code end -local lastUpdateError = nil - -local function drawVersionIndicator() - if w < 1 then return end - local markerColor = colors.yellow - 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)) - termDev.setTextColor(markerColor) - termDev.write(markerText) - - if lastUpdateError then - termDev.setCursorPos(1, 2) - termDev.setTextColor(colors.red) - termDev.write(string.sub(tostring(lastUpdateError), 1, w)) - end - - termDev.setTextColor(colors.white) -end - local function drawServerStatusIndicator() if w < 2 then return end local col = colors.yellow