diff --git a/phone/src/index.tsx b/phone/src/index.tsx index aa60ebf..98824a8 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -8,6 +8,7 @@ import { Integrations } from '@sentry/tracing'; import './main.css'; import PhoneConfig from './config/default.json'; import { PhoneContainer } from './PhoneContainer'; +import attachMockNuiEvent from './os/debug/AttachMockNuiEvent'; // Enable Sentry when config setting is true if (PhoneConfig.SentryErrorMetrics) { @@ -21,6 +22,8 @@ if (PhoneConfig.SentryErrorMetrics) { }); } +attachMockNuiEvent(); + ReactDOM.render( diff --git a/phone/src/os/debug/AttachMockNuiEvent.ts b/phone/src/os/debug/AttachMockNuiEvent.ts new file mode 100644 index 0000000..cec7fcc --- /dev/null +++ b/phone/src/os/debug/AttachMockNuiEvent.ts @@ -0,0 +1,32 @@ +function dispatchEvent({ method, app, data }: { method: string; app: string; data: unknown }) { + setTimeout(() => { + window.dispatchEvent( + new MessageEvent('message', { + data: { + app, + method, + data, + }, + }), + ); + }, 200); +} +/** + * Allows you to mock NUI data from your console by attaching + * to the global window object + * @example + * mockNuiEvent({ + * app: 'NOTES', + * method: 'setAlert', + * data: { + * message: 'CONTACT_ADD_SUCCESS', + * type: 'success', + * } + * }) + **/ +const attachMockNuiEvent = () => { + //@ts-ignore + window.mockNuiEvent = dispatchEvent; +}; + +export default attachMockNuiEvent;