Kaynağa Gözat

Implemented Unread PM Notifications.

Thomas Buck 11 yıl önce
ebeveyn
işleme
67371acf4f

+ 2
- 2
RedditBar/AppDelegate.h Dosyayı Görüntüle

31
 #import "StateModel.h"
31
 #import "StateModel.h"
32
 #import "Reddit.h"
32
 #import "Reddit.h"
33
 
33
 
34
-@interface AppDelegate : NSObject <NSApplicationDelegate>
34
+@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
35
 
35
 
36
 @property (atomic, retain) IBOutlet NSMenu *statusMenu;
36
 @property (atomic, retain) IBOutlet NSMenu *statusMenu;
37
 @property (atomic, retain) IBOutlet NSApplication *application;
37
 @property (atomic, retain) IBOutlet NSApplication *application;
64
 -(void)reloadListNotAuthenticatedCallback;
64
 -(void)reloadListNotAuthenticatedCallback;
65
 -(void)reloadListHasSubredditsCallback:(NSArray *)items;
65
 -(void)reloadListHasSubredditsCallback:(NSArray *)items;
66
 -(void)reloadListHasFrontpageCallback:(NSArray *)items;
66
 -(void)reloadListHasFrontpageCallback:(NSArray *)items;
67
--(void)readPMsCallback:(NSNumber *)items;
67
+-(void)readPMsCallback:(NSArray *)items;
68
 -(void)singleItemReloadedCallback:(NSArray *)items;
68
 -(void)singleItemReloadedCallback:(NSArray *)items;
69
 
69
 
70
 -(void)prefsDidSave;
70
 -(void)prefsDidSave;

+ 25
- 4
RedditBar/AppDelegate.m Dosyayı Görüntüle

32
 
32
 
33
 NSInteger itemsBeforeLinkList = 2;
33
 NSInteger itemsBeforeLinkList = 2;
34
 NSInteger numberOfStaticMenuItems = 10;
34
 NSInteger numberOfStaticMenuItems = 10;
35
+
35
 #define MULTIPLIER_PM_INTERVALL_TO_SEC 60
36
 #define MULTIPLIER_PM_INTERVALL_TO_SEC 60
36
-#define RECHECK_PM_AFTER_OPEN 10
37
+#define RECHECK_PM_AFTER_OPEN 7
37
 #define SUBMENU_INDEX_LINK 0
38
 #define SUBMENU_INDEX_LINK 0
38
 #define SUBMENU_INDEX_COMMENTS 1
39
 #define SUBMENU_INDEX_COMMENTS 1
39
 #define SUBMENU_INDEX_BOTH 2
40
 #define SUBMENU_INDEX_BOTH 2
58
     lastFullName = nil;
59
     lastFullName = nil;
59
     [self reloadListWithOptions];
60
     [self reloadListWithOptions];
60
     [self recreateRefreshTimer];
61
     [self recreateRefreshTimer];
62
+    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
63
+}
64
+
65
+-(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
66
+    return YES;
67
+}
68
+
69
+-(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
70
+    [self openUnread:nil];
61
 }
71
 }
62
 
72
 
63
 -(void)recreateRefreshTimer {
73
 -(void)recreateRefreshTimer {
71
     [NSThread detachNewThreadSelector:@selector(readPMs:) toTarget:api withObject:self];
81
     [NSThread detachNewThreadSelector:@selector(readPMs:) toTarget:api withObject:self];
72
 }
82
 }
73
 
83
 
74
--(void)readPMsCallback:(NSNumber *)items {
75
-    if ((items == nil) || ([items integerValue] == 0)) {
84
+-(void)readPMsCallback:(NSArray *)items {
85
+    if ((items == nil) || ([items count] < 1) || (((NSNumber *)[items objectAtIndex:0]).integerValue == 0)) {
76
         [statusItem setImage:statusImage];
86
         [statusItem setImage:statusImage];
77
         [statusItem setAlternateImage:statusHighlightImage];
87
         [statusItem setAlternateImage:statusHighlightImage];
78
         [PMItem setHidden:TRUE];
88
         [PMItem setHidden:TRUE];
80
     } else {
90
     } else {
81
         [statusItem setImage:orangeredImage];
91
         [statusItem setImage:orangeredImage];
82
         [statusItem setAlternateImage:orangeredHighlightImage];
92
         [statusItem setAlternateImage:orangeredHighlightImage];
83
-        [PMItem setTitle:[NSString stringWithFormat:NSLocalizedString(@"You've got %ld unread PMs!", @"PM message"), (long)items.integerValue]];
93
+        [PMItem setTitle:[NSString stringWithFormat:NSLocalizedString(@"You've got %ld unread PMs.", @"PM message"), (long)((NSNumber *)[items objectAtIndex:0]).integerValue]];
84
         [PMItem setHidden:FALSE];
94
         [PMItem setHidden:FALSE];
85
         [PMSeparator setHidden:FALSE];
95
         [PMSeparator setHidden:FALSE];
96
+
97
+        if ([items count] >= 2) {
98
+            if (![currentState.lastNotifiedPM isEqualToString:[items objectAtIndex:1]]) {
99
+                currentState.lastNotifiedPM = [items objectAtIndex:1];
100
+                [currentState savePreferences];
101
+                NSUserNotification *notification = [[NSUserNotification alloc] init];
102
+                notification.title = NSLocalizedString(@"New Reddit PM!", @"Notification Title");
103
+                notification.informativeText = [NSString stringWithFormat:NSLocalizedString(@"You've got %ld unread PMs.", nil), (long)((NSNumber *)[items objectAtIndex:0]).integerValue];
104
+                [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
105
+            }
106
+        }
86
     }
107
     }
87
 }
108
 }
88
 
109
 

+ 9
- 3
RedditBar/Reddit.m Dosyayı Görüntüle

228
     return array;
228
     return array;
229
 }
229
 }
230
 
230
 
231
--(NSNumber *)messagesCount:(NSData *)data {
231
+-(NSArray *)messagesData:(NSData *)data {
232
     NSError *error;
232
     NSError *error;
233
     NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
233
     NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
234
     NSDictionary *dat = [json valueForKey:@"data"];
234
     NSDictionary *dat = [json valueForKey:@"data"];
237
     NSArray *children = [dat valueForKey:@"children"];
237
     NSArray *children = [dat valueForKey:@"children"];
238
     if (children == nil)
238
     if (children == nil)
239
         return nil;
239
         return nil;
240
-    return [NSNumber numberWithInteger:[children count]];
240
+    NSString *newest_name = nil;
241
+    if (children.count > 0) {
242
+        NSDictionary *child = [children objectAtIndex:0];
243
+        NSDictionary *current = [child valueForKey:@"data"];
244
+        newest_name = [current valueForKey:@"name"];
245
+    }
246
+    return [NSArray arrayWithObjects:[NSNumber numberWithInteger:[children count]], newest_name, nil];
241
 }
247
 }
242
 
248
 
243
 -(void)readPMs:(id)parent {
249
 -(void)readPMs:(id)parent {
247
     if ((data == nil) || ([response statusCode] != 200)) {
253
     if ((data == nil) || ([response statusCode] != 200)) {
248
         [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:nil waitUntilDone:FALSE];
254
         [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:nil waitUntilDone:FALSE];
249
     } else {
255
     } else {
250
-        [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:[self messagesCount:data] waitUntilDone:FALSE];
256
+        [(AppDelegate *)parent performSelectorOnMainThread:@selector(readPMsCallback:) withObject:[self messagesData:data] waitUntilDone:FALSE];
251
     }
257
     }
252
 }
258
 }
253
 
259
 

+ 2
- 2
RedditBar/RedditBar-Info.plist Dosyayı Görüntüle

17
 	<key>CFBundlePackageType</key>
17
 	<key>CFBundlePackageType</key>
18
 	<string>APPL</string>
18
 	<string>APPL</string>
19
 	<key>CFBundleShortVersionString</key>
19
 	<key>CFBundleShortVersionString</key>
20
-	<string>1.3.1</string>
20
+	<string>1.4.0</string>
21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>301</string>
24
+	<string>312</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

+ 1
- 0
RedditBar/StateModel.h Dosyayı Görüntüle

41
 @property (atomic, retain) NSString *filter;
41
 @property (atomic, retain) NSString *filter;
42
 @property (atomic) Boolean removeVisited;
42
 @property (atomic) Boolean removeVisited;
43
 @property (atomic) Boolean reloadAfterVisit;
43
 @property (atomic) Boolean reloadAfterVisit;
44
+@property (atomic, retain) NSString *lastNotifiedPM;
44
 
45
 
45
 -(void)registerDefaultPreferences;
46
 -(void)registerDefaultPreferences;
46
 -(void)savePreferences;
47
 -(void)savePreferences;

+ 5
- 1
RedditBar/StateModel.m Dosyayı Görüntüle

30
 
30
 
31
 @implementation StateModel
31
 @implementation StateModel
32
 
32
 
33
-@synthesize username, modhash, useSubscriptions, subreddits, length, showSubreddit, titleLength, refreshInterval, filter, removeVisited, reloadAfterVisit;
33
+@synthesize username, modhash, useSubscriptions, subreddits, length, showSubreddit, titleLength, refreshInterval, filter, removeVisited, reloadAfterVisit, lastNotifiedPM;
34
 
34
 
35
 NSString *s_username = @"username";
35
 NSString *s_username = @"username";
36
 NSString *s_modhash = @"modhash";
36
 NSString *s_modhash = @"modhash";
43
 NSString *s_filter = @"filter";
43
 NSString *s_filter = @"filter";
44
 NSString *s_remove = @"remove";
44
 NSString *s_remove = @"remove";
45
 NSString *s_reload = @"reload";
45
 NSString *s_reload = @"reload";
46
+NSString *s_lastPM = @"lastNotifiedPM";
46
 
47
 
47
 -(void)registerDefaultPreferences {
48
 -(void)registerDefaultPreferences {
48
     NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
49
     NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
56
     [appDefaults setValue:@"hot" forKey:s_filter];
57
     [appDefaults setValue:@"hot" forKey:s_filter];
57
     [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_remove];
58
     [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_remove];
58
     [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_reload];
59
     [appDefaults setValue:[NSNumber numberWithBool:YES] forKey:s_reload];
60
+    [appDefaults setValue:@"" forKey:s_lastPM];
59
     [store registerDefaults:appDefaults];
61
     [store registerDefaults:appDefaults];
60
 }
62
 }
61
 
63
 
72
     [store setObject:filter forKey:s_filter];
74
     [store setObject:filter forKey:s_filter];
73
     [store setBool:removeVisited forKey:s_remove];
75
     [store setBool:removeVisited forKey:s_remove];
74
     [store setBool:reloadAfterVisit forKey:s_reload];
76
     [store setBool:reloadAfterVisit forKey:s_reload];
77
+    [store setObject:lastNotifiedPM forKey:s_lastPM];
75
     [store synchronize];
78
     [store synchronize];
76
 }
79
 }
77
 
80
 
89
     filter = [store stringForKey:s_filter];
92
     filter = [store stringForKey:s_filter];
90
     removeVisited = [store boolForKey:s_remove];
93
     removeVisited = [store boolForKey:s_remove];
91
     reloadAfterVisit = [store boolForKey:s_reload];
94
     reloadAfterVisit = [store boolForKey:s_reload];
95
+    lastNotifiedPM = [store stringForKey:s_lastPM];
92
 }
96
 }
93
 
97
 
94
 @end
98
 @end

+ 3
- 0
RedditBar/de.lproj/Localizable.strings Dosyayı Görüntüle

22
 /* Statusitem when API is not authenticated */
22
 /* Statusitem when API is not authenticated */
23
 "Login Error!" = "Fehler beim Login!";
23
 "Login Error!" = "Fehler beim Login!";
24
 
24
 
25
+/* Notification Title */
26
+"New Reddit PM!" = "Neue Reddit PM!";
27
+
25
 /* Statusitem when no modhash is stored */
28
 /* Statusitem when no modhash is stored */
26
 "Not logged in!" = "Nicht eingeloggt!";
29
 "Not logged in!" = "Nicht eingeloggt!";
27
 
30
 

BIN
RedditBar/en.lproj/Localizable.strings Dosyayı Görüntüle


Loading…
İptal
Kaydet