Skip to content

Commit

Permalink
feat: version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
vipexv committed Dec 24, 2023
1 parent 9208f7c commit 0f2cf8f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ client_scripts {

server_scripts {
-- "@vrp/lib/utils.lua", -- Enable if you are using vRP
"server/core.lua"
"server/core.lua",
"server/versionChecker.lua"
}

files {
Expand Down
53 changes: 53 additions & 0 deletions server/versionChecker.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- Copy and pasta from ox_lib Credit: "https://github.com/overextended/ox_lib"

if not LoadResourceFile(GetCurrentResourceName(), 'web/build/index.html') then
local err =
'Unable to load UI. Build vHud or download the latest release.\n https://github.com/vipexv/vHud/releases/latest'
print(err)
end

local versionCheck = function(repository)
local resource = GetInvokingResource() or GetCurrentResourceName()

local currentVersion = 'v1.1.1'

if currentVersion then
currentVersion = currentVersion:match('%d+%.%d+%.%d+')
end

if not currentVersion then
return print(("^1Unable to determine current resource version for '%s' ^0"):format(
resource))
end

SetTimeout(1000, function()
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository),
function(status, response)
if status ~= 200 then return end

response = json.decode(response)
if response.prerelease then return end

local latestVersion = response.tag_name:match('%d+%.%d+%.%d+')
if not latestVersion or latestVersion == currentVersion then return end

local cv = { string.strsplit('.', currentVersion) }
local lv = { string.strsplit('.', latestVersion) }

for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(lv[i])

if current ~= minimum then
if current < minimum then
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(
resource, currentVersion, response.html_url))
else
break
end
end
end
end, 'GET')
end)
end

versionCheck('vipexv/vHud')

0 comments on commit 0f2cf8f

Please sign in to comment.