Forked from karstenBriksoft/bundlelessApplication.m
Created
February 11, 2021 08:18
-
-
Save bubach/62b611a89d433346e16e9042d3d5778e to your computer and use it in GitHub Desktop.
NSApplication without Bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compile using: clang -fobjc-arc -framework AppKit bundlelessApplication.m -o bundleLess | |
// | |
// opens a NSApplication with dock icon and menu bar. NSRunningApplication will return no bundleURL for it | |
// | |
// via http://stackoverflow.com/questions/8137538/cocoa-applications-from-the-command-line | |
// and http://casperbhansen.wordpress.com/2010/08/15/dev-tip-nibless-development/ | |
#import <Foundation/Foundation.h> | |
#import <Cocoa/Cocoa.h> | |
@interface AppDelegate : NSObject | |
@property (retain) NSWindow * window; | |
@property (retain) NSView * view; | |
@end | |
@implementation AppDelegate | |
- (id)init { | |
if ( self = [super init] ) { | |
// create a reference rect | |
NSRect contentSize = NSMakeRect(0.0f, 0.0f, 480.0f, 320.0f); | |
// allocate window | |
self.window = [[NSWindow alloc] initWithContentRect:contentSize styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES]; | |
// allocate view | |
self.view = [[NSView alloc] initWithFrame:contentSize]; | |
} | |
return self; | |
} | |
- (void)applicationWillFinishLaunching:(NSNotification *)notification { | |
// attach the view to the window | |
[self.window setContentView:self.view]; | |
} | |
- (void)applicationDidFinishLaunching:(NSNotification *)notification { | |
// make the window visible. | |
[self.window makeKeyAndOrderFront:self]; | |
} | |
@end | |
int main(int argc, char *argv[]) | |
{ | |
// create an autorelease pool | |
@autoreleasepool { | |
// make sure the application singleton has been instantiated | |
NSApplication * application = [NSApplication sharedApplication]; | |
// instantiate our application delegate | |
AppDelegate * applicationDelegate = [[AppDelegate alloc] init]; | |
// assign our delegate to the NSApplication | |
[application setDelegate:applicationDelegate]; | |
ProcessSerialNumber psn = { 0, kCurrentProcess }; | |
OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication); | |
[NSApp activateIgnoringOtherApps:YES]; | |
// call the run method of our application | |
[application run]; | |
} | |
// execution never gets here .. | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment