Add an options to show a notification when the queue is done.
This commit is contained in:
1 parent
64c57a9442
commit
1226d0abbd
6 files changed
+201
-95
No files matched your search
+2
-3
@@ -52,9 +52,8 @@ extern NSString *SBQueueCancelledNotification;
|
||||
- (void)removeItemsAtIndexes:(NSIndexSet *)indexes;
|
||||
- (void)removeItem:(SBQueueItem *)item;
|
||||
|
||||
@property (nonatomic, readonly, copy) NSIndexSet * _Nonnull removeCompletedItems;
|
||||
|
||||
@property (nonatomic, readonly) BOOL saveQueueToDisk;
|
||||
- (NSIndexSet *)removeCompletedItems;
|
||||
- (BOOL)saveQueueToDisk;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+10
-3
@@ -173,6 +173,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
[self disableSleep];
|
||||
|
||||
dispatch_async(self.workQueue, ^{
|
||||
|
||||
NSUInteger completedCount = 0;
|
||||
NSUInteger failedCount = 0;
|
||||
|
||||
for (;;) {
|
||||
@autoreleasepool {
|
||||
NSError *outError = nil;
|
||||
@@ -207,8 +211,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
if (noErr) {
|
||||
self.currentItem.status = SBQueueItemStatusCompleted;
|
||||
completedCount += 1;
|
||||
} else {
|
||||
self.currentItem.status = SBQueueItemStatusFailed;
|
||||
failedCount += 1;
|
||||
[self handleSBStatusFailed:outError];
|
||||
}
|
||||
|
||||
@@ -226,7 +232,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
// Disable sleep assertion
|
||||
[self enableSleep];
|
||||
[self handleSBStatusCompleted];
|
||||
[self handleSBStatusCompleted:completedCount failed:failedCount];
|
||||
|
||||
// Reset cancelled state
|
||||
self.cancelled = NO;
|
||||
@@ -265,9 +271,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
* Processes SBQueueStatusCompleted state information. Current implementation just
|
||||
* sends SBQueueCompletedNotification.
|
||||
*/
|
||||
- (void)handleSBStatusCompleted {
|
||||
- (void)handleSBStatusCompleted:(NSUInteger)completedCount failed:(NSUInteger)failedCount {
|
||||
self.status = SBQueueStatusCompleted;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCompletedNotification object:self];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCompletedNotification object:self userInfo:@{@"CompletedCount": @(completedCount),
|
||||
@"FailedCount": @(failedCount)}];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,7 +94,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[self.progressBar setIndeterminate:NO];
|
||||
self.progressBar.doubleValue = [[info valueForKey:@"Progress"] doubleValue];
|
||||
|
||||
if ([[info valueForKey:@"ItemIndex"] integerValue] != -1) {
|
||||
if ([info[@"ItemIndex"] integerValue] != -1) {
|
||||
[self updateUI];
|
||||
}
|
||||
}];
|
||||
@@ -108,6 +108,24 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[self.statusLabel setStringValue:NSLocalizedString(@"Done", @"Queue -> Done")];
|
||||
|
||||
[self updateUI];
|
||||
|
||||
if ([self.options[SBQueueShowDoneNotification] boolValue]) {
|
||||
NSDictionary *info = note.userInfo;
|
||||
|
||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||
notification.title = NSLocalizedString(@"Queue done", nil);
|
||||
if ([info[@"FailedCount"] unsignedIntegerValue]) {
|
||||
notification.informativeText = [NSString stringWithFormat:@"Completed: %lu; Failed: %lu",
|
||||
[info[@"CompletedCount"] unsignedIntegerValue],
|
||||
[info[@"FailedCount"] unsignedIntegerValue]];
|
||||
}
|
||||
else {
|
||||
notification.informativeText = [NSString stringWithFormat:@"Completed: %lu",
|
||||
[info[@"CompletedCount"] unsignedIntegerValue]];
|
||||
}
|
||||
notification.soundName = NSUserNotificationDefaultSoundName;
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
}
|
||||
}];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueFailedNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) {
|
||||
|
||||
@@ -19,6 +19,7 @@ extern NSString * const SBQueueSet;
|
||||
|
||||
extern NSString * const SBQueueAutoStart;
|
||||
extern NSString * const SBQueueOptimize;
|
||||
extern NSString * const SBQueueShowDoneNotification;
|
||||
|
||||
extern NSString * const SBQueueFixTrackLanguage;
|
||||
extern NSString * const SBQueueFixTrackLanguageValue;
|
||||
|
||||
@@ -19,6 +19,7 @@ NSString * const SBQueueSubtitles = @"SBQueueSubtitles";
|
||||
|
||||
NSString * const SBQueueAutoStart = @"SBQueueAutoStart";
|
||||
NSString * const SBQueueOptimize = @"SBQueueOptimize";
|
||||
NSString * const SBQueueShowDoneNotification = @"SBQueueShowDoneNotification";
|
||||
|
||||
NSString * const SBQueueFixTrackLanguage = @"SBQueueFixTrackLanguage";
|
||||
NSString * const SBQueueFixTrackLanguageValue = @"SBQueueFixTrackLanguageValue";
|
||||
@@ -40,7 +41,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
if (self) {
|
||||
_options = [[NSMutableDictionary alloc] init];
|
||||
|
||||
NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage];
|
||||
NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage];
|
||||
|
||||
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
self.options[obj] = [[NSUserDefaults standardUserDefaults] valueForKey:obj];
|
||||
@@ -69,8 +70,11 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
SBQueueFixFallbacks: @NO,
|
||||
SBQueueMetadata : @NO,
|
||||
SBQueueSubtitles: @YES,
|
||||
|
||||
SBQueueAutoStart: @NO,
|
||||
SBQueueOptimize : @YES,
|
||||
SBQueueShowDoneNotification: @YES,
|
||||
|
||||
SBQueueMovieProvider : @"TheMovieDB",
|
||||
SBQueueTVShowProvider : @"TheTVDB",
|
||||
SBQueueMovieProviderLanguage : @"English",
|
||||
@@ -81,7 +85,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
* Save the queue user defaults
|
||||
*/
|
||||
- (void)saveUserDefaults {
|
||||
NSArray<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage];
|
||||
NSArray<NSString *> *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage];
|
||||
|
||||
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||
[[NSUserDefaults standardUserDefaults] setValue:(self.options)[obj] forKey:obj];
|
||||
|
||||
Reference in new issue
Block a user