From 3368fa3266da64d1c50d876f2bee70d3a76ff2a3 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 30 Apr 2020 21:27:07 -0600 Subject: [PATCH] update notification --- sys/apps/Version.lua | 48 +++++++++++++++++++++++++++++++++++++++++ sys/autorun/version.lua | 11 +++++----- 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 sys/apps/Version.lua diff --git a/sys/apps/Version.lua b/sys/apps/Version.lua new file mode 100644 index 0000000..55d196e --- /dev/null +++ b/sys/apps/Version.lua @@ -0,0 +1,48 @@ +local Config = require('opus.config') +local UI = require('opus.ui') + +local shell = _ENV.shell + +local config = Config.load('version') +if not config.current then + return +end + +UI:setPage(UI.Page { + UI.TextArea { + x = 2, y = 2, ey = -2, + value = 'A new version of Opus is available.' + }, + UI.Button { + x = 2, y = 5, width = 21, + event = 'skip', + text = 'Skip this version', + }, + UI.Button { + x = 2, y = 7, width = 21, + event = 'remind', + text = 'Remind me tomorrow', + }, + UI.Button { + x = 2, y = 9, width = 21, + event = 'update', + text = 'Update' + }, + eventHandler = function(self, event) + if event.type == 'skip' then + config.skip = config.current + Config.update('version', config) + UI:quit() + + elseif event.type == 'remind' then + UI:quit() + + elseif event.type == 'update' then + shell.openForegroundTab('update update') + UI:quit() + end + return UI.Page.eventHandler(self, event) + end, +}) + +UI:start() diff --git a/sys/autorun/version.lua b/sys/autorun/version.lua index 8acf87d..f551f4a 100644 --- a/sys/autorun/version.lua +++ b/sys/autorun/version.lua @@ -6,15 +6,11 @@ local shell = _ENV.shell local URL = 'https://raw.githubusercontent.com/kepler155c/opus/%s/.opus_version' -local function notifyUpdate(config) - print('Opus has been updated to: ' .. config.current) - read() -end - if fs.exists('.opus_version') then local f = fs.open('.opus_version') local date = f.readLine() f.close() + date = type(date) == 'string' and Util.split(date)[1] if type(date) == 'string' and #date > 0 then local today = os.date('%j') @@ -44,7 +40,10 @@ if fs.exists('.opus_version') then if config.opus ~= c and config.skip ~= c then config.current = c Config.update('version', config) - notifyUpdate(config) + print('New version available') + if _ENV.multishell then + shell.openForegroundTab('Version') + end end end end)