From 1ad6f2c01114d5767d445ebf51237f7af07a0ddd Mon Sep 17 00:00:00 2001 From: Oleksandr Honcharov <0976053529@ukr.net> Date: Thu, 13 Jun 2024 17:20:22 +0300 Subject: [PATCH] added mp checks in cef --- cef/src/index.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/cef/src/index.ts b/cef/src/index.ts index 10b2ef5..9e56774 100644 --- a/cef/src/index.ts +++ b/cef/src/index.ts @@ -21,7 +21,9 @@ class Cef { eventName: EventName, callback: RageFW_CefCallback, ): void { - rpc.register(eventName, callback) + if ('mp' in window) { + rpc.register(eventName, callback) + } } public trigger( @@ -30,7 +32,13 @@ class Cef { ? [RageFW_CefArguments] : [] ): Promise> { - return rpc.call(eventName, args) + if ('mp' in window) { + return rpc.call(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } public triggerServer( @@ -39,7 +47,13 @@ class Cef { ? [RageFW_ServerArguments] : [] ): Promise> { - return rpc.callServer(eventName, args) + if ('mp' in window) { + return rpc.callServer(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } public triggerClient( @@ -48,7 +62,13 @@ class Cef { ? [RageFW_ClientArguments] : [] ): Promise> { - return rpc.callClient(eventName, args) + if ('mp' in window) { + return rpc.callClient(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } }