From 462d4aa8d369266bbc8204148c6da85930893790 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 12 Dec 2017 16:11:34 +0100 Subject: MacGui: do not update the UI if the windows are not visible. --- macosx/HBQueueController.m | 49 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'macosx/HBQueueController.m') diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index 74b3ffd5d..a57e0fbaa 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -30,6 +30,13 @@ @interface HBQueueController () +/// Whether the window is visible or occluded, +/// useful to avoid updating the UI needlessly +@property (nonatomic) BOOL visible; + +// Progress +@property (nonatomic, strong) NSString *progressInfo; + @property (nonatomic, readonly) HBDockTile *dockTile; @property (nonatomic, readwrite) double dockIconProgress; @@ -73,6 +80,13 @@ _core = [[HBCore alloc] initWithLogLevel:loggingLevel name:@"QueueCore"]; _core.automaticallyPreventSleep = NO; + // Progress + _progressInfo = @""; + if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10) + { + _visible = YES; + } + // Load the queue from disk. _jobs = [[HBDistributedArray alloc] initWithURL:queueURL class:[HBJob class]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadQueue) name:HBDistributedArrayChanged object:_jobs]; @@ -495,6 +509,29 @@ [self.jobs commit]; } +- (void)windowDidChangeOcclusionState:(NSNotification *)notification +{ + if ([self.window occlusionState] & NSWindowOcclusionStateVisible) + { + self.visible = YES; + self.progressTextField.stringValue = self.progressInfo; + } + else + { + self.visible = NO; + } +} + +- (void)updateProgress:(NSString *)info progress:(double)progress hidden:(BOOL)hidden +{ + self.progressInfo = info; + if (self.visible) + { + self.progressTextField.stringValue = info; + } + [self.controller setQueueInfo:info progress:progress hidden:hidden]; +} + /** * Updates the queue status label. */ @@ -705,8 +742,7 @@ [self jobCompletedAlerts:job result:result]; break; } - self.progressTextField.stringValue = info; - [self.controller setQueueInfo:info progress:1.0 hidden:YES]; + [self updateProgress:info progress:1.0 hidden:YES]; // Restore dock icon [self.dockTile updateDockIcon:-1.0 withETA:@""]; @@ -723,9 +759,7 @@ // Progress handler void (^progressHandler)(HBState state, HBProgress progress, NSString *info) = ^(HBState state, HBProgress progress, NSString *info) { - NSString *status = info; - self.progressTextField.stringValue = status; - [self.controller setQueueInfo:status progress:0 hidden:NO]; + [self updateProgress:info progress:0 hidden:NO]; }; // Completion handler @@ -783,9 +817,8 @@ [self.dockTile updateDockIcon:1.0 withETA:@""]; } - // Update text field - self.progressTextField.stringValue = info; - [self.controller setQueueInfo:info progress:progress.percent hidden:NO]; + // Update UI + [self updateProgress:info progress:progress.percent hidden:NO]; }; // Completion handler -- cgit v1.2.3