summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2017-12-12 16:11:34 +0100
committerDamiano Galassi <[email protected]>2017-12-12 16:11:34 +0100
commit462d4aa8d369266bbc8204148c6da85930893790 (patch)
tree4ecf8d5cdade346a088ed29d8cf1fd323ce513b4 /macosx
parent92c643e6e7ea1c80514561691b91ce3767498c2c (diff)
MacGui: do not update the UI if the windows are not visible.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBController.m47
-rw-r--r--macosx/HBQueueController.m49
2 files changed, 84 insertions, 12 deletions
diff --git a/macosx/HBController.m b/macosx/HBController.m
index 84ed25c75..75338bcc7 100644
--- a/macosx/HBController.m
+++ b/macosx/HBController.m
@@ -120,9 +120,17 @@
/// Whether the job has been edited after a preset was applied.
@property (nonatomic) BOOL edited;
-/// The HBCore used for scanning.
+/// The HBCore used for scanning.
@property (nonatomic, strong) HBCore *core;
+/// Whether the window is visible or occluded,
+/// useful to avoid updating the UI needlessly
+@property (nonatomic) BOOL visible;
+
+/// Queue progress info
+@property (nonatomic, copy) NSString *progressInfo;
+@property (nonatomic) double progress;
+
@property (nonatomic, readwrite) NSColor *labelColor;
@end
@@ -153,6 +161,13 @@
_scanSpecificTitleIdx = 1;
+ // Progress
+ _progressInfo = @"";
+ if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10)
+ {
+ _visible = YES;
+ }
+
// Check to see if the last destination has been set, use if so, if not, use Movies
#ifdef __SANDBOX_ENABLED__
NSData *bookmark = [[NSUserDefaults standardUserDefaults] objectForKey:@"HBLastDestinationDirectoryBookmark"];
@@ -188,7 +203,7 @@
[self enableUI:NO];
// Bottom
- [fStatusField setStringValue:@""];
+ [self updateProgress];
// Register HBController's Window as a receiver for files/folders drag & drop operations
[self.window registerForDraggedTypes:@[NSFilenamesPboardType]];
@@ -1000,6 +1015,25 @@
#pragma mark - Queue progress
+- (void)windowDidChangeOcclusionState:(NSNotification *)notification
+{
+ if ([self.window occlusionState] & NSWindowOcclusionStateVisible)
+ {
+ self.visible = YES;
+ [self updateProgress];
+ }
+ else
+ {
+ self.visible = NO;
+ }
+}
+
+- (void)updateProgress
+{
+ fStatusField.stringValue = self.progressInfo;
+ fRipIndicator.doubleValue = self.progress;
+}
+
- (void)setQueueState:(NSUInteger)count
{
self.showQueueToolbarItem.badgeValue = count ? @(count).stringValue : nil;
@@ -1007,8 +1041,13 @@
- (void)setQueueInfo:(NSString *)info progress:(double)progress hidden:(BOOL)hidden
{
- fStatusField.stringValue = info;
- fRipIndicator.doubleValue = progress;
+ self.progressInfo = info;
+ self.progress = progress;
+
+ if (_visible)
+ {
+ [self updateProgress];
+ }
if (hidden)
{
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 () <NSOutlineViewDataSource, HBQueueOutlineViewDelegate>
+/// 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