From d75b9f26f1138e60f79ee7f4b06d3aa91e14a81e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 15 Sep 2020 20:41:43 +1000 Subject: [PATCH] Callback hooks for MOAE --- v2/internal/ffenestri/ffenestri_darwin.c | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 62a8abce..3e4f9c50 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -117,8 +117,15 @@ struct Application { void messageHandler(id self, SEL cmd, id contentController, id message) { struct Application *app = (struct Application *)objc_getAssociatedObject( self, "application"); - const char *m = (const char *)msg(msg(message, s("body")), s("UTF8String")); - app->sendMessageToBackend(m); + const char *name = (const char *)msg(msg(message, s("name")), s("UTF8String")); + if( strcmp(name, "completed") == 0) { + // Delete handler + // Show window + Debug("Show window!!!!"); + } else { + const char *m = (const char *)msg(msg(message, s("body")), s("UTF8String")); + app->sendMessageToBackend(m); + } } // closeWindow is called when the close button is pressed @@ -177,11 +184,15 @@ void SetTitle(void *appPointer, const char *title) { msg(app->mainWindow, s("setTitle:"), msg(c("NSString"), s("stringWithUTF8String:"), title)); } +// fullscreenInternal sets the main window to be fullscreen +void fullscreenInternal(void *appPointer) { + Debug("Fullscreen Called"); + struct Application *app = (struct Application*) appPointer; + msg(app->mainWindow, s("toggleFullScreen:")); +} // Fullscreen sets the main window to be fullscreen void Fullscreen(void *appPointer) { - Debug("Fullscreen Called"); - // struct Application *app = (struct Application*) appPointer; - // gtk_window_fullscreen (app->mainWindow); + execOnMainThread(appPointer, fullscreenInternal, NULL); } // UnFullscreen resets the main window after a fullscreen @@ -696,6 +707,7 @@ void Run(void *applicationPointer, int argc, char **argv) { msg(wkwebview, s("initWithFrame:configuration:"), CGRectMake(0, 0, 0, 0), config); msg(manager, s("addScriptMessageHandler:name:"), delegate, str("external")); + msg(manager, s("addScriptMessageHandler:name:"), delegate, str("completed")); msg(mainWindow, s("setContentView:"), wkwebview); msg(mainWindow, s("makeKeyAndOrderFront:"), NULL); // msg(mainWindow, s("setHidden:"), true); @@ -737,6 +749,11 @@ void Run(void *applicationPointer, int argc, char **argv) { // Debug("MOAE: %s", internalCode); + // Include callback after evaluation + temp = concat(internalCode, "webkit.messageHandlers.completed.postMessage(true);"); + free((void*)internalCode); + internalCode = temp; + // This evaluates the MOAE once the Dom has finished loading msg(manager, s("addUserScript:"),