[flutter_tools] refactor Chrome launch logic to remove globals/statics (#55160)
This commit is contained in:
@@ -15,11 +15,13 @@ import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/os.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
/// An environment variable used to override the location of chrome.
|
||||
/// An environment variable used to override the location of Google Chrome.
|
||||
const String kChromeEnvironment = 'CHROME_EXECUTABLE';
|
||||
|
||||
/// An environment variable used to override the location of Microsoft Edge.
|
||||
const String kEdgeEnvironment = 'EDGE_ENVIRONMENT';
|
||||
|
||||
/// The expected executable name on linux.
|
||||
const String kLinuxExecutable = 'google-chrome';
|
||||
|
||||
@@ -27,9 +29,14 @@ const String kLinuxExecutable = 'google-chrome';
|
||||
const String kMacOSExecutable =
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
|
||||
/// The expected executable name on Windows.
|
||||
/// The expected Chrome executable name on Windows.
|
||||
const String kWindowsExecutable = r'Google\Chrome\Application\chrome.exe';
|
||||
|
||||
/// The expected Edge executable name on Windows.
|
||||
const String kWindowsEdgeExecutable = r'Microsoft\Edge\Application\msedge.exe';
|
||||
|
||||
typedef BrowserFinder = String Function(Platform, FileSystem);
|
||||
|
||||
/// Find the chrome executable on the current platform.
|
||||
///
|
||||
/// Does not verify whether the executable exists.
|
||||
@@ -63,43 +70,73 @@ String findChromeExecutable(Platform platform, FileSystem fileSystem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
void resetChromeForTesting() {
|
||||
ChromeLauncher._currentCompleter = Completer<Chrome>();
|
||||
/// Find the Microsoft Edge executable on the current platform.
|
||||
///
|
||||
/// Does not verify whether the executable exists.
|
||||
String findEdgeExecutable(Platform platform, FileSystem fileSystem) {
|
||||
if (platform.environment.containsKey(kEdgeEnvironment)) {
|
||||
return platform.environment[kEdgeEnvironment];
|
||||
}
|
||||
if (platform.isWindows) {
|
||||
/// The possible locations where the Edge executable can be located on windows.
|
||||
final List<String> kWindowsPrefixes = <String>[
|
||||
platform.environment['LOCALAPPDATA'],
|
||||
platform.environment['PROGRAMFILES'],
|
||||
platform.environment['PROGRAMFILES(X86)'],
|
||||
];
|
||||
final String windowsPrefix = kWindowsPrefixes.firstWhere((String prefix) {
|
||||
if (prefix == null) {
|
||||
return false;
|
||||
}
|
||||
final String path = fileSystem.path.join(prefix, kWindowsEdgeExecutable);
|
||||
return fileSystem.file(path).existsSync();
|
||||
}, orElse: () => '.');
|
||||
return fileSystem.path.join(windowsPrefix, kWindowsEdgeExecutable);
|
||||
}
|
||||
// Not yet supported for macOS and Linux.
|
||||
return '';
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
void launchChromeInstance(Chrome chrome) {
|
||||
ChromeLauncher._currentCompleter.complete(chrome);
|
||||
}
|
||||
|
||||
/// Responsible for launching chrome with devtools configured.
|
||||
class ChromeLauncher {
|
||||
const ChromeLauncher({
|
||||
/// A launcher for Chromium browsers with devtools configured.
|
||||
class ChromiumLauncher {
|
||||
ChromiumLauncher({
|
||||
@required FileSystem fileSystem,
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required OperatingSystemUtils operatingSystemUtils,
|
||||
@required Logger logger,
|
||||
@required BrowserFinder browserFinder,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_platform = platform,
|
||||
_processManager = processManager,
|
||||
_operatingSystemUtils = operatingSystemUtils,
|
||||
_logger = logger;
|
||||
_logger = logger,
|
||||
_browserFinder = browserFinder,
|
||||
_fileSystemUtils = FileSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
);
|
||||
|
||||
final FileSystem _fileSystem;
|
||||
final Platform _platform;
|
||||
final ProcessManager _processManager;
|
||||
final OperatingSystemUtils _operatingSystemUtils;
|
||||
final Logger _logger;
|
||||
final BrowserFinder _browserFinder;
|
||||
final FileSystemUtils _fileSystemUtils;
|
||||
|
||||
static bool get hasChromeInstance => _currentCompleter.isCompleted;
|
||||
bool get hasChromeInstance => _currentCompleter.isCompleted;
|
||||
|
||||
static Completer<Chrome> _currentCompleter = Completer<Chrome>();
|
||||
Completer<Chromium> _currentCompleter = Completer<Chromium>();
|
||||
|
||||
@visibleForTesting
|
||||
void testLaunchChromium(Chromium chromium) {
|
||||
_currentCompleter.complete(chromium);
|
||||
}
|
||||
|
||||
/// Whether we can locate the chrome executable.
|
||||
bool canFindChrome() {
|
||||
final String chrome = findChromeExecutable(_platform, _fileSystem);
|
||||
bool canFindExecutable() {
|
||||
final String chrome = _browserFinder(_platform, _fileSystem);
|
||||
try {
|
||||
return _processManager.canRun(chrome);
|
||||
} on ArgumentError {
|
||||
@@ -107,7 +144,10 @@ class ChromeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch the chrome browser to a particular `host` page.
|
||||
/// The executable this launcher will use.
|
||||
String findExecutable() => _browserFinder(_platform, _fileSystem);
|
||||
|
||||
/// Launch a Chromium browser to a particular `host` page.
|
||||
///
|
||||
/// `headless` defaults to false, and controls whether we open a headless or
|
||||
/// a `headfull` browser.
|
||||
@@ -116,13 +156,19 @@ class ChromeLauncher {
|
||||
/// port is picked automatically.
|
||||
///
|
||||
/// `skipCheck` does not attempt to make a devtools connection before returning.
|
||||
Future<Chrome> launch(String url, { bool headless = false, int debugPort, bool skipCheck = false, Directory cacheDir }) async {
|
||||
Future<Chromium> launch(String url, {
|
||||
bool headless = false,
|
||||
int debugPort,
|
||||
bool skipCheck = false,
|
||||
Directory cacheDir,
|
||||
}) async {
|
||||
if (_currentCompleter.isCompleted) {
|
||||
throwToolExit('Only one instance of chrome can be started.');
|
||||
}
|
||||
|
||||
final String chromeExecutable = findChromeExecutable(_platform, _fileSystem);
|
||||
final Directory userDataDir = _fileSystem.systemTempDirectory.createTempSync('flutter_tools_chrome_device.');
|
||||
final String chromeExecutable = _browserFinder(_platform, _fileSystem);
|
||||
final Directory userDataDir = _fileSystem.systemTempDirectory
|
||||
.createTempSync('flutter_tools_chrome_device.');
|
||||
|
||||
if (cacheDir != null) {
|
||||
// Seed data dir with previous state.
|
||||
@@ -148,7 +194,12 @@ class ChromeLauncher {
|
||||
'--disable-default-apps',
|
||||
'--disable-translate',
|
||||
if (headless)
|
||||
...<String>['--headless', '--disable-gpu', '--no-sandbox', '--window-size=2400,1800'],
|
||||
...<String>[
|
||||
'--headless',
|
||||
'--disable-gpu',
|
||||
'--no-sandbox',
|
||||
'--window-size=2400,1800',
|
||||
],
|
||||
url,
|
||||
];
|
||||
|
||||
@@ -180,12 +231,13 @@ class ChromeLauncher {
|
||||
return 'Failed to spawn stderr';
|
||||
});
|
||||
final Uri remoteDebuggerUri = await _getRemoteDebuggerUrl(Uri.parse('http://localhost:$port'));
|
||||
return _connect(Chrome._(
|
||||
return _connect(Chromium._(
|
||||
port,
|
||||
ChromeConnection('localhost', port),
|
||||
url: url,
|
||||
process: process,
|
||||
remoteDebuggerUri: remoteDebuggerUri,
|
||||
chromiumLauncher: this,
|
||||
), skipCheck);
|
||||
}
|
||||
|
||||
@@ -217,7 +269,7 @@ class ChromeLauncher {
|
||||
|
||||
if (sourceLocalStorageDir.existsSync()) {
|
||||
targetLocalStorageDir.createSync(recursive: true);
|
||||
globals.fsUtils.copyDirectorySync(sourceLocalStorageDir, targetLocalStorageDir);
|
||||
_fileSystemUtils.copyDirectorySync(sourceLocalStorageDir, targetLocalStorageDir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,11 +288,11 @@ class ChromeLauncher {
|
||||
|
||||
if (sourceLocalStorageDir.existsSync()) {
|
||||
targetLocalStorageDir.createSync(recursive: true);
|
||||
globals.fsUtils.copyDirectorySync(sourceLocalStorageDir, targetLocalStorageDir);
|
||||
_fileSystemUtils.copyDirectorySync(sourceLocalStorageDir, targetLocalStorageDir);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Chrome> _connect(Chrome chrome, bool skipCheck) async {
|
||||
Future<Chromium> _connect(Chromium chrome, bool skipCheck) async {
|
||||
// The connection is lazy. Try a simple call to make sure the provided
|
||||
// connection is valid.
|
||||
if (!skipCheck) {
|
||||
@@ -256,7 +308,7 @@ class ChromeLauncher {
|
||||
return chrome;
|
||||
}
|
||||
|
||||
static Future<Chrome> get connectedInstance => _currentCompleter.future;
|
||||
Future<Chromium> get connectedInstance => _currentCompleter.future;
|
||||
|
||||
/// Returns the full URL of the Chrome remote debugger for the main page.
|
||||
///
|
||||
@@ -281,27 +333,30 @@ class ChromeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
/// A class for managing an instance of Chrome.
|
||||
class Chrome {
|
||||
Chrome._(
|
||||
/// A class for managing an instance of a Chromium browser.
|
||||
class Chromium {
|
||||
Chromium._(
|
||||
this.debugPort,
|
||||
this.chromeConnection, {
|
||||
this.url,
|
||||
Process process,
|
||||
this.remoteDebuggerUri,
|
||||
}) : _process = process;
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
}) : _process = process,
|
||||
_chromiumLauncher = chromiumLauncher;
|
||||
|
||||
final String url;
|
||||
final int debugPort;
|
||||
final Process _process;
|
||||
final ChromeConnection chromeConnection;
|
||||
final Uri remoteDebuggerUri;
|
||||
final ChromiumLauncher _chromiumLauncher;
|
||||
|
||||
Future<int> get onExit => _process.exitCode;
|
||||
|
||||
Future<void> close() async {
|
||||
if (ChromeLauncher.hasChromeInstance) {
|
||||
ChromeLauncher._currentCompleter = Completer<Chrome>();
|
||||
if (_chromiumLauncher.hasChromeInstance) {
|
||||
_chromiumLauncher._currentCompleter = Completer<Chromium>();
|
||||
}
|
||||
chromeConnection.close();
|
||||
_process?.kill();
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/os.dart';
|
||||
import '../build_info.dart';
|
||||
import '../device.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import 'chrome.dart';
|
||||
|
||||
@@ -26,16 +29,29 @@ class WebApplicationPackage extends ApplicationPackage {
|
||||
Directory get webSourcePath => flutterProject.directory.childDirectory('web');
|
||||
}
|
||||
|
||||
class ChromeDevice extends Device {
|
||||
ChromeDevice() : super(
|
||||
'chrome',
|
||||
category: Category.web,
|
||||
platformType: PlatformType.web,
|
||||
ephemeral: false,
|
||||
);
|
||||
/// A web device that supports a chromium browser.
|
||||
abstract class ChromiumDevice extends Device {
|
||||
ChromiumDevice({
|
||||
@required String name,
|
||||
@required this.chromeLauncher,
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_logger = logger,
|
||||
super(
|
||||
name,
|
||||
category: Category.web,
|
||||
platformType: PlatformType.web,
|
||||
ephemeral: false,
|
||||
);
|
||||
|
||||
final ChromiumLauncher chromeLauncher;
|
||||
|
||||
final FileSystem _fileSystem;
|
||||
final Logger _logger;
|
||||
|
||||
/// The active chrome instance.
|
||||
Chrome _chrome;
|
||||
Chromium _chrome;
|
||||
|
||||
// TODO(jonahwilliams): this is technically false, but requires some refactoring
|
||||
// to allow hot mode restart only devices.
|
||||
@@ -83,47 +99,11 @@ class ChromeDevice extends Device {
|
||||
Future<String> get emulatorId async => null;
|
||||
|
||||
@override
|
||||
bool isSupported() => featureFlags.isWebEnabled && globals.chromeLauncher.canFindChrome();
|
||||
|
||||
@override
|
||||
String get name => 'Chrome';
|
||||
bool isSupported() => chromeLauncher.canFindExecutable();
|
||||
|
||||
@override
|
||||
DevicePortForwarder get portForwarder => const NoOpDevicePortForwarder();
|
||||
|
||||
@override
|
||||
Future<String> get sdkNameAndVersion async => _sdkNameAndVersion ??= await _computeSdkNameAndVersion();
|
||||
|
||||
String _sdkNameAndVersion;
|
||||
Future<String> _computeSdkNameAndVersion() async {
|
||||
if (!isSupported()) {
|
||||
return 'unknown';
|
||||
}
|
||||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=158372
|
||||
String version = 'unknown';
|
||||
if (globals.platform.isWindows) {
|
||||
final ProcessResult result = await globals.processManager.run(<String>[
|
||||
r'reg', 'query', r'HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon', '/v', 'version',
|
||||
]);
|
||||
if (result.exitCode == 0) {
|
||||
final List<String> parts = (result.stdout as String).split(RegExp(r'\s+'));
|
||||
if (parts.length > 2) {
|
||||
version = 'Google Chrome ' + parts[parts.length - 2];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final String chrome = findChromeExecutable(globals.platform, globals.fs);
|
||||
final ProcessResult result = await globals.processManager.run(<String>[
|
||||
chrome,
|
||||
'--version',
|
||||
]);
|
||||
if (result.exitCode == 0) {
|
||||
version = result.stdout as String;
|
||||
}
|
||||
}
|
||||
return version.trim();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LaunchResult> startApp(
|
||||
covariant WebApplicationPackage package, {
|
||||
@@ -139,9 +119,9 @@ class ChromeDevice extends Device {
|
||||
final String url = platformArgs['uri'] as String;
|
||||
final bool launchChrome = platformArgs['no-launch-chrome'] != true;
|
||||
if (launchChrome) {
|
||||
_chrome = await globals.chromeLauncher.launch(
|
||||
_chrome = await chromeLauncher.launch(
|
||||
url,
|
||||
cacheDir: globals.fs.currentDirectory
|
||||
cacheDir: _fileSystem.currentDirectory
|
||||
.childDirectory('.dart_tool')
|
||||
.childDirectory('chrome-device'),
|
||||
headless: debuggingOptions.webRunHeadless,
|
||||
@@ -149,7 +129,7 @@ class ChromeDevice extends Device {
|
||||
);
|
||||
}
|
||||
|
||||
globals.logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': launchChrome});
|
||||
_logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': launchChrome});
|
||||
return LaunchResult.succeeded(observatoryUri: url != null ? Uri.parse(url): null);
|
||||
}
|
||||
|
||||
@@ -177,27 +157,140 @@ class ChromeDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
class WebDevices extends PollingDeviceDiscovery {
|
||||
WebDevices() : super('chrome');
|
||||
/// The Google Chrome browser based on Chromium.
|
||||
class GoogleChromeDevice extends ChromiumDevice {
|
||||
GoogleChromeDevice({
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
@required Logger logger,
|
||||
@required FileSystem fileSystem,
|
||||
}) : _platform = platform,
|
||||
_processManager = processManager,
|
||||
super(
|
||||
name: 'chrome',
|
||||
chromeLauncher: chromiumLauncher,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
final bool _chromeIsAvailable = globals.chromeLauncher.canFindChrome();
|
||||
final ChromeDevice _webDevice = ChromeDevice();
|
||||
final WebServerDevice _webServerDevice = WebServerDevice();
|
||||
final Platform _platform;
|
||||
final ProcessManager _processManager;
|
||||
|
||||
@override
|
||||
String get name => 'Chrome';
|
||||
|
||||
@override
|
||||
Future<String> get sdkNameAndVersion async => _sdkNameAndVersion ??= await _computeSdkNameAndVersion();
|
||||
|
||||
String _sdkNameAndVersion;
|
||||
Future<String> _computeSdkNameAndVersion() async {
|
||||
if (!isSupported()) {
|
||||
return 'unknown';
|
||||
}
|
||||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=158372
|
||||
String version = 'unknown';
|
||||
if (_platform.isWindows) {
|
||||
final ProcessResult result = await _processManager.run(<String>[
|
||||
r'reg', 'query', r'HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon', '/v', 'version',
|
||||
]);
|
||||
if (result.exitCode == 0) {
|
||||
final List<String> parts = (result.stdout as String).split(RegExp(r'\s+'));
|
||||
if (parts.length > 2) {
|
||||
version = 'Google Chrome ' + parts[parts.length - 2];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final String chrome = chromeLauncher.findExecutable();
|
||||
final ProcessResult result = await _processManager.run(<String>[
|
||||
chrome,
|
||||
'--version',
|
||||
]);
|
||||
if (result.exitCode == 0) {
|
||||
version = result.stdout as String;
|
||||
}
|
||||
}
|
||||
return version.trim();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// The Microsoft Edge browser based on Chromium.
|
||||
// This is not currently used, see https://github.com/flutter/flutter/issues/55322
|
||||
class MicrosoftEdgeDevice extends ChromiumDevice {
|
||||
MicrosoftEdgeDevice({
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
@required Logger logger,
|
||||
@required FileSystem fileSystem,
|
||||
}) : super(
|
||||
name: 'edge',
|
||||
chromeLauncher: chromiumLauncher,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
|
||||
@override
|
||||
String get name => 'Edge';
|
||||
|
||||
@override
|
||||
Future<String> get sdkNameAndVersion async => '<?>';
|
||||
}
|
||||
|
||||
class WebDevices extends PollingDeviceDiscovery {
|
||||
WebDevices({
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required FeatureFlags featureFlags,
|
||||
}) : _featureFlags = featureFlags,
|
||||
super('Chrome') {
|
||||
final OperatingSystemUtils operatingSystemUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
);
|
||||
_chromeDevice = GoogleChromeDevice(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
chromiumLauncher: ChromiumLauncher(
|
||||
browserFinder: findChromeExecutable,
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
operatingSystemUtils: operatingSystemUtils,
|
||||
),
|
||||
);
|
||||
_webServerDevice = WebServerDevice(
|
||||
logger: logger,
|
||||
);
|
||||
}
|
||||
|
||||
GoogleChromeDevice _chromeDevice;
|
||||
WebServerDevice _webServerDevice;
|
||||
final FeatureFlags _featureFlags;
|
||||
|
||||
@override
|
||||
bool get canListAnything => featureFlags.isWebEnabled;
|
||||
|
||||
@override
|
||||
Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
|
||||
if (!_featureFlags.isWebEnabled) {
|
||||
return <Device>[];
|
||||
}
|
||||
return <Device>[
|
||||
if (_chromeIsAvailable)
|
||||
_webDevice,
|
||||
_webServerDevice,
|
||||
if (_chromeDevice.isSupported())
|
||||
_chromeDevice,
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
bool get supportsPlatform => featureFlags.isWebEnabled;
|
||||
bool get supportsPlatform => _featureFlags.isWebEnabled;
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
@@ -208,12 +301,17 @@ String parseVersionForWindows(String input) {
|
||||
|
||||
/// A special device type to allow serving for arbitrary browsers.
|
||||
class WebServerDevice extends Device {
|
||||
WebServerDevice() : super(
|
||||
'web-server',
|
||||
platformType: PlatformType.web,
|
||||
category: Category.web,
|
||||
ephemeral: false,
|
||||
);
|
||||
WebServerDevice({
|
||||
@required Logger logger,
|
||||
}) : _logger = logger,
|
||||
super(
|
||||
'web-server',
|
||||
platformType: PlatformType.web,
|
||||
category: Category.web,
|
||||
ephemeral: false,
|
||||
);
|
||||
|
||||
final Logger _logger;
|
||||
|
||||
@override
|
||||
void clearLogs() { }
|
||||
@@ -244,7 +342,7 @@ class WebServerDevice extends Device {
|
||||
Future<bool> get isLocalEmulator async => false;
|
||||
|
||||
@override
|
||||
bool isSupported() => featureFlags.isWebEnabled;
|
||||
bool isSupported() => true;
|
||||
|
||||
@override
|
||||
bool isSupportedForProject(FlutterProject flutterProject) {
|
||||
@@ -271,11 +369,11 @@ class WebServerDevice extends Device {
|
||||
}) async {
|
||||
final String url = platformArgs['uri'] as String;
|
||||
if (debuggingOptions.startPaused) {
|
||||
globals.printStatus('Waiting for connection from Dart debug extension at $url', emphasis: true);
|
||||
_logger.printStatus('Waiting for connection from Dart debug extension at $url', emphasis: true);
|
||||
} else {
|
||||
globals.printStatus('$mainPath is being served at $url', emphasis: true);
|
||||
_logger.printStatus('$mainPath is being served at $url', emphasis: true);
|
||||
}
|
||||
globals.logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': false});
|
||||
_logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': false});
|
||||
return LaunchResult.succeeded(observatoryUri: url != null ? Uri.parse(url): null);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,47 +5,39 @@
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../doctor.dart';
|
||||
import 'chrome.dart';
|
||||
|
||||
/// A validator that checks whether chrome is installed and can run.
|
||||
class WebValidator extends DoctorValidator {
|
||||
const WebValidator({
|
||||
@required Platform platform,
|
||||
@required ChromeLauncher chromeLauncher,
|
||||
@required FileSystem fileSystem,
|
||||
}) : _platform = platform,
|
||||
_chromeLauncher = chromeLauncher,
|
||||
_fileSystem = fileSystem,
|
||||
super('Chrome - develop for the web');
|
||||
/// A validator for Chromium-based brosers.
|
||||
abstract class ChromiumValidator extends DoctorValidator {
|
||||
const ChromiumValidator(String title) : super(title);
|
||||
|
||||
final Platform _platform;
|
||||
final ChromeLauncher _chromeLauncher;
|
||||
final FileSystem _fileSystem;
|
||||
Platform get _platform;
|
||||
ChromiumLauncher get _chromiumLauncher;
|
||||
String get _name;
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
final String chrome = findChromeExecutable(_platform, _fileSystem);
|
||||
final bool canRunChrome = _chromeLauncher.canFindChrome();
|
||||
final bool canRunChromium = _chromiumLauncher.canFindExecutable();
|
||||
final String chromimSearchLocation = _chromiumLauncher.findExecutable();
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[
|
||||
if (_platform.environment.containsKey(kChromeEnvironment))
|
||||
if (!canRunChrome)
|
||||
ValidationMessage.hint('$chrome is not executable.')
|
||||
if (!canRunChromium)
|
||||
ValidationMessage.hint('$chromimSearchLocation is not executable.')
|
||||
else
|
||||
ValidationMessage('$kChromeEnvironment = $chrome')
|
||||
ValidationMessage('$kChromeEnvironment = $chromimSearchLocation')
|
||||
else
|
||||
if (!canRunChrome)
|
||||
const ValidationMessage.hint('Cannot find Chrome. Try setting '
|
||||
'$kChromeEnvironment to a Chrome executable.')
|
||||
if (!canRunChromium)
|
||||
ValidationMessage.hint('Cannot find $_name. Try setting '
|
||||
'$kChromeEnvironment to a $_name executable.')
|
||||
else
|
||||
ValidationMessage('Chrome at $chrome'),
|
||||
ValidationMessage('$_name at $chromimSearchLocation'),
|
||||
];
|
||||
if (!canRunChrome) {
|
||||
if (!canRunChromium) {
|
||||
return ValidationResult(
|
||||
ValidationType.missing,
|
||||
messages,
|
||||
statusInfo: 'Cannot find chrome executable at $chrome',
|
||||
statusInfo: 'Cannot find $_name executable at $chromimSearchLocation',
|
||||
);
|
||||
}
|
||||
return ValidationResult(
|
||||
@@ -54,3 +46,42 @@ class WebValidator extends DoctorValidator {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A validator that checks whether Chrome is installed and can run.
|
||||
class ChromeValidator extends ChromiumValidator {
|
||||
const ChromeValidator({
|
||||
@required Platform platform,
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
}) : _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Chrome - develop for the web');
|
||||
|
||||
@override
|
||||
final Platform _platform;
|
||||
|
||||
@override
|
||||
final ChromiumLauncher _chromiumLauncher;
|
||||
|
||||
@override
|
||||
String get _name => 'Chrome';
|
||||
}
|
||||
|
||||
/// A validator that checks whethere Edge is installed and can run.
|
||||
// This is not currently used, see https://github.com/flutter/flutter/issues/55322
|
||||
class EdgeValidator extends ChromiumValidator {
|
||||
const EdgeValidator({
|
||||
@required Platform platform,
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
}) : _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Edge - develop for the web');
|
||||
|
||||
@override
|
||||
final Platform _platform;
|
||||
|
||||
@override
|
||||
final ChromiumLauncher _chromiumLauncher;
|
||||
|
||||
@override
|
||||
String get _name => 'Edge';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user