From 440fb9a73eb2227458b5b5074a0926181cfb23f9 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 18 Jul 2025 10:09:40 +0200 Subject: [PATCH] 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 --- shell/browser/ui/cocoa/electron_ns_window.mm | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/shell/browser/ui/cocoa/electron_ns_window.mm b/shell/browser/ui/cocoa/electron_ns_window.mm index e657539adf49..40cd21029503 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.mm +++ b/shell/browser/ui/cocoa/electron_ns_window.mm @@ -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