From ae83cff7d4b0afd285064bdb2ae43a37eeddbb42 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 13 Feb 2018 10:04:01 -0800 Subject: Added the information dialog box when the app cannot run on Mac --- .../Apple/Source/Classes/OSX/AppDelegate.m | 14 ++++++- Common/NativeApp/Apple/Source/Classes/OSX/GLView.h | 1 + Common/NativeApp/Apple/Source/Classes/OSX/GLView.m | 47 +++++++++++++++++----- 3 files changed, 50 insertions(+), 12 deletions(-) (limited to 'Common/NativeApp') diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m b/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m index 3359ea6..3eb1f46 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m +++ b/Common/NativeApp/Apple/Source/Classes/OSX/AppDelegate.m @@ -16,8 +16,20 @@ @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application NSWindow* mainWindow = [[NSApplication sharedApplication]mainWindow]; + + NSString* error = [[mainWindow contentView] getError]; + if(error != nil) + { + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"OK"]; + [alert setMessageText:@"Failed to start the application"]; + [alert setInformativeText:error]; + [alert setAlertStyle:NSAlertStyleCritical]; + [alert runModal]; + [NSApp terminate:self]; + } + [mainWindow setAcceptsMouseMovedEvents:YES]; NSString *Name = [[mainWindow contentView] getAppName]; [mainWindow setTitle:Name]; diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h index bf12ce0..993334d 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h +++ b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.h @@ -17,5 +17,6 @@ -(void)stopDisplayLink; -(void)startDisplayLink; -(NSString*)getAppName; +- (NSString*)getError; @end diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m index e239bca..ab99afc 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m +++ b/Common/NativeApp/Apple/Source/Classes/OSX/GLView.m @@ -7,6 +7,7 @@ */ #include +#include #import "GLView.h" #include "NativeAppBase.h" @@ -17,6 +18,7 @@ { std::unique_ptr _theApp; NSRect _viewRectPixels; + std::string _error; } @end @@ -148,7 +150,15 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // Init the application. - _theApp->OnGLContextCreated(); + try + { + _theApp->OnGLContextCreated(); + } + catch(std::runtime_error &err) + { + _error = err.what(); + _theApp.reset(); + } } - (void)reshape @@ -192,7 +202,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, #endif // !SUPPORT_RETINA_RESOLUTION // Set the new dimensions in our renderer - _theApp->WindowResize(_viewRectPixels.size.width, _viewRectPixels.size.height); + if(_theApp) + _theApp->WindowResize(_viewRectPixels.size.width, _viewRectPixels.size.height); CGLUnlockContext([[self openGLContext] CGLContextObj]); } @@ -230,8 +241,11 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, // simultaneously when resizing CGLLockContext([[self openGLContext] CGLContextObj]); - _theApp->Update(); - _theApp->Render(); + if(_theApp) + { + _theApp->Update(); + _theApp->Render(); + } CGLFlushDrawable([[self openGLContext] CGLContextObj]); CGLUnlockContext([[self openGLContext] CGLContextObj]); @@ -256,27 +270,32 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, #if SUPPORT_RETINA_RESOLUTION curPoint = [self convertPointToBacking:curPoint]; #endif - _theApp->OnMouseMove(curPoint.x, _viewRectPixels.size.height-1 - curPoint.y); + if(_theApp) + _theApp->OnMouseMove(curPoint.x, _viewRectPixels.size.height-1 - curPoint.y); } - (void)mouseDown:(NSEvent *)theEvent { [self mouseMove: theEvent]; - _theApp->OnMouseDown(1); + if(_theApp) + _theApp->OnMouseDown(1); } - (void)mouseUp:(NSEvent *)theEvent { [self mouseMove: theEvent]; - _theApp->OnMouseUp(1); + if(_theApp) + _theApp->OnMouseUp(1); } - (void)rightMouseDown:(NSEvent *)theEvent { [self mouseMove: theEvent]; - _theApp->OnMouseDown(3); + if(_theApp) + _theApp->OnMouseDown(3); } - (void)rightMouseUp:(NSEvent *)theEvent { [self mouseMove: theEvent]; - _theApp->OnMouseUp(3); + if(_theApp) + _theApp->OnMouseUp(3); } - (void)mouseMoved:(NSEvent *)theEvent { @@ -296,7 +315,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, case 0x7F: key = '\b'; break; default: key = c; } - _theApp->OnKeyPressed(key); + if(_theApp) + _theApp->OnKeyPressed(key); [super keyDown:theEvent]; } @@ -317,7 +337,12 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, - (NSString*)getAppName { - return [NSString stringWithFormat:@"%s", _theApp->GetAppTitle()]; + return [NSString stringWithFormat:@"%s", _theApp ? _theApp->GetAppTitle() : ""]; +} + +- (NSString*)getError +{ + return _error.empty() ? nil : [NSString stringWithFormat:@"%s", _error.c_str()]; } @end -- cgit v1.2.3