Skip to content

Conversation

@vashworth
Copy link
Contributor

@vashworth vashworth commented Mar 17, 2023

This PR updates the device selection flow to allow more time for wireless devices to load.

If the terminal has stdin and supports ANSI, a message is displayed while wireless devices are loading and other devices can be selected. After they are done loading, it will clear out the message and update with the device list

Connected devices:
target-device-1 (mobile) • xxx • ios • iOS 16
target-device-2 (mobile) • xxx • ios • iOS 16

Checking for wireless devices...

[1]: target-device-1 (xxx)
[2]: target-device-2 (xxx)

After done loading:

Multiple devices found:
target-device-1 (mobile) • xxx • ios • iOS 16
target-device-2 (mobile) • xxx • ios • iOS 16

Wirelessly connected devices:
target-device-5 (mobile) • xxx • ios • iOS 16

[1]: target-device-1 (xxx)
[2]: target-device-2 (xxx)
[3]: target-device-5 (xxx)

Fixes #118109.

Part 4 in breakdown of #121262.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Mar 17, 2023
@vashworth vashworth marked this pull request as ready for review March 20, 2023 22:56
}

@visibleForTesting
class MacOSTargetDevices extends TargetDevices {
Copy link
Member

Choose a reason for hiding this comment

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

This name seems like it's deploying a macOS desktop app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to TargetDevicesWithExtendedWirelessDeviceDiscovery. I changed the one in the devices command too to DevicesCommandOutputWithExtendedWirelessDeviceDiscovery. Let me know if you think that's better

final RegExp pattern = RegExp(r'\d+$|q', caseSensitive: false);
final String prompt = userMessages.flutterChooseOne;
String? choice;
globals.terminal.singleCharMode = true;
Copy link
Member

Choose a reason for hiding this comment

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

Can you use promptForCharInput instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Looks like you'll have to check first if the user is in an interactive session (unless the callers of readUserInput already guard that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not without changing it extensively. promptForCharInput requires a list of acceptable characters and then only displays and allows input of those characters. With the new process, more devices might be loaded while promptForCharInput is still waiting for user input and it can't be updated to use a new list of acceptable characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is fine

setUp(() {
cache = Cache.test(processManager: FakeProcessManager.any());
platform = FakePlatform();
testUsingContext('Ensure factory returns MacOSTargetDevices on MacOS', () async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this and the next test actually rely on the context, or can they be invoked with testWithoutContext()? And if they do rely on the context, should we be overriding those values with fake objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't need the context, good catch. Fixed.

Follow up question, though. Sometimes when it does need the context to be overridden but it doesn't need anything more custom than the default overrides (see below), is it okay to use testUsingContext without extra overrides or is it better practice to always add the overrides it needs to the test?

AnsiTerminal: () => AnsiTerminal(platform: globals.platform, stdio: globals.stdio),
Config: () => buildConfig(globals.fs),
DeviceManager: () => FakeDeviceManager(),
Doctor: () => FakeDoctor(globals.logger),
FlutterVersion: () => FakeFlutterVersion(),
HttpClient: () => FakeHttpClient.any(),
IOSSimulatorUtils: () => const NoopIOSSimulatorUtils(),
OutputPreferences: () => OutputPreferences.test(),
Logger: () => BufferLogger.test(),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
PersistentToolState: () => buildPersistentToolState(globals.fs),
Usage: () => TestUsage(),
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreter(),
FileSystem: () => LocalFileSystemBlockingSetCurrentDirectory(),
PlistParser: () => FakePlistParser(),
Signals: () => FakeSignals(),
Pub: () => ThrowingPub(), // prevent accidentally using pub.
CrashReporter: () => const NoopCrashReporter(),
TemplateRenderer: () => const MustacheTemplateRenderer(),

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good question. In answer to your question, it's fine to rely on the default (in contradiction of my earlier suggestion). In terms of improving explicitness and readability, the real fix is migrating completely to testWithoutContext.

_slowWarning = slowWarningCallback!();
final SlowWarningCallback? callback = slowWarningCallback;
if (_slowWarning.isEmpty && callback != null) {
final TerminalColor? color = warningColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with how we handle colors in the tool. Is there a reason why we can't make this a global color? Is it because some warnings are red and some the normal text color? Or is it a difference of host platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because some are normal text color. Before this change, all were normal text color. I added this so that the warning could be red

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM!

@jmagman
Copy link
Member

jmagman commented Mar 28, 2023

@XilaiZhang @CaseyHillers do you know why FRoB says "Do not test" for this PR? And why Google testing check is still pending then?

@CaseyHillers
Copy link
Contributor

@XilaiZhang @CaseyHillers do you know why FRoB says "Do not test" for this PR? And why Google testing check is still pending then?

This PR has failures with Google Testing. For some unknown reason, the state changed from "Failed" to "Pending" after ~12 hours. Please do not skip the Google Testing check on this PR, as this is causing real failures.

@vashworth
Copy link
Contributor Author

@jmagman So I'm fairly confident the issue with g3 was that adb does not like being run multiple times at the same time, and would throw errors which would cause the tool to exit.

throwToolExit(
'Unable to run "adb", check your Android SDK installation and '
'$kAndroidSdkRoot environment variable: ${exception.executable}',
);

So I updated the flow of things a bit so only iOS discovery runs simultaneously.

Can you review the newest commit?

@vashworth vashworth added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 29, 2023
@auto-submit auto-submit bot merged commit fa01649 into flutter:master Mar 29, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 1, 2023
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
…#122932)

Update device selection to wait for wireless devices to load
@vashworth vashworth deleted the wireless_device_discovery_part_4 branch September 27, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS network device not available when doing flutter run

4 participants