flutter icon indicating copy to clipboard operation
flutter copied to clipboard

[desktop] performing a hot reload should focus on the app

Open gaaclarke opened this issue 11 months ago • 7 comments
trafficstars

Observed result

  1. Launch a macos flutter app from the terminal
  2. Change the code
  3. go to the terminal and perform a hot reload
  4. 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.

gaaclarke avatar Dec 16 '24 22:12 gaaclarke

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

  1. I probably have moved the app window to a second display anyway, and
  2. 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.

andrewkolos avatar Dec 16 '24 23:12 andrewkolos

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.

gaaclarke avatar Dec 16 '24 23:12 gaaclarke

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.

flutter-triage-bot[bot] avatar Dec 17 '24 00:12 flutter-triage-bot[bot]

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?

stuartmorgan-g avatar Dec 17 '24 01:12 stuartmorgan-g

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.

gaaclarke avatar Dec 17 '24 17:12 gaaclarke

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.

cbracken avatar Dec 20 '24 22:12 cbracken

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.

gaaclarke avatar Dec 20 '24 23:12 gaaclarke

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.

bkonyi avatar Jan 14 '25 19:01 bkonyi