Fix visibility of web server device when Chrome is not available (#40757)
* Fix visbility of web server device when Chrome is not available * Add tests * Update workflow test * Fix tests to not rely on Chrome being on the underlying machine
This commit is contained in:
@@ -71,6 +71,16 @@ class ChromeLauncher {
|
||||
|
||||
static final Completer<Chrome> _currentCompleter = Completer<Chrome>();
|
||||
|
||||
/// Whether we can locate the chrome executable.
|
||||
bool canFindChrome() {
|
||||
final String chrome = findChromeExecutable();
|
||||
try {
|
||||
return processManager.canRun(chrome);
|
||||
} on ArgumentError {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch the chrome browser to a particular `host` page.
|
||||
///
|
||||
/// `headless` defaults to false, and controls whether we open a headless or
|
||||
|
||||
@@ -15,7 +15,6 @@ import '../features.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
import 'chrome.dart';
|
||||
import 'workflow.dart';
|
||||
|
||||
class WebApplicationPackage extends ApplicationPackage {
|
||||
WebApplicationPackage(this.flutterProject) : super(id: flutterProject.manifest.appName);
|
||||
@@ -81,7 +80,7 @@ class ChromeDevice extends Device {
|
||||
Future<String> get emulatorId async => null;
|
||||
|
||||
@override
|
||||
bool isSupported() => featureFlags.isWebEnabled && canFindChrome();
|
||||
bool isSupported() => featureFlags.isWebEnabled && chromeLauncher.canFindChrome();
|
||||
|
||||
@override
|
||||
String get name => 'Chrome';
|
||||
@@ -162,6 +161,7 @@ class ChromeDevice extends Device {
|
||||
class WebDevices extends PollingDeviceDiscovery {
|
||||
WebDevices() : super('chrome');
|
||||
|
||||
final bool _chromeIsAvailable = chromeLauncher.canFindChrome();
|
||||
final ChromeDevice _webDevice = ChromeDevice();
|
||||
final WebServerDevice _webServerDevice = WebServerDevice();
|
||||
|
||||
@@ -171,7 +171,8 @@ class WebDevices extends PollingDeviceDiscovery {
|
||||
@override
|
||||
Future<List<Device>> pollingGetDevices() async {
|
||||
return <Device>[
|
||||
_webDevice,
|
||||
if (_chromeIsAvailable)
|
||||
_webDevice,
|
||||
_webServerDevice,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import '../base/platform.dart';
|
||||
import '../doctor.dart';
|
||||
import 'chrome.dart';
|
||||
import 'workflow.dart';
|
||||
|
||||
/// A validator that checks whether chrome is installed and can run.
|
||||
class WebValidator extends DoctorValidator {
|
||||
@@ -14,7 +13,7 @@ class WebValidator extends DoctorValidator {
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
final String chrome = findChromeExecutable();
|
||||
final bool canRunChrome = canFindChrome();
|
||||
final bool canRunChrome = chromeLauncher.canFindChrome();
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[
|
||||
if (platform.environment.containsKey(kChromeEnvironment))
|
||||
if (!canRunChrome)
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
|
||||
import '../base/context.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../doctor.dart';
|
||||
import '../features.dart';
|
||||
import 'chrome.dart';
|
||||
|
||||
/// The web workflow instance.
|
||||
WebWorkflow get webWorkflow => context.get<WebWorkflow>();
|
||||
@@ -19,21 +17,11 @@ class WebWorkflow extends Workflow {
|
||||
bool get appliesToHostPlatform => featureFlags.isWebEnabled && (platform.isWindows || platform.isMacOS || platform.isLinux);
|
||||
|
||||
@override
|
||||
bool get canLaunchDevices => featureFlags.isWebEnabled && canFindChrome();
|
||||
bool get canLaunchDevices => featureFlags.isWebEnabled;
|
||||
|
||||
@override
|
||||
bool get canListDevices => featureFlags.isWebEnabled && canFindChrome();
|
||||
bool get canListDevices => featureFlags.isWebEnabled;
|
||||
|
||||
@override
|
||||
bool get canListEmulators => false;
|
||||
}
|
||||
|
||||
/// Whether we can locate the chrome executable.
|
||||
bool canFindChrome() {
|
||||
final String chrome = findChromeExecutable();
|
||||
try {
|
||||
return processManager.canRun(chrome);
|
||||
} on ArgumentError {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user