update notification

This commit is contained in:
kepler155c@gmail.com 2020-04-30 21:27:07 -06:00
parent e721eb68b6
commit 3368fa3266
2 changed files with 53 additions and 6 deletions

48
sys/apps/Version.lua Normal file
View File

@ -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()

View File

@ -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)