fix: unsubscribe from observers when window is closing (#25554)
This commit is contained in:
parent
29c6864ee1
commit
22c6c891be
3 changed files with 11 additions and 10 deletions
|
@ -32,6 +32,11 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||||
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
|
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
|
||||||
~NativeWindowMac() override;
|
~NativeWindowMac() override;
|
||||||
|
|
||||||
|
// Cleanup observers when window is getting closed. Note that the destructor
|
||||||
|
// can be called much later after window gets closed, so we should not do
|
||||||
|
// cleanup in destructor.
|
||||||
|
void Cleanup();
|
||||||
|
|
||||||
// NativeWindow:
|
// NativeWindow:
|
||||||
void SetContentView(views::View* view) override;
|
void SetContentView(views::View* view) override;
|
||||||
void Close() override;
|
void Close() override;
|
||||||
|
|
|
@ -536,9 +536,11 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
original_level_ = [window_ level];
|
original_level_ = [window_ level];
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindowMac::~NativeWindowMac() {
|
NativeWindowMac::~NativeWindowMac() {}
|
||||||
|
|
||||||
|
void NativeWindowMac::Cleanup() {
|
||||||
|
DCHECK(!IsClosed());
|
||||||
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
||||||
if (wheel_event_monitor_)
|
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,13 +637,6 @@ void NativeWindowMac::Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::CloseImmediately() {
|
void NativeWindowMac::CloseImmediately() {
|
||||||
// Remove event monitor before destroying window, otherwise the monitor may
|
|
||||||
// call its callback after window has been destroyed.
|
|
||||||
if (wheel_event_monitor_) {
|
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
|
||||||
wheel_event_monitor_ = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retain the child window before closing it. If the last reference to the
|
// Retain the child window before closing it. If the last reference to the
|
||||||
// NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
|
// NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
|
||||||
// See e.g. http://crbug.com/616701.
|
// See e.g. http://crbug.com/616701.
|
||||||
|
|
|
@ -283,6 +283,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowWillClose:(NSNotification*)notification {
|
- (void)windowWillClose:(NSNotification*)notification {
|
||||||
|
shell_->Cleanup();
|
||||||
shell_->NotifyWindowClosed();
|
shell_->NotifyWindowClosed();
|
||||||
|
|
||||||
// Something called -[NSWindow close] on a sheet rather than calling
|
// Something called -[NSWindow close] on a sheet rather than calling
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue