implemented Notification Center
This commit is contained in:
parent
d8683ed9d5
commit
9bcba0beae
4 changed files with 48 additions and 4 deletions
|
@ -14,7 +14,7 @@
|
|||
#import "AccessToken.h"
|
||||
|
||||
|
||||
@interface Controller : NSObject {
|
||||
@interface Controller : NSObject <NSUserNotificationCenterDelegate> {
|
||||
IBOutlet WebView *timelineView;
|
||||
IBOutlet NSWindow *timelineViewWindow;
|
||||
IBOutlet WebView *mentionsView;
|
||||
|
@ -52,6 +52,8 @@
|
|||
- (NSString *)pluginURL;
|
||||
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
|
||||
- (void)unreadMentions:(NSInteger)count;
|
||||
- (void)notificateUserAboutMention:(NSString *)text fromName:(NSString *)name withPostId:(NSString *)postId andEntity:(NSString *)entity;
|
||||
|
||||
- (void)openURL:(NSString *)url;
|
||||
|
||||
- (void)setString:(NSString *)string forKey:(NSString *)aKey;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
- (void)awakeFromNib {
|
||||
|
||||
[self initHotKeys];
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc addObserver:self
|
||||
|
@ -257,6 +258,24 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)notificateUserAboutMention:(NSString *)text fromName:(NSString *)name withPostId:(NSString *)postId andEntity:(NSString *)entity {
|
||||
|
||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||
notification.title = @"Tent Mention";
|
||||
notification.subtitle = [NSString stringWithFormat:@"Mentioned by %@", name];
|
||||
notification.informativeText = text;
|
||||
notification.hasActionButton = YES;
|
||||
notification.actionButtonTitle = @"Show";
|
||||
notification.soundName = NSUserNotificationDefaultSoundName;
|
||||
notification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
entity, @"entity",
|
||||
postId, @"postId", nil];
|
||||
|
||||
NSLog(@"%@", notification);
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
}
|
||||
|
||||
- (void)openURL:(NSString *)url {
|
||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
|
||||
}
|
||||
|
@ -326,6 +345,13 @@
|
|||
conversationViewWindow.title = @"Test";
|
||||
}
|
||||
|
||||
// Notifications
|
||||
|
||||
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
|
||||
{
|
||||
[self showConversationForPostId:[notification.userInfo objectForKey:@"postId"] andEntity:[notification.userInfo objectForKey:@"entity"]];
|
||||
}
|
||||
|
||||
/* CARBON */
|
||||
|
||||
OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData)
|
||||
|
|
|
@ -19,13 +19,23 @@ function(HostApp, Timeline) {
|
|||
|
||||
Mentions.prototype = Object.create(Timeline.prototype);
|
||||
|
||||
Mentions.prototype.newStatus = function(status) {
|
||||
Mentions.prototype.newStatus = function(statuses) {
|
||||
|
||||
Timeline.prototype.newStatus.call(this, status);
|
||||
Timeline.prototype.newStatus.call(this, statuses);
|
||||
|
||||
if(this.is_not_init) {
|
||||
this.unread_mentions += status.length;
|
||||
this.unread_mentions += statuses.length;
|
||||
HostApp.unreadMentions(this.unread_mentions);
|
||||
for (var i = 0; i < statuses.length; i++) {
|
||||
var status = statuses[i];
|
||||
|
||||
var name;
|
||||
if(this.followings.followings[status.entity]) {
|
||||
name = this.followings.followings[status.entity].profile["https://tent.io/types/info/basic/v0.1.0"].name;
|
||||
}
|
||||
|
||||
HostApp.notificateUserAboutMention(status.content.text, name || status.entity, status.id, status.entity);
|
||||
};
|
||||
}
|
||||
|
||||
this.is_not_init = true;
|
||||
|
|
|
@ -70,6 +70,12 @@ define(function() {
|
|||
}
|
||||
}
|
||||
|
||||
HostApp.notificateUserAboutMention = function(text, name, post_id, entity) {
|
||||
if (OS_TYPE == "mac") {
|
||||
controller.notificateUserAboutMention_fromName_withPostId_andEntity_(text, name, post_id, entity);
|
||||
}
|
||||
}
|
||||
|
||||
return HostApp;
|
||||
|
||||
});
|
Reference in a new issue