ブロック使うAPIだった。
var snd = $.NSSound('soundNamed',$('Hero'));
snd('play');
var fs = require('fs')
var logfile = __filename + '.log'
fs.closeSync(2)
var fd = fs.openSync(logfile, 'w')
// This example adapted from Matt Gallagher's "Minimalist Cocoa Programming"
// blog article:
// http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
var $ = require('../../../../')
$.import('Cocoa')
var pool = $.NSAutoreleasePool('alloc')('init')
, app = $.NSApplication('sharedApplication')
app('setActivationPolicy', $.NSApplicationActivationPolicyRegular)
menuBar('addItem', appMenuItem)
app('setMainMenu', menuBar)
var appMenu = $.NSMenu('alloc')('init')
, appName = $('Hello NodeJS!')
, quitTitle = $('Quit "' + appName + '"')
, quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle
,'action', 'terminate:'
,'keyEquivalent', $('q'))
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)
window('cascadeTopLeftFromPoint', $.NSMakePoint(20,20))
window('setTitle', appName)
window('makeKeyAndOrderFront', window)
window('center')
var button = $.NSButton('alloc')('initWithFrame',$.NSMakeRect(0,0,78,32));
button('setBezelStyle',$.NSRoundedBezelStyle);
var view = window('contentView');
view('addSubview',button);
// 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.addMethod('applicationWillTerminate:', 'v@:@', function (self, _cmd, notif) {
console.log('got applicationWillTerminate')
console.log(notif)
})
AppDelegate.addMethod('myMethod:','v@:@',function (self,_cmd,notif) {
console.log("oops!");
});
AppDelegate.register()
var delegate = AppDelegate('alloc')('init')
app('setDelegate', delegate)
//var button = $.NSButton('alloc')('initWithContentRect', $.NSMakeRect(0,0,20,20))
button('setTarget',delegate)
button('setAction',$.NSSelectorFromString($('myMethod:')))
button('setTitle',$("Hello"))
app('activateIgnoringOtherApps', true)
app('run')
NodObjC固有の問題か? -> 直前で例外が発生していて、実行していると思ったfs.writeSyncが動いていなかっただけだった。orz
fsモジュールがモジュールモジュール
MacRubyで挫折したJavaScriptCoreの利用ができるのではなかろうか?
自前のアイコン持っていればOK?!
残念ながらnode本体をCocoa化?してそこから動かさないと通知センターを取得できず、動かせない模様(2013年末)
var myNotification = $.NSUserNotification('alloc')('init')
myNotification('title',$("Hello, world!"))
myNotification('informativeText',$("Nice to meet you."))
$.NSUserNotificationCenter('defaultUserNotificationCenter')('deliverNotification:',myNotification)
delegate('hide')
myNotification = NSUserNotification.alloc().init()
myNotification.title = "Hello, world!"
myNotification.informativeText = "Nice to meet you."
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(myNotification)
#NSApp.terminate(self)
NSApp.hide(self)
NSUserNotification *myNotification = [[NSUserNotification alloc] init];
myNotification.title = @"Hello, world!";
myNotification.informativeText = @"Nice to meet you.";
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:myNotification];
display notification “無理やり通知する!” with title “node-webkit” subtitle “applescriptで”
// create an NSString of the applescript command that will be run
var command = $('display notification “無理やり通知する!” with title “node-webkit” subtitle “applescriptで”')
// create an NSAppleScript instance with the `command` NSString
var appleScript = $.NSAppleScript('alloc')('initWithSource', command)
// finally execute the NSAppleScript instance synchronously
var resultObj = appleScript('executeAndReturnError', null)