mirror of
https://github.com/cesanta/mongoose.git
synced 2025-07-25 22:56:16 +08:00
Initial version for the Macos app bundle
This commit is contained in:
parent
bde9a63390
commit
38cc14a1af
17
Makefile
17
Makefile
@ -28,10 +28,7 @@ all:
|
|||||||
LUA = lua-5.2.1/src
|
LUA = lua-5.2.1/src
|
||||||
LUA_FLAGS = -DUSE_LUA -I$(LUA) -L$(LUA) -llua -lm
|
LUA_FLAGS = -DUSE_LUA -I$(LUA) -L$(LUA) -llua -lm
|
||||||
|
|
||||||
GCC_WARNS = -W -Wall -pedantic
|
CFLAGS = -std=c99 -O2 -W -Wall -pedantic $(COPT)
|
||||||
CFLAGS = -std=c99 -O2 $(GCC_WARNS) $(COPT)
|
|
||||||
MAC_SHARED = -flat_namespace -bundle -undefined suppress
|
|
||||||
LINFLAGS = -ldl -pthread $(CFLAGS)
|
|
||||||
LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX)
|
LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX)
|
||||||
|
|
||||||
# Make sure that the compiler flags come last in the compilation string.
|
# 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.
|
# "-Wl,--as-needed" turned on by default in cc command.
|
||||||
# Also, this is turned in many other distros in static linkage builds.
|
# Also, this is turned in many other distros in static linkage builds.
|
||||||
linux:
|
linux:
|
||||||
$(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) $(LINFLAGS)
|
$(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) -ldl -pthread $(CFLAGS)
|
||||||
$(CC) mongoose.c main.c -o $(PROG) $(LINFLAGS)
|
$(CC) mongoose.c main.c -o $(PROG) -ldl -pthread $(CFLAGS)
|
||||||
|
|
||||||
bsd:
|
bsd:
|
||||||
$(CC) mongoose.c -shared -pthread -fpic -fPIC -o $(LIB) $(CFLAGS)
|
$(CC) mongoose.c -shared -pthread -fpic -fPIC -o $(LIB) $(CFLAGS)
|
||||||
$(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
|
$(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
|
||||||
|
|
||||||
mac:
|
mac:
|
||||||
$(CC) mongoose.c -pthread -o $(LIB) $(MAC_SHARED) $(CFLAGS)
|
$(CC) mongoose.c -pthread -o $(LIB) -flat_namespace -bundle -undefined suppress $(CFLAGS)
|
||||||
$(CC) mongoose.c main.c -pthread -o $(PROG) $(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:
|
solaris:
|
||||||
$(CC) mongoose.c -pthread -lnsl \
|
$(CC) mongoose.c -pthread -lnsl -lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS)
|
||||||
-lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS)
|
|
||||||
$(CC) mongoose.c main.c -pthread -lnsl -lsocket -o $(PROG) $(CFLAGS)
|
$(CC) mongoose.c main.c -pthread -lnsl -lsocket -o $(PROG) $(CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,17 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleIconFile</key> <string>mongoose_16x16.png</string>
|
<key>CFBundleExecutable</key>
|
||||||
<key>LSUIElement</key> <true/>
|
<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>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
81
main.c
81
main.c
@ -490,6 +490,87 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
|
|||||||
// Return the WM_QUIT value.
|
// Return the WM_QUIT value.
|
||||||
return msg.wParam;
|
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
|
#else
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
init_server_name();
|
init_server_name();
|
||||||
|
Loading…
Reference in New Issue
Block a user