@@ -12,18 +12,19 @@ @interface FilesQueue ()
1212
1313-(NSArray *)extensions ;
1414-(BOOL )isAnyQueueBusy ;
15- -(void )updateProgressbar ;
15+ -(void )updateBusyState ;
1616-(void )deleteObjects : (NSArray *)objects ;
1717@end
1818
1919static NSString *kIMDraggedRowIndexesPboardType = @" com.imageoptim.rows" ;
2020
2121@implementation FilesQueue
2222
23- -(id )configureWithTableView : (NSTableView *)inTableView progressBar : (NSProgressIndicator *)inBar
23+ @synthesize isBusy;
24+
25+ -(id )configureWithTableView : (NSTableView *)inTableView
2426{
2527 if (self = [super init ]) {
26- progressBar = inBar;
2728 tableView = inTableView;
2829 seenPathHashes = [[NSHashTable alloc ] initWithOptions: NSHashTableZeroingWeakMemory capacity: 1000 ];
2930
@@ -71,21 +72,15 @@ -(void)waitForQueuesToFinish {
7172 [cpuQueue waitUntilAllOperationsAreFinished ];
7273
7374 } while ([self isAnyQueueBusy ]);
75+ NSLog (@" wait thread loop end" );
7476 }
7577 @finally {
7678 [queueWaitingLock unlock ];
7779 }
7880 }
79- [self performSelectorOnMainThread: @selector (updateProgressbar ) withObject: nil waitUntilDone: NO ];
81+ [self performSelectorOnMainThread: @selector (updateBusyState ) withObject: nil waitUntilDone: NO ];
8082}
8183
82- -(void )waitInBackgroundForQueuesToFinish {
83- if ([queueWaitingLock tryLock ]) // if it's locked, there's thread waiting for finish
84- {
85- [queueWaitingLock unlock ]; // can't lock/unlock across threads, so new lock will have to be made
86- [self performSelectorInBackground: @selector (waitForQueuesToFinish ) withObject: nil ];
87- }
88- }
8984
9085-(void )setRow : (NSInteger )row
9186{
@@ -322,7 +317,7 @@ -(void)addFileObjects:(NSArray *)files
322317 }
323318 }
324319
325- [self updateProgressbar ];
320+ [self updateBusyState ];
326321}
327322
328323-(void )addPaths : (NSArray *)paths
@@ -434,23 +429,26 @@ -(void)startAgainOptimized:(BOOL)optimized
434429
435430 if (!anyStarted) NSBeep ();
436431
437- [self updateProgressbar ];
432+ [self updateBusyState ];
438433}
439434
440- -(void )updateProgressbar
435+ -(void )updateBusyState
441436{
442- if (![self isAnyQueueBusy ])
443- {
444- [progressBar stopAnimation: nil ];
445- if ([[NSUserDefaults standardUserDefaults ] boolForKey: @" BounceDock" ]) {
446- [NSApp requestUserAttention: NSInformationalRequest];
437+ BOOL currentlyBusy = [self isAnyQueueBusy ];
438+
439+ if (isBusy != currentlyBusy) {
440+ [self willChangeValueForKey: @" isBusy" ];
441+ isBusy = currentlyBusy;
442+ [self didChangeValueForKey: @" isBusy" ];
443+
444+ if (isBusy) {
445+ if ([queueWaitingLock tryLock ]) // if it's locked, there's thread waiting for finish
446+ {
447+ [queueWaitingLock unlock ]; // can't lock/unlock across threads, so new lock will have to be made
448+ [self performSelectorInBackground: @selector (waitForQueuesToFinish ) withObject: nil ];
449+ }
447450 }
448- }
449- else
450- {
451- [progressBar startAnimation: nil ];
452- [self waitInBackgroundForQueuesToFinish ];
453- }
451+ }
454452}
455453
456454#define PNG_ENABLED 1
0 commit comments