-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathupdate_checker.lua
More file actions
40 lines (37 loc) · 1.3 KB
/
update_checker.lua
File metadata and controls
40 lines (37 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local http = require("socket.http")
local ltn12 = require("ltn12")
local json = require("json")
local meta = require("_meta")
local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local function checkForUpdates()
local response_body = {}
local _, code = http.request {
url = "https://api.github.com/repos/drewbaumann/AskGPT/releases/latest",
headers = {
["Accept"] = "application/vnd.github.v3+json"
},
sink = ltn12.sink.table(response_body)
}
if code == 200 then
local data = table.concat(response_body)
local parsed_data = json.decode(data)
local latest_version = parsed_data.tag_name -- e.g., "v0.9"
local stripped_latest_version = latest_version:match("^v(.+)$")
-- Compare with current version
if meta.version < tonumber(stripped_latest_version) then
-- Show notification to the user if a new version is available
local message = "A new version of the app (" .. latest_version .. ") is available. Please update!"
local info_message = InfoMessage:new{
text = message,
timeout = 5 -- Display message for 5 seconds
}
UIManager:show(info_message)
end
else
print("Failed to check for updates. HTTP code:", code)
end
end
return {
checkForUpdates = checkForUpdates
}