mw.notify() now supports time argument.

This commit is contained in:
Xhacker Liu
2014-09-13 02:23:52 -07:00
parent 9fdf5be776
commit 52b55d3f14
2 changed files with 17 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ mw.setAutoStart(true) // not implemented yet
mw.notify({
title: "Pomotodo",
content: "Break is over!",
time: "2038-01-19 03:14:07", // (optional) delivery date
popupOnClick: true // popup when clicking notification
})

View File

@@ -185,14 +185,26 @@ static const NSInteger kPreferencesDefaultHeight = 192;
self.statusItemView.highlightedIcon = [NSImage imageNamed:@"StatusIconWhite"];
}
- (void)notify:(WebScriptObject *)message
- (void)notify:(WebScriptObject *)obj
{
LDYWebScriptObjectConverter *converter = [[LDYWebScriptObjectConverter alloc] initWithWebView:self.webView];
NSDictionary *message = [converter dictionaryFromWebScriptObject:obj];
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = [message valueForKey:@"title"];
notification.informativeText = [message valueForKey:@"content"];
notification.title = message[@"title"];
notification.informativeText = message[@"content"];
notification.deliveryDate = [NSDate date];
notification.soundName = NSUserNotificationDefaultSoundName;
notification.userInfo = @{@"popupOnClick": [message valueForKey:@"popupOnClick"]};
notification.userInfo = @{@"popupOnClick": message[@"popupOnClick"]};
if (message[@"time"]) {
static NSDateFormatter *formatter;
if (!formatter) {
formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
}
notification.deliveryDate = [formatter dateFromString:message[@"time"]];
}
NSUserNotificationCenter *notificationCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
notificationCenter.delegate = self;