Created
September 8, 2011 17:07
-
-
Save TooTallNate/1203944 to your computer and use it in GitHub Desktop.
Creating a Cocoa GUI window with NodObjC, with a proper Menu, dock icon, and NSApplicationDelegate.
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
// This example adapted from Matt Gallagher's "Minimalist Cocoa Programming" | |
// blog article: | |
// http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html | |
var $ = require('NodObjC') | |
$.import('Cocoa') | |
var pool = $.NSAutoreleasePool('alloc')('init') | |
, app = $.NSApplication('sharedApplication') | |
app('setActivationPolicy', $.NSApplicationActivationPolicyRegular) | |
var menuBar = $.NSMenu('alloc')('init')('autorelease') | |
, appMenuItem = $.NSMenuItem('alloc')('init')('autorelease') | |
menuBar('addItem', appMenuItem) | |
app('setMainMenu', menuBar) | |
var appMenu = $.NSMenu('alloc')('init')('autorelease') | |
, appName = $('Hello NodeJS!') | |
, quitTitle = $('Quit ')('stringByAppendingString', appName) | |
, quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle | |
,'action', 'terminate:' | |
,'keyEquivalent', $('q'))('autorelease') | |
appMenu('addItem', quitMenuItem) | |
appMenuItem('setSubmenu', appMenu) | |
var styleMask = $.NSTitledWindowMask | |
| $.NSResizableWindowMask | |
| $.NSClosableWindowMask | |
var window = $.NSWindow('alloc')('initWithContentRect', $.NSMakeRect(0,0,200,200) | |
,'styleMask', styleMask | |
,'backing', $.NSBackingStoreBuffered | |
,'defer', false)('autorelease') | |
window('cascadeTopLeftFromPoint', $.NSMakePoint(20,20)) | |
window('setTitle', appName) | |
window('makeKeyAndOrderFront', window) | |
// set up the app delegate | |
var AppDelegate = $.NSObject.extend('AppDelegate') | |
AppDelegate.addMethod('applicationDidFinishLaunching:', 'v@:@', function (self, _cmd, notif) { | |
console.log('got applicationDidFinishLauching') | |
console.log(notif) | |
}) | |
AppDelegate.register() | |
var delegate = AppDelegate('alloc')('init') | |
app('setDelegate', delegate) | |
app('activateIgnoringOtherApps', true) | |
app('run') |
boom! better irc client here we come
the last line > app('run') > results in a "bus error 10".
So What do I wrong?
I am on a quite new MacBookPro, Mountain Lion, latest versions of node and nodObjC.
so I could narrow it. It is related to AppDelegate.addMethod(). without that code, it works at least without crashing with a "bus error 10". Any ideas?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results in: