flutter / flutter-intellij

Flutter Plugin for IntelliJ
https://flutter.dev/using-ide
BSD 3-Clause "New" or "Revised" License
1.97k stars 316 forks source link

[proposal] Provide a way to call `FlutterSdk.flutterRun` in non paused state #5461

Open pedromassangocode opened 3 years ago

pedromassangocode commented 3 years ago

Steps to Reproduce

I'm building a IntelliJ plugin which depends on this Flutter plugin to execute some Flutter commands. I'm using the FlutterSdk.flutterRun method to run the opened project and everything works fine. However I noticed that when I run on a device (Android, web or MacOS) in debug mode, the app is started in paused mode: it builds the app on the device, but I get a blank app (the Flutter UI is not rendered).

After some investigation I notice that the method I'm using is adding the --start-paused option automatically:

https://github.com/flutter/flutter-intellij/blob/f21250eaedeed48397c24cddef7d30c75ad19db1/src/io/flutter/sdk/FlutterSdk.java#L277-L279

Proposal

Provide a way to prevent this flag of being passed automatically.

Version info

flutter run -v ```console [✓] Flutter (Channel stable, 2.0.6, on macOS 11.2.3 20D91 darwin-x64, locale en-AO) • Flutter version 2.0.6 at /Users/pedromassango/Code/flutter_stable • Framework revision 1d9032c7e1 (5 days ago), 2021-04-29 17:37:58 -0700 • Engine revision 05e680e202 • Dart version 2.12.3 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/pedromassango/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /Users/pedromassango/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.4, Build version 12D4e • CocoaPods version 1.10.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [✓] IntelliJ IDEA Community Edition (version 2021.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 55.1.5 • Dart plugin version 211.7179 [✓] VS Code (version 1.55.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.16.0 [✓] Connected device (3 available) • Redmi 5 Plus (mobile) • 0258ff700005 • android-arm64 • Android 8.1.0 (API 27) • macOS (desktop) • macos • darwin-x64 • macOS 11.2.3 20D91 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.93 • No issues found! ```
stevemessick commented 3 years ago

We start paused so breakpoints can be set before the app starts.

pedromassango commented 3 years ago

We start paused so breakpoints can be set before the app starts.

Hi @stevemessick Sorry if I was not clear enough, This proposal is to add an option to avoid the flag to be passed and not to remove the flag completely, my use-case is to run the project, I don't care much about breakpoints as I'm not running the app for debugging purposes.

@stevemessick we can either do this proposal or make it clear how to resume the app once flutterRun is called.

stevemessick commented 3 years ago

You might be able to get the effect you want by defining a new type of RunMode. If you'd like to put together a PR I'll be happy to review it.

Resuming a paused app is non-trivial. An example is in FlutterTestRunner.run().

pedromassangocode commented 3 years ago

I will definitely work on this. Is flutterRun the only place I need to make the change? Just to make sure I don't break anything.

Also, is there any other side-effect (besides the begugger/breakpints won't work) if I just pass the RunMode.PROFILE (with any of the FlutterLaunchMode options) to just workaround this problem? Currently if I pass the profile mode it works as expected, however I'm not sure what this may cause.

stevemessick commented 3 years ago

Using profile mode might work, but Bazel projects could have some unintended side-effect -- I'm not an expert on that. (I'm not sure how common Bazel is outside Google, but it is common within the company.) @helin24 might know more about Bazel. Using profile mode will cause your app to run in profile mode on the device, which may or may not be what you want.

You'd need to look at how RunMode.PROFILE is used, and trace back those dependencies to understand how to add a new kind of RunMode. You may not need to change flutterRun() at all.

pedromassango commented 3 years ago

Yes, for what I can see it being used for Bazel projects only.

https://github.com/flutter/flutter-intellij/blob/ac43db943ce2a53300aefd1cd21b1b1e79d6f5b0/src/io/flutter/run/bazel/BazelFields.java#L248-L260

Using profile mode will cause your app to run in profile mode on the device, which may or may not be what you want.

I did some tests and by calling flutterRun() with RunMode.PROFILE and any of the FlutterLaunchMode the project were launched properly. By that I mean, if use RunMode.PROFILE in combination with FlutterLaunchMode.DEBUG the app were launched in DEBUG mode (the same for FlutterLaunchMode.RELEASE/PROFILE) and not in Profile mode.

But I'm not exactly sure what is a Bazel project and when your statement above will be true.

helin24 commented 3 years ago

Note: another reason we use start paused mode for run is because there are some cases where early errors aren't caught and displayed if the plugin hasn't started listening to certain streams yet at the time the app starts.

If you want to put together your change I can test it out for the Bazel projects. I'm not clear on how your changes will flow through to Bazel yet.