5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-10 22:19:46 +08:00

Semi runs

This commit is contained in:
Lea Anthony 2020-09-11 22:48:35 +10:00 committed by Travis McLane
parent e831bc75c6
commit f25abb0b26
No known key found for this signature in database
GPG Key ID: 7BA828AE61CD949B
2 changed files with 90 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -51,6 +51,7 @@ BOOL yes(id self, SEL cmd)
return YES;
}
// Debug works like sprintf but mutes if the global debug flag is true
// Credit: https://stackoverflow.com/a/20639708
void Debug(char *message, ... ) {
@ -66,6 +67,12 @@ void Debug(char *message, ... ) {
}
}
void messageHandler(id self, SEL cmd, id contentController, id msg) {
// TODO: Pass message to callback in application object
Debug("TODO: Process message");
}
extern void messageFromWindowCallback(const char *);
typedef void (*ffenestriCallback)(const char *);
@ -684,12 +691,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
class_addProtocol(delegateClass, objc_getProtocol("NSTouchBarProvider"));
class_addMethod(delegateClass, s("applicationShouldTerminateAfterLastWindowClosed:"), (IMP) yes, "c@:@");
// TODO: add userContentController:didReceiveScriptMessage
class_addMethod(delegateClass, s("userContentController:didReceiveScriptMessage:"),
(IMP)(^(id self, SEL cmd, id contentController, id msg) {
// const char *m = (const char *)msg(msg(message, s("body")), s("UTF8String"));
// Debug("*** didReceiveScriptMessage: %p", message);
Debug("Hi!");
}),
class_addMethod(delegateClass, s("userContentController:didReceiveScriptMessage:"), (IMP) messageHandler,
"v@:@@");
objc_registerClassPair(delegateClass);
@ -736,25 +738,11 @@ void Run(void *applicationPointer, int argc, char **argv) {
// We want to evaluate the internal code plus runtime before the assets
const char *temp = concat(invoke, app->bindings);
const char *internalCode = concat(temp, (const char*)&runtime);
Debug("Internal code: %s", internalCode);
// Debug("Internal code: %s", internalCode);
free((void*)temp);
// Evaluate internal code
msg(wkwebview, s("evaluateJavaScript:completionHandler:"),
msg(c("NSString"), s("stringWithUTF8String:"), (char*)internalCode), ^(id result, void *error) {
Debug("Result: %p", result);
Debug("Error: %p", error);
// Free internalCode memory
free((void*)internalCode);
/*
if( error != NULL) {
Debug("Error message: %s", error);
return;
}
*/
// Loop over assets
int index = 0;
int index = 1;
while(1) {
// Get next asset pointer
const unsigned char *asset = assets[index];
@ -764,11 +752,36 @@ void Run(void *applicationPointer, int argc, char **argv) {
break;
}
// sync eval the asset
ExecJS(app, (char*)asset);
temp = concat(internalCode, asset);
free((void*)internalCode);
internalCode = temp;
index++;
};
Debug("MOAE: %s", internalCode);
// Evaluate internal code
// ---------------------------------------------------------------
// TODO: WORK OUT WHY EXECUTING THE INTERNAL CODE BLOWS THE APP UP
// ---------------------------------------------------------------
msg(wkwebview,
s("evaluateJavaScript:completionHandler:"),
msg(c("NSString"), s("stringWithUTF8String:"), (char*)internalCode),
^() {
// Debug("Result: %p", result);
// Debug("Error: %p", error);
// Free internalCode memory
// free((void*)internalCode);
/*
if( error != NULL) {
Debug("Error message: %s", error);
return;
}
*/
Debug("DO I CARE?");
}
);