Skip to content

Commit

Permalink
feat: Add did-become-active event on mac (#23872)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Weber <luweber@microsoft.com>
  • Loading branch information
isnotgood and Lukas Weber committed Jun 16, 2020
1 parent f9fe8a6 commit cf28499
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions shell/browser/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/browser_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/mac/electron_application_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notify {
#endif
}

- (void)applicationDidBecomeActive:(NSNotification*)notification {
electron::Browser::Get()->DidBecomeActive();
}

- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
if (menu_controller_)
return [menu_controller_ menu];
Expand Down

0 comments on commit cf28499

Please sign in to comment.