feat: Add did-become-active event on mac (#23872)

Co-authored-by: Lukas Weber <luweber@microsoft.com>
This commit is contained in:
Lukas Weber 2020-06-16 19:03:41 +02:00 committed by GitHub
parent f9fe8a67b9
commit cf284991d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 0 deletions

View file

@ -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:

View file

@ -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(

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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];