flutter
flutter copied to clipboard
[desktop] performing a hot reload should focus on the app
Observed result
- Launch a macos flutter app from the terminal
- Change the code
- go to the terminal and perform a hot reload
- Notice now that you have to find the app and bring it to focus to see the results with something like alt+tab.
Expected result
I'd expect that performing a hot reload would bring the app into focus when performing a hot reload.
Proposal
Focusing on the app should be the default behavior for the flutter tool when developing desktop apps. We can add a flag --no-auto-focus to override that behavior in case someone ever doesn't like it.
I am not a professional Flutter app developer, but I imagine this is something I would not want unless I only ever work off of a single monitor/display.
If I am rapidly experimenting with UI changes, then
- I probably have moved the app window to a second display anyway, and
- I want my IDE to remain focused so that I can make changes and hot reload again as quickly as possible.
If the tool were to bring the app window into focus, then I would have to alt-tab back to my IDE to resume experimenting with code changes. The "I have to alt-tab to continue" problem isn't solved—it just gets moved to a different part of the workflow.
I would be interested to hear from folks about what their workflow is like when using hot reload on desktop.
I want my IDE to remain focused
In the scenario I laid out above, hot reload is being invoked from the terminal, not an IDE. In that case there is nothing more meaningful that can happen from the terminal.
You make a good point about an IDE though.
Issue is assigned to multiple teams (tool, macos). Please ensure the issue has only one team-* label at a time. Use fyi-* labels to have another team look at the issue without reassigning it.
I'd expect that performing a hot reload would bring the app into focus when performing a hot reload.
Is there a reason you expect this for desktop targets but not for a mobile app running in a simulator/emulator?
Is there a reason you expect this for desktop targets but not for a mobile app running in a simulator/emulator?
This could be a problem for the simulator/emulator too. It didn't occur to me since it wasn't what I was currently running into.
I don't think we want per-platform behaviour for this; we probably want to decide on a policy and use that across all platforms -- or, if justified, one for desktop platforms and another for simulator/emulators? I'm going to re-triage as a tool issue for further discussion.
fwiw, if I'm working in a terminal window, I generally wouldn't expect it to refocus other windows. The only cases I can think of are running dbus commands specifically to focus windows in e.g. a tiling window manager etc. on Linux.
Looks like Apple waffled on this themselves with the open command. There is now a vestigial --background flag.
I think this is another example of something that would be nice to have flutter tool plugins for since there are people that want this but it would be better as a module instead of bloating the tool with a feature where less than half of the people will use it.
I think this is actually something that would need to be implemented in either the engine or the embedders, assuming there's a hook for handling a hot restart (I can't remember the exact implementation in the engine). Either way, this is probably not a high priority and, as @gaaclarke mentioned, could potentially be implemented as a plugin.