From b6383112a0ee2d236e9a3298ea1c32ff0c12fa1b Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:31:11 -0400 Subject: [PATCH] feat: remove ox_lib dependency --- README.md | 4 ---- fxmanifest.lua | 2 -- server/main.lua | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7e6947d..9f608d3 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ Just a simple React Typescript loading screen utilizing Mantine UI -## Dependencies - -- [ox_lib](https://github.com/overextended/ox_lib) (For version checking) - ## How to build ``` diff --git a/fxmanifest.lua b/fxmanifest.lua index 5b28a3a..2fcad26 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,8 +7,6 @@ description 'Just a simple React loading screen' repository 'https://github.com/mafewtm/m_loading' version '1.2.0' -shared_script '@ox_lib/init.lua' - server_script 'server/main.lua' files { diff --git a/server/main.lua b/server/main.lua index 506bc75..8b4e4ee 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1 +1,42 @@ -lib.versionCheck('mafewtm/m_loading') \ No newline at end of file +--- versionCheck functionality borrowed from ox_lib: https://github.com/overextended/ox_lib/blob/e10e8af0de655cbd8fa99c0d27840234c91828cb/resource/version/server.lua +local function versionCheck() + local resource = GetCurrentResourceName() + local currentVersion = GetResourceMetadata(resource, 'version', 0) + + 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/mafewtm/m_loading/releases/latest', 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 this resource (current version: %s)\r\n%s^0'):format(currentVersion, response.html_url)) + else + break + end + end + end + end, 'GET') + end) +end + +versionCheck() \ No newline at end of file