diff --git a/Makefile b/Makefile index a1f3c46a5a4fd0ccbbbb77b58cce5c448554cc76..30913fbf2904387a8fbe19f80ffd1b04c0eb20e9 100644 --- a/Makefile +++ b/Makefile @@ -28,10 +28,7 @@ all: LUA = lua-5.2.1/src LUA_FLAGS = -DUSE_LUA -I$(LUA) -L$(LUA) -llua -lm -GCC_WARNS = -W -Wall -pedantic -CFLAGS = -std=c99 -O2 $(GCC_WARNS) $(COPT) -MAC_SHARED = -flat_namespace -bundle -undefined suppress -LINFLAGS = -ldl -pthread $(CFLAGS) +CFLAGS = -std=c99 -O2 -W -Wall -pedantic $(COPT) LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX) # Make sure that the compiler flags come last in the compilation string. @@ -39,20 +36,20 @@ LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX) # "-Wl,--as-needed" turned on by default in cc command. # Also, this is turned in many other distros in static linkage builds. linux: - $(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) $(LINFLAGS) - $(CC) mongoose.c main.c -o $(PROG) $(LINFLAGS) + $(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) -ldl -pthread $(CFLAGS) + $(CC) mongoose.c main.c -o $(PROG) -ldl -pthread $(CFLAGS) bsd: $(CC) mongoose.c -shared -pthread -fpic -fPIC -o $(LIB) $(CFLAGS) $(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS) mac: - $(CC) mongoose.c -pthread -o $(LIB) $(MAC_SHARED) $(CFLAGS) - $(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS) + $(CC) mongoose.c -pthread -o $(LIB) -flat_namespace -bundle -undefined suppress $(CFLAGS) + $(CC) mongoose.c main.c -DUSE_COCOA -pthread $(CFLAGS) -framework Cocoa -ObjC -arch i386 -arch x86_64 -o $(PROG) + V=`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' mongoose.c`; DIR=dmg/$(PROG).app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 build/mongoose_*.png $$DIR/Contents/Resources/ && install -m 644 build/Info.plist $$DIR/Contents/ && install -m 755 $(PROG) $$DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create $(PROG)_$$V.dmg -volname "Mongoose $$V" -srcfolder dmg -ov #; rm -rf dmg solaris: - $(CC) mongoose.c -pthread -lnsl \ - -lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS) + $(CC) mongoose.c -pthread -lnsl -lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS) $(CC) mongoose.c main.c -pthread -lnsl -lsocket -o $(PROG) $(CFLAGS) diff --git a/build/Info.plist b/build/Info.plist index 91b4e144ade61536b4017b2261f552f1957f31a7..6747ac3a58e59326fbf27f166e404085f29cfc90 100644 --- a/build/Info.plist +++ b/build/Info.plist @@ -2,7 +2,17 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> - <key>CFBundleIconFile</key> <string>mongoose_16x16.png</string> - <key>LSUIElement</key> <true/> + <key>CFBundleExecutable</key> + <string>mongoose</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleTypeRole</key> + <string>None</string> + <key>CFBundleIconFiles</key> + <array> + <string>mongoose_16x16.png</string> + </array> + <key>LSUIElement</key> + <true/> </dict> </plist> diff --git a/main.c b/main.c index b8c2285efc1991c29565fb63ee395da4d7828c09..3dab9c018b79bc0c41bf7f826400fca76a5194f6 100644 --- a/main.c +++ b/main.c @@ -490,6 +490,87 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) { // Return the WM_QUIT value. return msg.wParam; } +#elif defined(USE_COCOA) +#import <Cocoa/Cocoa.h> + +@interface Mongoose : NSObject<NSApplicationDelegate> +- (void) openBrowser; +- (void) shutDown; +@end + +@implementation Mongoose +- (void) openBrowser { + [[NSWorkspace sharedWorkspace] + openURL:[NSURL URLWithString: + [NSString stringWithUTF8String:"http://www.yahoo.com"]]]; +} +- (void) editConfig { + [[NSWorkspace sharedWorkspace] + openFile:@"mongoose.conf" withApplication:@"TextEdit"]; +} +- (void)shutDown{ + [NSApp terminate:nil]; +} +@end + +int main(int argc, char *argv[]) { + init_server_name(); + start_mongoose(argc, argv); + + [NSAutoreleasePool new]; + [NSApplication sharedApplication]; + + // Add delegate to process menu item actions + Mongoose *myDelegate = [[Mongoose alloc] autorelease]; + [NSApp setDelegate: myDelegate]; + + // Run this app as agent + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToBackgroundApplication); + SetFrontProcess(&psn); + + // Add status bar menu + id menu = [[NSMenu new] autorelease]; + + // Add version menu item + [menu addItem:[[[NSMenuItem alloc] + //initWithTitle:[NSString stringWithFormat:@"%s", server_name] + initWithTitle:[NSString stringWithUTF8String:server_name] + action:@selector(noexist) keyEquivalent:@""] autorelease]]; + + // Add configuration menu item + [menu addItem:[[[NSMenuItem alloc] + initWithTitle:@"Edit configuration" + action:@selector(editConfig) keyEquivalent:@""] autorelease]]; + + // Add connect menu item + [menu addItem:[[[NSMenuItem alloc] + initWithTitle:@"Open web root in a browser" + action:@selector(openBrowser) keyEquivalent:@""] autorelease]]; + + // Separator + [menu addItem:[NSMenuItem separatorItem]]; + + // Add quit menu item + [menu addItem:[[[NSMenuItem alloc] + initWithTitle:@"Quit" + action:@selector(shutDown) keyEquivalent:@"q"] autorelease]]; + + // Attach menu to the status bar + id item = [[[NSStatusBar systemStatusBar] + statusItemWithLength:NSVariableStatusItemLength] retain]; + [item setHighlightMode:YES]; + [item setImage:[NSImage imageNamed:@"mongoose_22x22.png"]]; + [item setMenu:menu]; + + // Run the app + [NSApp activateIgnoringOtherApps:YES]; + [NSApp run]; + + mg_stop(ctx); + + return EXIT_SUCCESS; +} #else int main(int argc, char *argv[]) { init_server_name();