]> granicus.if.org Git - handbrake/commitdiff
MacGui: do not update the UI if the windows are not visible.
authorDamiano Galassi <damiog@gmail.com>
Tue, 12 Dec 2017 15:11:34 +0000 (16:11 +0100)
committerDamiano Galassi <damiog@gmail.com>
Tue, 12 Dec 2017 15:11:34 +0000 (16:11 +0100)
macosx/HBController.m
macosx/HBQueueController.m

index 84ed25c757301dad99bc283a630422d35b85c14d..75338bcc7f33fb93e99fc5f1ef09af38d2e9f49d 100644 (file)
 /// 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
 
         _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"];
     [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]];
 
 #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;
 
 - (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)
     {
index 74b3ffd5d0d83cf512a8d3ae2130b4e7a107cbe6..a57e0fbaa0f447466cbb7f5aabb278826436dabe 100644 (file)
 
 @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;
 
         _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];
     [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.
  */
             [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:@""];
     // 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
             [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