Skip to content

Commit

Permalink
add qw:// protocol for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
fzwoch committed Dec 4, 2015
1 parent 15aa318 commit e062253
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Expand Up @@ -313,8 +313,8 @@ else
LIBS_c += -lm

ifeq ($(SYS),Darwin)
LIBS_c += -framework OpenGL -framework IOKit -framework CoreServices -ldl
OBJS_c += in_osx.o
LIBS_c += -framework Foundation -framework OpenGL -framework IOKit -framework CoreServices -ldl
OBJS_c += in_osx.o sys_osx.o
else
LIBS_c += -lGL
endif
Expand Down Expand Up @@ -387,6 +387,11 @@ $(BUILD_c)/%.o: %.c
$(Q)$(MKDIR) $(@D)
$(Q)$(CC) -c $(CFLAGS) $(CFLAGS_c) -o $@ $<

$(BUILD_c)/%.o: %.m
$(E) [CC] $@
$(Q)$(MKDIR) $(@D)
$(Q)$(CC) -c $(CFLAGS) $(CFLAGS_c) -o $@ $<

$(BUILD_c)/%.o: %.rc
$(E) [RC] $@
$(Q)$(MKDIR) $(@D)
Expand Down
7 changes: 7 additions & 0 deletions misc/install/create_osx_bundle.sh
Expand Up @@ -48,5 +48,12 @@ chmod u+x $BUNDLE_NAME/Contents/MacOS/ezquake
/usr/libexec/PlistBuddy -c "Add :CFBundleIdentifier string \"net.sf.ezquake\"" $BUNDLE_NAME/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string \"3.0.0\"" $BUNDLE_NAME/Contents/Info.plist

# qw:// protocol support
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" $BUNDLE_NAME/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" $BUNDLE_NAME/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string QW" $BUNDLE_NAME/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" $BUNDLE_NAME/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string qw" $BUNDLE_NAME/Contents/Info.plist

sh $(dirname $0)/fixbundle.sh $BUNDLE_NAME $BUNDLE_NAME/Contents/MacOS/$BINARY
ditto -c -k --keepParent --arch x86_64 $BUNDLE_NAME ezquake.zip
25 changes: 25 additions & 0 deletions sys_osx.m
@@ -0,0 +1,25 @@
#import <Foundation/Foundation.h>
#import "common.h"

@interface URL : NSObject
- (void)getURL:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)reply;
@end

@implementation URL
- (void)getURL:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)reply
{
Cbuf_AddText(va("qwurl \"%s\"\n", [[[event paramDescriptorForKeyword:keyDirectObject] stringValue] cStringUsingEncoding:NSASCIIStringEncoding]));
}
@end

static URL *url = NULL;

void init_url_handler()
{
if (url == NULL)
{
url = [[URL alloc] init];
}

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:url andSelector:@selector(getURL:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
6 changes: 6 additions & 0 deletions sys_posix.c
Expand Up @@ -97,6 +97,12 @@ void Sys_Quit(void)

void Sys_Init(void)
{
#ifdef __APPLE__
extern void init_url_handler();

init_url_handler();
#endif

Cvar_SetCurrentGroup(CVAR_GROUP_SYSTEM_SETTINGS);
Cvar_Register (&sys_yieldcpu);
Cvar_ResetCurrentGroup();
Expand Down

1 comment on commit e062253

@JosephPecoraro
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe neat!

Please sign in to comment.