feat: Add did-become-active event on mac (#23872)
Co-authored-by: Lukas Weber <luweber@microsoft.com>
This commit is contained in:
parent
f9fe8a67b9
commit
cf284991d8
7 changed files with 30 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue