diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 4cf2fee82f71..72b8e33ef7b5 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -191,6 +191,10 @@ void Window::OnWindowClosed() { FROM_HERE, GetDestroyClosure()); } +void Window::OnWindowEndSession() { + Emit("session-end"); +} + void Window::OnWindowBlur() { Emit("blur"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 1388b63de75a..75f0328ba64f 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -63,6 +63,7 @@ class Window : public mate::TrackableObject, void WillCloseWindow(bool* prevent_default) override; void WillDestroyNativeObject() override; void OnWindowClosed() override; + void OnWindowEndSession() override; void OnWindowBlur() override; void OnWindowFocus() override; void OnWindowShow() override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 93bfc76c51e4..9e2c11aec4ab 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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(); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 48b56e8b47ea..d3f18d8fb95c 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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(); diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 191f1bcab492..8c908dc8237a 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -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() {} diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index 1b523e90b804..abda0d0b0262 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -147,6 +147,11 @@ bool NativeWindowViews::PreHandleMSG( } return false; } + case WM_ENDSESSION: { + if (w_param) { + NotifyWindowEndSession(); + } + } default: return false; } diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index cd55ba0bbda3..8fcc3f8213d0 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -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.