diff --git a/docs/api/app.md b/docs/api/app.md index 5d76e8ed92a..1f040f9667f 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -140,6 +140,16 @@ this event, such as launching the application for the first time, attempting to re-launch the application when it's already running, or clicking on the application's dock or taskbar icon. +### Event: 'did-become-active' _macOS_ + +Returns: + +* `event` Event + +Emitted when mac application become active. Difference from `activate` event is +that `did-become-active` is emitted every time the app becomes active, not only +when Dock icon is clicked or application is re-launched. + ### Event: 'continue-activity' _macOS_ Returns: diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 9ca9a7ad0dd..51b0710a148 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -684,6 +684,10 @@ void App::OnUpdateUserActivityState(bool* prevent_default, void App::OnNewWindowForTab() { Emit("new-window-for-tab"); } + +void App::OnDidBecomeActive() { + Emit("did-become-active"); +} #endif bool App::CanCreateWindow( diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index 52380508039..fade809f893 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -106,6 +106,7 @@ class App : public ElectronBrowserClient::Delegate, const std::string& type, const base::DictionaryValue& user_info) override; void OnNewWindowForTab() override; + void OnDidBecomeActive() override; #endif // content::ContentBrowserClient: diff --git a/shell/browser/browser.cc b/shell/browser/browser.cc index 5bb6e74e2e7..3d8513025e7 100644 --- a/shell/browser/browser.cc +++ b/shell/browser/browser.cc @@ -262,6 +262,11 @@ void Browser::NewWindowForTab() { for (BrowserObserver& observer : observers_) observer.OnNewWindowForTab(); } + +void Browser::DidBecomeActive() { + for (BrowserObserver& observer : observers_) + observer.OnDidBecomeActive(); +} #endif } // namespace electron diff --git a/shell/browser/browser.h b/shell/browser/browser.h index 0cce2b27508..b0e88dbd3b3 100644 --- a/shell/browser/browser.h +++ b/shell/browser/browser.h @@ -240,6 +240,9 @@ class Browser : public WindowListObserver { #if defined(OS_MACOSX) // Tell the application to create a new window for a tab. void NewWindowForTab(); + + // Tell the application that application did become active + void DidBecomeActive(); #endif // defined(OS_MACOSX) // Tell the application that application is activated with visible/invisible diff --git a/shell/browser/browser_observer.h b/shell/browser/browser_observer.h index 95f5064677e..3eae894055e 100644 --- a/shell/browser/browser_observer.h +++ b/shell/browser/browser_observer.h @@ -82,6 +82,9 @@ class BrowserObserver : public base::CheckedObserver { const base::DictionaryValue& user_info) {} // User clicked the native macOS new tab button. (macOS only) virtual void OnNewWindowForTab() {} + + // Browser did become active. + virtual void OnDidBecomeActive() {} #endif protected: diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index 73da6ec7c51..4dabcabc0d8 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/shell/browser/mac/electron_application_delegate.mm @@ -89,6 +89,10 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session; #endif } +- (void)applicationDidBecomeActive:(NSNotification*)notification { + electron::Browser::Get()->DidBecomeActive(); +} + - (NSMenu*)applicationDockMenu:(NSApplication*)sender { if (menu_controller_) return [menu_controller_ menu];