Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash due to the use of NSAlert from non-main Thread #234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions Cakebrew/BPHomebrewInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,20 @@ - (NSString *)getValidUserShellPath

if (!isValidShell)
{
static NSAlert *alert = nil;
if (!alert) {
alert = [[NSAlert alloc] init];
[alert setMessageText:NSLocalizedString(@"Message_Shell_Invalid_Title", nil)];
[alert addButtonWithTitle:NSLocalizedString(@"Generic_OK", nil)];
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Message_Shell_Invalid_Body", nil), userShell]];
}
[alert performSelectorOnMainThread:@selector(runModal) withObject:nil waitUntilDone:YES];

static NSAlert *alert = nil;
dispatch_group_t waitForFinish = dispatch_group_create();
dispatch_group_enter(waitForFinish);
dispatch_async(dispatch_get_main_queue(), ^{
if (!alert) {
alert = [[NSAlert alloc] init];
[alert setMessageText:NSLocalizedString(@"Message_Shell_Invalid_Title", nil)];
[alert addButtonWithTitle:NSLocalizedString(@"Generic_OK", nil)];
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Message_Shell_Invalid_Body", nil), userShell]];
}
[alert runModal];
dispatch_group_leave(waitForFinish);
});
dispatch_group_wait(waitForFinish, DISPATCH_TIME_FOREVER);
NSLog(@"No valid shell found...");
return nil;
}
Expand Down