This commit is contained in:
Lorraxs 2023-12-13 00:21:40 +07:00
parent eaba4d56f2
commit 2a5bea33b4
4 changed files with 70 additions and 19 deletions

View File

@ -1,10 +1,16 @@
Config = {}
Config.EnableModules = {
["Newbie"] = false,
["Test"] = true,
["Test2"] = true,
["Newbie"] = {
enabled = true,
client = true, -- enable client side
priority = 1, -- 1 : init on start | 2 : init on player loaded
},
["Test"] = {
enabled = true,
priority = 2, -- 1 : init on start | 2 : init on player loaded
},
}
Config.Debug = true
Config.Nui = false
Config.Dev = false
Config.Framework = "esx" -- "qb" | "ProjectStarboy"
Config.Framework = "esx" -- "qb" | "ProjectStarboy"

View File

@ -174,7 +174,7 @@ function Main:CheckValidImpl(name, impl)
end
function Main:RegisterImpl(name, impl)
if not Config.EnableModules[name] then
if Config.EnableModules[name] == nil or not Config.EnableModules[name].enabled then
self:LogWarning("Impl %s not enabled", name)
return
end
@ -207,7 +207,7 @@ end
function Main:InitImpl()
if not IsDuplicityVersion() then
for k, v in pairs(Config.EnableModules) do
if v then
if v.enabled and v.priority == 1 and v.client then
self:LogInfo("Loading %s", k)
local source = lib.callback.await(ResourceName..":getClientImpl", false, k)
if source ~= nil then
@ -216,16 +216,51 @@ function Main:InitImpl()
end
end
end
for name, impl in pairs(self.impls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 1 then
self.initializedImpls[name] = impl(self)
end
end
self:LogInfo("All priority 1 initialized")
for name, impl in pairs(self.initializedImpls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 1 then
impl:OnReady()
end
end
else
for name, impl in pairs(self.impls) do
self.initializedImpls[name] = impl(self)
end
for name, impl in pairs(self.initializedImpls) do
impl:OnReady()
end
end
for name, impl in pairs(self.impls) do
self.initializedImpls[name] = impl(self)
end
self:LogInfo("All impls initialized")
self.ready = true
for name, impl in pairs(self.initializedImpls) do
impl:OnReady()
end
if not IsDuplicityVersion() then
end
function Main:InitImplAfterPlayerLoaded()
if not IsDuplicityVersion() then
for k, v in pairs(Config.EnableModules) do
if v.enabled and v.priority == 2 and v.client then
self:LogInfo("Loading %s", k)
local source = lib.callback.await(ResourceName..":getClientImpl", false, k)
if source ~= nil then
self:LogInfo("Loaded %s", k)
load(source)()
end
end
end
for name, impl in pairs(self.impls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 2 then
self.initializedImpls[name] = impl(self)
end
end
self:LogInfo("All priority 2 initialized")
for name, impl in pairs(self.initializedImpls) do
if Config.EnableModules[name] and Config.EnableModules[name].priority == 2 then
impl:OnReady()
end
end
SendNUIMessage({
action = "updateServerState",
data = {
@ -233,7 +268,7 @@ function Main:InitImpl()
}
})
end
self.ready = true
end
function Main:GetImpl(name)
@ -301,6 +336,7 @@ Citizen.CreateThread(function()
main:LogInfo("Waiting for Framework")
Wait(100)
end
main:InitImpl()
if not IsDuplicityVersion() then
if Config.Framework == 'esx' then
while not Framework.IsPlayerLoaded() do
@ -317,5 +353,5 @@ Citizen.CreateThread(function()
Wait(100)
end
end
main:InitImpl()
main:InitImplAfterPlayerLoaded()
end)

File diff suppressed because one or more lines are too long

View File

@ -1,13 +1,22 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Provider, useSelector } from 'react-redux';
import { AppActions, RootState, store } from './store';
import { ToastContainer } from 'react-toastify';
import { Box } from 'lr-components';
import { NextUIProvider } from '@nextui-org/react';
import AppActionHook from './components/AppActionHook';
import { isEnvBrowser } from './utils/misc';
import { fetchNui } from './utils/fetchNui';
function App() {
const show = useSelector((state: RootState) => state.state.show);
useEffect(() => {
if (!isEnvBrowser()) {
setTimeout(() => {
fetchNui('AppReady');
}, 2000);
}
}, []);
return (
show && (
<NextUIProvider>