mirror of
https://github.com/kepler155c/opus
synced 2024-12-28 17:40:26 +00:00
update notification
This commit is contained in:
parent
e721eb68b6
commit
3368fa3266
48
sys/apps/Version.lua
Normal file
48
sys/apps/Version.lua
Normal 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()
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user