Merge pull request #9254 from electron/endsession-event

End session event on browser window
This commit is contained in:
Kevin Sawicki 2017-04-24 12:02:05 -07:00 committed by GitHub
commit 7881376aff
7 changed files with 24 additions and 0 deletions

View file

@ -191,6 +191,10 @@ void Window::OnWindowClosed() {
FROM_HERE, GetDestroyClosure());
}
void Window::OnWindowEndSession() {
Emit("session-end");
}
void Window::OnWindowBlur() {
Emit("blur");
}

View file

@ -63,6 +63,7 @@ class Window : public mate::TrackableObject<Window>,
void WillCloseWindow(bool* prevent_default) override;
void WillDestroyNativeObject() override;
void OnWindowClosed() override;
void OnWindowEndSession() override;
void OnWindowBlur() override;
void OnWindowFocus() override;
void OnWindowShow() override;

View file

@ -474,6 +474,11 @@ void NativeWindow::NotifyWindowClosed() {
observer.OnWindowClosed();
}
void NativeWindow::NotifyWindowEndSession() {
for (NativeWindowObserver& observer : observers_)
observer.OnWindowEndSession();
}
void NativeWindow::NotifyWindowBlur() {
for (NativeWindowObserver& observer : observers_)
observer.OnWindowBlur();

View file

@ -218,6 +218,7 @@ class NativeWindow : public base::SupportsUserData,
// Public API used by platform-dependent delegates and observers to send UI
// related notifications.
void NotifyWindowClosed();
void NotifyWindowEndSession();
void NotifyWindowBlur();
void NotifyWindowFocus();
void NotifyWindowShow();

View file

@ -40,6 +40,9 @@ class NativeWindowObserver {
// Called when the window is closed.
virtual void OnWindowClosed() {}
// Called when Windows sends WM_ENDSESSION message
virtual void OnWindowEndSession() {}
// Called when window loses focus.
virtual void OnWindowBlur() {}

View file

@ -147,6 +147,11 @@ bool NativeWindowViews::PreHandleMSG(
}
return false;
}
case WM_ENDSESSION: {
if (w_param) {
NotifyWindowEndSession();
}
}
default:
return false;
}

View file

@ -376,6 +376,11 @@ window.onbeforeunload = (e) => {
Emitted when the window is closed. After you have received this event you should
remove the reference to the window and avoid using it any more.
#### Event: 'session-end' _Windows_
Emitted when window session is going to end due to force shutdown or machine restart
or session log off.
#### Event: 'unresponsive'
Emitted when the web page becomes unresponsive.