Skip to content

Commit

Permalink
fix: correctly check whether dock has progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jan 12, 2019
1 parent 134792a commit af1b0b9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions atom/browser/native_window_mac.mm
Expand Up @@ -1127,15 +1127,20 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
const NativeWindow::ProgressState state) {
NSDockTile* dock_tile = [NSApp dockTile];

// Sometimes macOS would install a default contentView for dock, we must
// verify whether NSProgressIndicator has been installed.
bool first_time = !dock_tile.contentView ||
[[dock_tile.contentView subviews] count] == 0 ||
![[[dock_tile.contentView subviews] lastObject]
isKindOfClass:[NSProgressIndicator class]];

// For the first time API invoked, we need to create a ContentView in
// DockTile.
if (dock_tile.contentView == nullptr) {
if (first_time) {
NSImageView* image_view = [[NSImageView alloc] init];
[image_view setImage:[NSApp applicationIconImage]];
[dock_tile setContentView:image_view];
}

if ([[dock_tile.contentView subviews] count] == 0) {
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
Expand All @@ -1148,7 +1153,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

NSProgressIndicator* progress_indicator = static_cast<NSProgressIndicator*>(
[[[dock_tile contentView] subviews] objectAtIndex:0]);
[[[dock_tile contentView] subviews] lastObject]);
if (progress < 0) {
[progress_indicator setHidden:YES];
} else if (progress > 1) {
Expand Down

0 comments on commit af1b0b9

Please sign in to comment.