fix: handle missing NativeWindowMac in ElectronNSWindow (#47811)

fix: handle missing NativeWindowMac in ElectronNSWindow

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-07-18 10:09:40 +02:00 committed by GitHub
parent 8c974c022a
commit 440fb9a73e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -176,10 +176,8 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (id)accessibilityFocusedUIElement {
views::Widget* widget = shell_->widget();
id superFocus = [super accessibilityFocusedUIElement];
if (!widget || shell_->IsFocused())
return superFocus;
if (!shell_ || !shell_->widget() || shell_->IsFocused())
return [super accessibilityFocusedUIElement];
return nil;
}
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect {
@ -187,7 +185,7 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (NSTouchBar*)makeTouchBar {
if (shell_->touch_bar())
if (shell_ && shell_->touch_bar())
return [shell_->touch_bar() makeTouchBar];
else
return nil;
@ -217,7 +215,8 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (void)rotateWithEvent:(NSEvent*)event {
shell_->NotifyWindowRotateGesture(event.rotation);
if (shell_)
shell_->NotifyWindowRotateGesture(event.rotation);
}
- (NSRect)contentRectForFrameRect:(NSRect)frameRect {
@ -241,7 +240,7 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
//
// If there's no frame, put the window wherever the developer
// wanted it to go
if (shell_->has_frame()) {
if (shell_ && shell_->has_frame()) {
result.size = frameRect.size;
} else {
result = frameRect;
@ -288,7 +287,7 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (NSString*)accessibilityTitle {
return base::SysUTF8ToNSString(shell_->GetTitle());
return base::SysUTF8ToNSString(shell_ ? shell_->GetTitle() : "");
}
- (BOOL)canBecomeMainWindow {
@ -308,7 +307,7 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
// support closing a window without title we need to manually do menu item
// validation. This code path is used by the "roundedCorners" option.
if ([item action] == @selector(performClose:))
return shell_->IsClosable();
return shell_ && shell_->IsClosable();
return [super validateUserInterfaceItem:item];
}
@ -328,7 +327,8 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
// shown, but we don't want the headless behavior of allowing the window to
// be placed unconstrained.
self.isHeadless = false;
shell_->widget()->DisableHeadlessMode();
if (shell_->widget())
shell_->widget()->DisableHeadlessMode();
}
}
@ -378,6 +378,9 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (BOOL)toggleFullScreenMode:(id)sender {
if (!shell_)
return NO;
bool is_simple_fs = shell_->IsSimpleFullScreen();
bool always_simple_fs = shell_->always_simple_fullscreen();
@ -411,11 +414,13 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (void)performMiniaturize:(id)sender {
if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover)
if (shell_ &&
shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover) {
[self miniaturize:self];
else
} else {
[super performMiniaturize:sender];
}
}
@end