This commit is contained in:
Lorraxs 2024-01-02 10:50:35 +07:00
parent 77dc46460b
commit 796cd23e8d
9 changed files with 50 additions and 69 deletions

View File

@ -1,10 +0,0 @@
local Impl = NewImpl("Newbie")
function Impl:Init()
main:LogInfo("%s initialized", self:GetName())
end
function Impl:OnReady()
main:LogInfo("%s ready", self:GetName())
end

View File

@ -1,39 +0,0 @@
local Impl = NewImpl("Test2")
function Impl:OnReady()
self:MainThread()
self:TestHook()
self:TestReplaceMethod()
end
function Impl:MainThread()
local testImpl = main:GetImpl("Test")
Citizen.CreateThread(function()
while true do
Wait(1000)
local result = testImpl:Add(1, 2)
main:LogInfo("TestImpl result %s", result)
end
end)
end
function Impl:TestHook()
local testImpl = main:GetImpl("Test")
testImpl:HookMethod("Add", function(self, amount, amount2)
return amount+1, amount2
end)
end
function Impl:TestReplaceMethod()
Citizen.CreateThread(function()
Wait(5000)
local testImpl = main:GetImpl("Test")
local oldMethod = testImpl:GetMethod("Add")
testImpl:ReplaceMethod("Add", function(self, amount, amount2)
self.testVar = self.testVar * amount * amount2
return self.testVar
end)
Wait(5000)
testImpl:ReplaceMethod("Add", oldMethod)
end)
end

View File

@ -1,4 +1,10 @@
Config = {}
Config.UISetting = {
locale = {}
}
--Dont touch this
Config.EnableModules = {
["Newbie"] = {
enabled = true,
@ -13,4 +19,5 @@ Config.EnableModules = {
Config.Debug = true
Config.Nui = false
Config.Dev = false
Config.Framework = "esx" -- "qb" | "ProjectStarboy"
Config.Framework = "custom" -- "qb" | "esx" | "custom"
Config.ClientLazyLoad = false

View File

@ -20,7 +20,7 @@ if IsDuplicityVersion() then
end
else
RegisterNUICallback('AppReady', function(data, cb)
cb({})
cb(Config.UISetting or {})
NuiReady = true
end)
end

View File

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { createContext, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { AppActions, RootState } from './store';
import { ToastContainer } from 'react-toastify';
@ -7,18 +7,24 @@ import { NextUIProvider } from '@nextui-org/react';
import AppActionHook from './components/AppActionHook';
import { isEnvBrowser } from './utils/misc';
import { fetchNui } from './utils/fetchNui';
import { DefaultUISetting, ISettingContext, UISetting } from './types';
const SettingContext = createContext<ISettingContext>(DefaultUISetting);
function App() {
const show = useSelector((state: RootState) => state.main.show);
const [setting, setSetting] = useState<UISetting>({ locale: {} });
const L = (key: string) => setting.locale[key] || key;
useEffect(() => {
if (!isEnvBrowser()) {
setTimeout(() => {
fetchNui('AppReady');
setTimeout(async () => {
const UISetting = await fetchNui<UISetting>('AppReady');
setSetting(UISetting);
}, 2000);
}
}, []);
}, [setSetting]);
return (
show && (
<SettingContext.Provider value={{ setting, setSetting, L }}>
<NextUIProvider>
<Box
display='flex'
@ -39,6 +45,7 @@ function App() {
);
})}
</Box>
{show && (
<Box
width={'100%'}
height={'100%'}
@ -48,10 +55,10 @@ function App() {
className='prose'
pointerEvents='none'
></Box>
)}
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
</NextUIProvider>
)
</SettingContext.Provider>
);
}

View File

@ -11,7 +11,6 @@ interface Props {
function AppActionHook(props: Props) {
const dispatch = useDispatch<AppDispatch>();
const isDev = isEnvBrowser();
console.log('AppActionHook', props.action);
useNuiEvent(props.action, (data) => {
//dynamicDispatch(action, data);
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -1 +1,2 @@
export * from './redux.type';
export * from './setting.type';

View File

@ -0,0 +1,16 @@
export interface ISettingContext {
setting: UISetting;
setSetting: (setting: UISetting) => void;
L: (key: string) => string;
}
export interface UISetting {
locale: { [key: string]: string };
}
export const DefaultUISetting: ISettingContext = {
setting: {
locale: {},
},
setSetting: () => {},
L: (key: string) => key,
};