Skip to content

fix: trigger activate event when app is activated via app switcher - #23727

Merged
jkleinsc merged 1 commit into
electron:masterfrom
isnotgood:fix-mac-activation
May 26, 2020
Merged

jkleinsc merged 1 commit into
electron:masterfrom
isnotgood:fix-mac-activation

Conversation

@isnotgood

Copy link
Copy Markdown
Contributor

When application is activated thru macOS app switcher (cmd+tab) the App's activate event is note emitted. Here is Electron Fiddle with steps to repro (tested on macOS 10.15.4).

Description of Change

The reason is that applicationShouldHandleReopen:hasVisibleWindows: is sent only when app
is activated via Dock not the other ways like app switcher. Using applicationDidBecomeActive: is handling all the cases properly. Also to maintain backward compatibility I added logic to avoid firing 'activate' event after the application launch.

Checklist

Release Notes

Notes: none

@welcome

welcome Bot commented May 22, 2020

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label May 22, 2020
@isnotgood
isnotgood marked this pull request as ready for review May 22, 2020 14:36
@isnotgood

Copy link
Copy Markdown
Contributor Author

Tests are failing but the same one are failing on develop as well. I guess it's being taken care of in #23699.

Also I didn't provided any tests for this, but if anyone will give me some hints how to test this functionality I'll be happy to do so 😄

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label May 23, 2020

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave a comment in the code on why applicationDidBecomeActive is used for implementing Activate? In case someone else refactored the code in future.

A link to this PR should be enough.

When application is activated thru macOS app switcher (cmd+tab) the
App's activate event is note emitted. The reason is that
`applicationShouldHandleReopen:hasVisibleWindows:` is sent only when app
is activated via Dock. Using `applicationDidBecomeActive:` is handling
all cases properly.
@isnotgood

Copy link
Copy Markdown
Contributor Author

@zcbenz yeah, of course! Updated the comment in the code. Thanks for taking look at it 🙇

@jkleinsc
jkleinsc merged commit 2bc85b2 into electron:master May 26, 2020
@welcome

welcome Bot commented May 26, 2020

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented May 26, 2020

Copy link
Copy Markdown

No Release Notes

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "10-x-y", please check out #23771

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "8-x-y", please check out #23772

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "9-x-y", please check out #23773

@alexeykuzmin

Copy link
Copy Markdown
Contributor

/trop run backport

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

The backport process for this PR has been manually initiated, here we go! :D

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "7-3-x" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented May 26, 2020

Copy link
Copy Markdown
Contributor

@isnotgood has manually backported this PR to "7-3-x", please check out #23775

@bpasero

bpasero commented May 28, 2020

Copy link
Copy Markdown
Contributor

@isnotgood I do not fully understand this change. Does this mean app.on('activate') will fire when you switch to the Electron app and before it was not? That sounds like a breaking change to me because e.g. VSCode opens a window when none is opened and I would not expect that to happen unless you click the dock icon.

@isnotgood

Copy link
Copy Markdown
Contributor Author

@bpasero ouch, unfortunately you understand correctly😢 In that case we need to revert this one back to use applicationShouldHandleReopen:hasVisibleWindows: not to break existing apps which use it for reopen handling and add new mac specific event for actual activation of the app app.on('did-become-active') as I don't see any other way how to handle that use case. @zcbenz wdyt?

@bpasero

bpasero commented May 28, 2020

Copy link
Copy Markdown
Contributor

Yes, adding a separate event seems better.

@zcbenz

zcbenz commented May 28, 2020

Copy link
Copy Markdown
Contributor

Yeah this should be reverted and adding a new event looks good to me. I'll revert the PRs, thanks for bringing this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants