Permalink
Browse files

Introduced a new -list option that can be used to get the delivery da…

…te of a specific group.

If used with the special group "ALL", details for all currently active groups are displayed.

Also introduced the "ALL" parameter to the -remove option: now you can clear all messages in one sweep.
  • Loading branch information...
1 parent bc33b6d commit b911d05330ae0b6a0efd8dea4b425149dd5d6edd @frostrubin frostrubin committed Aug 1, 2012
Showing with 70 additions and 5 deletions.
  1. +70 −5 Terminal Notifier/AppDelegate.m
@@ -26,6 +26,7 @@ - (void)printHelpBanner;
"\n" \
" -message VALUE The notification message.\n" \
" -remove ID Removes a notification with the specified ‘group’ ID.\n" \
+ " -list ID If the specified ‘group’ ID exists: show when it was delivered.\n" \
"\n" \
" Optional:\n" \
"\n" \
@@ -52,9 +53,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *subtitle = defaults[@"subtitle"];
- NSString *message = defaults[@"message"];
- NSString *remove = defaults[@"remove"];
- if (message == nil && remove == nil) {
+ NSString *message = defaults[@"message"];
+ NSString *remove = defaults[@"remove"];
+ NSString *list = defaults[@"list"];
+ if (message == nil && remove == nil && list == nil) {
[self printHelpBanner];
exit(1);
}
@@ -76,6 +78,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
message:message
options:options];
}
+
+ if (list) {
+ //NSMutableDictionary *options = [NSMutableDictionary dictionary];
+ [self listNotificationWithGroupID:list];
+ exit(0);
+ }
}
}
@@ -102,15 +110,72 @@ - (void)removeNotificationWithGroupID:(NSString *)groupID;
{
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
for (NSUserNotification *userNotification in center.deliveredNotifications) {
- if ([userNotification.userInfo[@"groupID"] isEqualToString:groupID]) {
+ if ( ([userNotification.userInfo[@"groupID"] isEqualToString:groupID]) ||
+ ([@"ALL" isEqualToString:groupID])) {
NSString *deliveredAt = [userNotification.actualDeliveryDate description];
printf("* Removing previously sent notification, which was sent on: %s\n", [deliveredAt UTF8String]);
[center removeDeliveredNotification:userNotification];
- break;
}
}
}
+- (void)listNotificationWithGroupID:(NSString *)groupID;
+{
+ NSUInteger len = 1;
+ NSUInteger longestLen = 0;
+ NSUInteger i=0;
+ NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
+ if ([@"ALL" isEqualToString:groupID]) {
+ printf("* Currently active groups:\n");
+ for (NSUserNotification *userNotification in center.deliveredNotifications) {
+ NSString *deliveredGroupID = userNotification.userInfo[@"groupID"];
+ len = [deliveredGroupID length];
+ if (len > longestLen) {
+ longestLen = len;
+ }
+ }
+ if (longestLen > 0) {
+ printf("* Group ID");
+ for (i = 8; i < longestLen; i++) {
+ printf(" ");
+ }
+ printf(" ");
+ printf("Delivered on\n");
+ }
+ for (NSUserNotification *userNotification in center.deliveredNotifications) {
+ NSString *deliveredGroupID = userNotification.userInfo[@"groupID"];
+ NSString *deliveredAt = [userNotification.actualDeliveryDate description];
+ printf("* %s", [deliveredGroupID UTF8String]);
+ len = [deliveredGroupID length];
+ for (i = len; i < longestLen; i++) {
+ printf(" ");
+ }
+ for (i = longestLen; i < 8; i++) {
+ printf(" ");
+ }
+ printf(" ");
+ printf("%s\n", [deliveredAt UTF8String]);
+ }
+ } else {
+ for (NSUserNotification *userNotification in center.deliveredNotifications) {
+ if ([userNotification.userInfo[@"groupID"] isEqualToString:groupID]) {
+ longestLen = 1;
+ NSString *deliveredAt = [userNotification.actualDeliveryDate description];
+ printf("* The last message for group %s was delivered on: %s\n", [groupID UTF8String], [deliveredAt UTF8String]);
+ break;
+ }
+ }
+ }
+ if (longestLen == 0) {
+ if ([@"ALL" isEqualToString:groupID]) {
+ printf("* None\n");
+ } else {
+ printf("* No message for the group %s could be found\n", [groupID UTF8String]);
+ }
+ }
+}
+
+
- (void)userActivatedNotification:(NSUserNotification *)userNotification;
{
[[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:userNotification];

0 comments on commit b911d05

Please sign in to comment.