|
@@ -30,6 +30,14 @@
|
30
|
30
|
|
31
|
31
|
@implementation AppDelegate
|
32
|
32
|
|
|
33
|
+NSInteger itemsBeforeLinkList = 2;
|
|
34
|
+NSInteger numberOfStaticMenuItems = 10;
|
|
35
|
+#define MULTIPLIER_PM_INTERVALL_TO_SEC 60
|
|
36
|
+#define RECHECK_PM_AFTER_OPEN 10
|
|
37
|
+#define SUBMENU_INDEX_LINK 0
|
|
38
|
+#define SUBMENU_INDEX_COMMENTS 1
|
|
39
|
+#define SUBMENU_INDEX_BOTH 2
|
|
40
|
+
|
33
|
41
|
@synthesize statusMenu, statusItem, statusImage, statusHighlightImage, orangeredImage, orangeredHighlightImage, prefWindow, currentState, application, api, firstMenuItem, menuItems, redditItems, lastFullName, refreshTimer, PMItem, PMSeparator;
|
34
|
42
|
|
35
|
43
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
@@ -55,7 +63,7 @@
|
55
|
63
|
-(void)recreateRefreshTimer {
|
56
|
64
|
if (refreshTimer != nil)
|
57
|
65
|
[refreshTimer invalidate];
|
58
|
|
- refreshTimer = [NSTimer scheduledTimerWithTimeInterval:(currentState.refreshInterval * 60) target:self selector:@selector(refreshTick:) userInfo:nil repeats:YES];
|
|
66
|
+ refreshTimer = [NSTimer scheduledTimerWithTimeInterval:(currentState.refreshInterval * MULTIPLIER_PM_INTERVALL_TO_SEC) target:self selector:@selector(refreshTick:) userInfo:nil repeats:YES];
|
59
|
67
|
[refreshTimer fire];
|
60
|
68
|
}
|
61
|
69
|
|
|
@@ -116,6 +124,19 @@
|
116
|
124
|
}
|
117
|
125
|
}
|
118
|
126
|
|
|
127
|
+-(void)singleItemReloadedCallback:(NSArray *)items {
|
|
128
|
+ if (items != nil) {
|
|
129
|
+ lastFullName = [items objectAtIndex:[items count] - 1]; // last link fullname is at end of array
|
|
130
|
+ items = [items subarrayWithRange:NSMakeRange(0, [items count] - 1)]; // Remove last item
|
|
131
|
+ NSMutableArray *newMenuItems = [NSMutableArray arrayWithArray:menuItems];
|
|
132
|
+ NSMenuItem *item = [self prepareItemForMenu:[items objectAtIndex:0]];
|
|
133
|
+ [newMenuItems addObject:item];
|
|
134
|
+ [statusMenu insertItem:item atIndex:([statusMenu numberOfItems] - numberOfStaticMenuItems + itemsBeforeLinkList)];
|
|
135
|
+ menuItems = newMenuItems;
|
|
136
|
+ redditItems = [redditItems arrayByAddingObjectsFromArray:items];
|
|
137
|
+ }
|
|
138
|
+}
|
|
139
|
+
|
119
|
140
|
-(void)reloadListWithOptions {
|
120
|
141
|
if ([currentState.modhash isEqualToString:@""]) {
|
121
|
142
|
[firstMenuItem setTitle:NSLocalizedString(@"Not logged in!", @"Statusitem when no modhash is stored")];
|
|
@@ -173,11 +194,11 @@
|
173
|
194
|
removed = TRUE;
|
174
|
195
|
}
|
175
|
196
|
|
176
|
|
- if (removed && ([statusMenu numberOfItems] <= 10)) {
|
|
197
|
+ if (removed && ([statusMenu numberOfItems] <= numberOfStaticMenuItems)) {
|
177
|
198
|
[self reloadNextList:nil];
|
178
|
199
|
} else {
|
179
|
200
|
if (removed && currentState.reloadAfterVisit) {
|
180
|
|
- // TODO load one more item!
|
|
201
|
+ [NSThread detachNewThreadSelector:@selector(readSingleItem:) toTarget:api withObject:self];
|
181
|
202
|
}
|
182
|
203
|
}
|
183
|
204
|
}
|
|
@@ -197,11 +218,11 @@
|
197
|
218
|
|
198
|
219
|
NSInteger index;
|
199
|
220
|
if ([title isEqualToString:NSLocalizedString(@"Link...", nil)])
|
200
|
|
- index = 0;
|
|
221
|
+ index = SUBMENU_INDEX_LINK;
|
201
|
222
|
else if ([title isEqualToString:NSLocalizedString(@"Comments...", nil)])
|
202
|
|
- index = 1;
|
|
223
|
+ index = SUBMENU_INDEX_COMMENTS;
|
203
|
224
|
else
|
204
|
|
- index = 2;
|
|
225
|
+ index = SUBMENU_INDEX_BOTH;
|
205
|
226
|
|
206
|
227
|
if ((submenu != nil) && (sender == [submenu itemAtIndex:index])) {
|
207
|
228
|
[self openAndRemoveAndReloadWithIndex:i Comments:isComments Both:isBoth];
|
|
@@ -221,7 +242,7 @@
|
221
|
242
|
|
222
|
243
|
-(IBAction)openUnread:(id)sender {
|
223
|
244
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.reddit.com/message/unread"]];
|
224
|
|
- [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(refreshTick:) userInfo:nil repeats:NO];
|
|
245
|
+ [NSTimer scheduledTimerWithTimeInterval:RECHECK_PM_AFTER_OPEN target:self selector:@selector(refreshTick:) userInfo:nil repeats:NO];
|
225
|
246
|
}
|
226
|
247
|
|
227
|
248
|
-(void)clearMenuItems {
|
|
@@ -240,7 +261,7 @@
|
240
|
261
|
for (NSUInteger i = 0; i < [array count]; i++) {
|
241
|
262
|
NSMenuItem *item = [self prepareItemForMenu:[array objectAtIndex:i]];
|
242
|
263
|
[items addObject:item];
|
243
|
|
- [statusMenu insertItem:item atIndex:(i + 2)];
|
|
264
|
+ [statusMenu insertItem:item atIndex:(i + itemsBeforeLinkList)];
|
244
|
265
|
}
|
245
|
266
|
menuItems = items;
|
246
|
267
|
}
|