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 on BrowserWindow.setEnabled() #34973

Merged
Show file tree
Hide file tree
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
19 changes: 15 additions & 4 deletions shell/browser/native_window_mac.mm
Expand Up @@ -483,7 +483,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
// [window_ performClose:nil], the window won't close properly
// even after the user has ended the sheet.
// Ensure it's closed before calling [window_ performClose:nil].
SetEnabled(true);
if ([window_ attachedSheet])
[window_ endSheet:[window_ attachedSheet]];

[window_ performClose:nil];

Expand Down Expand Up @@ -553,7 +554,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
// If a sheet is attached to the window when we call [window_ orderOut:nil],
// the sheet won't be able to show again on the same window.
// Ensure it's closed before calling [window_ orderOut:nil].
SetEnabled(true);
if ([window_ attachedSheet])
[window_ endSheet:[window_ attachedSheet]];

if (is_modal() && parent()) {
[window_ orderOut:nil];
Expand Down Expand Up @@ -597,9 +599,18 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

void NativeWindowMac::SetEnabled(bool enable) {
if (!enable) {
[window_ beginSheet:window_
NSRect frame = [window_ frame];
NSWindow* window =
[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, frame.size.width,
frame.size.height)
styleMask:NSWindowStyleMaskTitled
backing:NSBackingStoreBuffered
defer:NO];
[window setAlphaValue:0.5];

[window_ beginSheet:window
completionHandler:^(NSModalResponse returnCode) {
NSLog(@"modal enabled");
NSLog(@"main window disabled");
return;
}];
} else if ([window_ attachedSheet]) {
Expand Down
8 changes: 8 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -4234,6 +4234,14 @@ describe('BrowserWindow module', () => {
await createTwo();
});

ifit(process.platform !== 'darwin')('can disable and enable a window', () => {
const w = new BrowserWindow({ show: false });
w.setEnabled(false);
expect(w.isEnabled()).to.be.false('w.isEnabled()');
w.setEnabled(true);
expect(w.isEnabled()).to.be.true('!w.isEnabled()');
});

ifit(process.platform !== 'darwin')('disables parent window', () => {
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w, modal: true });
Expand Down