feat(phone/debug): Added a global window dispatch method

See JSDocs for usage details.
This commit is contained in:
Taso committed 2021-03-03 21:48:45 -05:00
1 parent 622a931ace
commit b6352ccf82
2 files changed
+35

No files matched your search

+3
View File
@@ -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(
<HashRouter>
<RecoilRoot>
+32
View File
@@ -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;