mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add did-resign-active event on app (#38018)
feat: add did-resign-active event on app Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -787,6 +787,10 @@ void App::OnNewWindowForTab() {
|
||||
void App::OnDidBecomeActive() {
|
||||
Emit("did-become-active");
|
||||
}
|
||||
|
||||
void App::OnDidResignActive() {
|
||||
Emit("did-resign-active");
|
||||
}
|
||||
#endif
|
||||
|
||||
bool App::CanCreateWindow(
|
||||
|
||||
@@ -116,6 +116,7 @@ class App : public ElectronBrowserClient::Delegate,
|
||||
base::Value::Dict user_info) override;
|
||||
void OnNewWindowForTab() override;
|
||||
void OnDidBecomeActive() override;
|
||||
void OnDidResignActive() override;
|
||||
#endif
|
||||
|
||||
// content::ContentBrowserClient:
|
||||
|
||||
@@ -291,6 +291,11 @@ void Browser::DidBecomeActive() {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnDidBecomeActive();
|
||||
}
|
||||
|
||||
void Browser::DidResignActive() {
|
||||
for (BrowserObserver& observer : observers_)
|
||||
observer.OnDidResignActive();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -278,8 +278,11 @@ class Browser : public WindowListObserver {
|
||||
// Tell the application to create a new window for a tab.
|
||||
void NewWindowForTab();
|
||||
|
||||
// Tell the application that application did become active
|
||||
// Indicate that the app is now active.
|
||||
void DidBecomeActive();
|
||||
// Indicate that the app is no longer active and doesn’t have focus.
|
||||
void DidResignActive();
|
||||
|
||||
#endif // BUILDFLAG(IS_MAC)
|
||||
|
||||
// Tell the application that application is activated with visible/invisible
|
||||
|
||||
@@ -78,8 +78,10 @@ class BrowserObserver : public base::CheckedObserver {
|
||||
// User clicked the native macOS new tab button. (macOS only)
|
||||
virtual void OnNewWindowForTab() {}
|
||||
|
||||
// Browser did become active.
|
||||
// Browser became active.
|
||||
virtual void OnDidBecomeActive() {}
|
||||
// Browser lost active status.
|
||||
virtual void OnDidResignActive() {}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -92,6 +92,10 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
|
||||
electron::Browser::Get()->DidBecomeActive();
|
||||
}
|
||||
|
||||
- (void)applicationDidResignActive:(NSNotification*)notification {
|
||||
electron::Browser::Get()->DidResignActive();
|
||||
}
|
||||
|
||||
- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
|
||||
if (menu_controller_)
|
||||
return [menu_controller_ menu];
|
||||
|
||||
Reference in New Issue
Block a user