From b59afc383d66c657671ed8e2acc2f9b6269a496c Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 24 Sep 2013 09:53:44 +0200 Subject: wx: Fix initializations on mac osx Remove dummy windows and move the console to gui app code before wxWidgets gets initialized to prevent hangings on current wxWidgets svn version. --- lib/wx/c_src/wxe_ps_init.c | 59 +++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'lib/wx/c_src/wxe_ps_init.c') diff --git a/lib/wx/c_src/wxe_ps_init.c b/lib/wx/c_src/wxe_ps_init.c index 541d188098..7c3e820e40 100644 --- a/lib/wx/c_src/wxe_ps_init.c +++ b/lib/wx/c_src/wxe_ps_init.c @@ -19,6 +19,7 @@ #include #include "wxe_driver.h" + /* Platform specific initialisation stuff */ #ifdef _MACOSX @@ -30,34 +31,54 @@ extern OSErr CPSSetProcessName (ProcessSerialNumber *psn, char *processname); void * wxe_ps_init() { ProcessSerialNumber psn; - NSAutoreleasePool *pool; // Enable GUI - GetCurrentProcess(&psn); - char *app_title = getenv("WX_APP_TITLE"); - // Undocumented function (but no documented way of doing this exists) - CPSSetProcessName(&psn, app_title?app_title:"Erlang"); - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - SetFrontProcess(&psn); - // Enable Cocoa calls from Carbon app - NSApplicationLoad(); + if(!GetCurrentProcess(&psn)) { + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + SetFrontProcess(&psn); + } + return (void *) 0; +} + +int is_packaged_app() { + // Can get lost in when execing around, we use the name instead + /* if(mainBundle) { */ + /* return (CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("CFBundlePackageType")) != nil); */ + /* } */ + NSString * appName = [[NSRunningApplication currentApplication] localizedName]; + return (strncmp("beam", [appName UTF8String], 4) != 0); +} + +void * wxe_ps_init2() { + NSAutoreleasePool *pool; + ProcessSerialNumber psn; // Setup and enable gui pool = [[NSAutoreleasePool alloc] init]; - - NSApplication *app = [NSApplication sharedApplication]; - // Load and set icon - NSMutableString *file = [[NSMutableString alloc] init]; - [file appendFormat:@"%s/%s", erl_wx_privdir, "erlang-logo64.png"]; - NSImage *icon = [[NSImage alloc] initWithContentsOfFile: file]; - [app setApplicationIconImage: icon]; + if( !is_packaged_app() ) { + // Undocumented function (but no documented way of doing this exists) + char *app_title = getenv("WX_APP_TITLE"); + if(!GetCurrentProcess(&psn)) { + CPSSetProcessName(&psn, app_title?app_title:"Erlang"); + } + // Load and set icon + NSMutableString *file = [[NSMutableString alloc] init]; + [file appendFormat:@"%s/%s", erl_wx_privdir, "erlang-logo64.png"]; + NSImage *icon = [[NSImage alloc] initWithContentsOfFile: file]; + [NSApp setApplicationIconImage: icon]; + }; - return (void *) pool; + return pool; } + /* _MACOSX */ #else -void * wxe_ps_init() +void * wxe_ps_init() +{ + return (void *) 0; +} +void * wxe_ps_init2() { return (void *) 0; } -#endif +#endif -- cgit v1.2.3