Fix some threading issues.
This commit is contained in:
1 parent
cd67331db2
commit
11028208b8
4 files changed
+128
-103
No files matched your search
@@ -70,11 +70,13 @@ static void *SBItemViewContex = &SBItemViewContex;
|
||||
// is different from ready
|
||||
if ([keyPath isEqualToString:@"item.status"]) {
|
||||
SBQueueItemStatus newStatus = [[change valueForKey:NSKeyValueChangeNewKey] integerValue];
|
||||
if (newStatus != SBQueueItemStatusReady && newStatus != SBQueueItemStatusEditing) {
|
||||
[self.editButton setEnabled:NO];
|
||||
} else {
|
||||
[self.editButton setEnabled:YES];
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (newStatus != SBQueueItemStatusReady && newStatus != SBQueueItemStatusEditing) {
|
||||
[self.editButton setEnabled:NO];
|
||||
} else {
|
||||
[self.editButton setEnabled:YES];
|
||||
}
|
||||
});
|
||||
} else if ([keyPath isEqualToString:@"item.actions"]) {
|
||||
NSInteger count = [change[NSKeyValueChangeNewKey] count] - [change[NSKeyValueChangeOldKey] count];
|
||||
CGFloat height = TABLE_ROW_HEIGHT * (count >= 0 ? count : 1);
|
||||
|
||||
+9
-7
@@ -222,22 +222,25 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
* Starts the queue.
|
||||
*/
|
||||
- (void)start {
|
||||
if (self.status == SBQueueStatusWorking) {
|
||||
if (self.status == SBQueueStatusWorking || self.cancelled) {
|
||||
return;
|
||||
} else {
|
||||
self.status = SBQueueStatusWorking;
|
||||
}
|
||||
|
||||
// Enable sleep assertion
|
||||
[self disableSleep];
|
||||
|
||||
dispatch_async(self.workQueue, ^{
|
||||
|
||||
// Enable sleep assertion
|
||||
[self disableSleep];
|
||||
|
||||
NSUInteger completedCount = 0;
|
||||
NSUInteger failedCount = 0;
|
||||
|
||||
for (;;) {
|
||||
@autoreleasepool {
|
||||
// Save to disk
|
||||
[self saveQueueToDisk];
|
||||
|
||||
NSError *outError = nil;
|
||||
BOOL noErr = NO;
|
||||
|
||||
@@ -280,6 +283,8 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
|
||||
self.currentItem.delegate = nil;
|
||||
self.currentItem = nil;
|
||||
|
||||
[self handleSBStatusWorking:100 index:self.currentIndex];
|
||||
}
|
||||
|
||||
if (self.status == SBQueueStatusCancelled) {
|
||||
@@ -287,9 +292,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
||||
}
|
||||
}
|
||||
|
||||
// Save to disk
|
||||
[self saveQueueToDisk];
|
||||
|
||||
// Disable sleep assertion
|
||||
[self enableSleep];
|
||||
[self handleSBStatusCompleted:completedCount failed:failedCount];
|
||||
|
||||
@@ -97,8 +97,9 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[self.progressBar setIndeterminate:NO];
|
||||
self.progressBar.doubleValue = [[info valueForKey:@"Progress"] doubleValue];
|
||||
|
||||
if ([info[@"ItemIndex"] integerValue] != -1) {
|
||||
[self updateUI];
|
||||
NSInteger index = [info[@"ItemIndex"] integerValue];
|
||||
if (index != -1) {
|
||||
[self updateUIIndexes:[NSIndexSet indexSetWithIndex:index]];
|
||||
}
|
||||
}];
|
||||
|
||||
@@ -484,6 +485,11 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateUIIndexes:(NSIndexSet *)indexes {
|
||||
[self.table reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
[self updateState];
|
||||
}
|
||||
|
||||
- (void)updateUI {
|
||||
[self.table reloadData];
|
||||
[self updateState];
|
||||
|
||||
Reference in new issue
Block a user