Fix macOS client/server failing to start from terminal
The macOS client and server were completely unusable when run from a terminal. They blocked forever in `[NSApp run];` which was called by Sys_InitProtocolHandler(). `applicationDidFinishLaunching` was never called to exit the NSApp run loop. Use SDL's SDL_DROPFILE event to receive URLs to handle on macOS instead. This also handles URLs while the game is running (connect to new server) instead of nothing happening when clicking a link while the game is running.
This commit is contained in:
1 parent
8b6333fbd3
commit
e452b7ac04
4 files changed
+29
-64
No files matched your search
@@ -34,10 +34,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#ifdef PROTOCOL_HANDLER
|
||||
char *protocolCommand = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
==============
|
||||
Sys_Dialog
|
||||
@@ -119,42 +115,3 @@ char *Sys_StripAppBundle( char *dir )
|
||||
Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
|
||||
return cwd;
|
||||
}
|
||||
|
||||
#ifdef PROTOCOL_HANDLER
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent
|
||||
{
|
||||
NSString *input = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
||||
protocolCommand = Sys_ParseProtocolUri( input.UTF8String );
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification
|
||||
{
|
||||
[NSApp stop:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
char *Sys_InitProtocolHandler( void )
|
||||
{
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
AppDelegate *appDelegate = [AppDelegate new];
|
||||
NSAppleEventManager *sharedAppleEventManager = [NSAppleEventManager new];
|
||||
[sharedAppleEventManager setEventHandler:appDelegate
|
||||
andSelector:@selector(handleAppleEvent:withReplyEvent:)
|
||||
forEventClass:kInternetEventClass
|
||||
andEventID:kAEGetURL];
|
||||
|
||||
[NSApp setDelegate:appDelegate];
|
||||
[NSApp run];
|
||||
|
||||
return protocolCommand;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user