fix: crash when calling setProgressBar on macOS (#16374)
* fix: correctly check whether dock has progress bar * fix: do not leak memory when setting dockTile
This commit is contained in:
parent
698d348168
commit
758d709c7a
1 changed files with 13 additions and 7 deletions
|
@ -1131,17 +1131,23 @@ void NativeWindowMac::SetProgressBar(double progress,
|
||||||
const NativeWindow::ProgressState state) {
|
const NativeWindow::ProgressState state) {
|
||||||
NSDockTile* dock_tile = [NSApp dockTile];
|
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
|
// For the first time API invoked, we need to create a ContentView in
|
||||||
// DockTile.
|
// DockTile.
|
||||||
if (dock_tile.contentView == nullptr) {
|
if (first_time) {
|
||||||
NSImageView* image_view = [[NSImageView alloc] init];
|
NSImageView* image_view = [[[NSImageView alloc] init] autorelease];
|
||||||
[image_view setImage:[NSApp applicationIconImage]];
|
[image_view setImage:[NSApp applicationIconImage]];
|
||||||
[dock_tile setContentView:image_view];
|
[dock_tile setContentView:image_view];
|
||||||
}
|
|
||||||
|
|
||||||
if ([[dock_tile.contentView subviews] count] == 0) {
|
NSRect frame = NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0);
|
||||||
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
|
NSProgressIndicator* progress_indicator =
|
||||||
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
|
[[[AtomProgressBar alloc] initWithFrame:frame] autorelease];
|
||||||
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
|
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
|
||||||
[progress_indicator setIndeterminate:NO];
|
[progress_indicator setIndeterminate:NO];
|
||||||
[progress_indicator setBezeled:YES];
|
[progress_indicator setBezeled:YES];
|
||||||
|
@ -1152,7 +1158,7 @@ void NativeWindowMac::SetProgressBar(double progress,
|
||||||
}
|
}
|
||||||
|
|
||||||
NSProgressIndicator* progress_indicator = static_cast<NSProgressIndicator*>(
|
NSProgressIndicator* progress_indicator = static_cast<NSProgressIndicator*>(
|
||||||
[[[dock_tile contentView] subviews] objectAtIndex:0]);
|
[[[dock_tile contentView] subviews] lastObject]);
|
||||||
if (progress < 0) {
|
if (progress < 0) {
|
||||||
[progress_indicator setHidden:YES];
|
[progress_indicator setHidden:YES];
|
||||||
} else if (progress > 1) {
|
} else if (progress > 1) {
|
||||||
|
|
Loading…
Reference in a new issue