diff --git a/lib/web_ui/dev/browser_lock.yaml b/lib/web_ui/dev/browser_lock.yaml index cfc7608d8b061..1ef30ed088ba9 100644 --- a/lib/web_ui/dev/browser_lock.yaml +++ b/lib/web_ui/dev/browser_lock.yaml @@ -6,3 +6,5 @@ chrome: Win: 695655 firefox: version: '71.0' +edge: + launcher_version: '1.2.0.0' diff --git a/lib/web_ui/dev/common.dart b/lib/web_ui/dev/common.dart index 717528b73c0a3..f88a20a790546 100644 --- a/lib/web_ui/dev/common.dart +++ b/lib/web_ui/dev/common.dart @@ -88,9 +88,6 @@ class _WindowsBinding implements PlatformBinding { String getSafariSystemExecutablePath() => throw UnsupportedError('Safari is not supported on Windows'); - // TODO(nurhan): Add code to check and install MicrosoftEdgeLauncher - // if missing. - // See: https://github.com/flutter/flutter/issues/48823 @override String getCommandToRunEdge() => 'MicrosoftEdgeLauncher'; } diff --git a/lib/web_ui/dev/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index 5c302a5fea2ef..0f7c7b5be4afd 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -6,8 +6,11 @@ import 'dart:async'; import 'dart:io' as io; import 'package:args/args.dart'; +import 'package:http/http.dart'; +import 'package:path/path.dart' as path; import 'common.dart'; +import 'environment.dart'; class EdgeArgParser extends BrowserArgParser { static final EdgeArgParser _singletonInstance = EdgeArgParser._(); @@ -68,12 +71,84 @@ Future getEdgeInstallation( // Since Edge is included in Windows, always assume there will be one on the // system. infoLog.writeln('Using the system version that is already installed.'); + final EdgeLauncher edgeLauncher = EdgeLauncher(); + if (edgeLauncher.isInstalled) { + infoLog.writeln('Launcher installation was skipped, already installed.'); + } else { + infoLog.writeln('Installing MicrosoftEdgeLauncher'); + await edgeLauncher.install(); + infoLog.writeln( + 'Installations complete. To launch it run ${edgeLauncher.executable}'); + } + return BrowserInstallation( version: 'system', - executable: PlatformBinding.instance.getCommandToRunEdge(), + executable: io.Directory(path.join( + edgeLauncher.launcherInstallationDir.path, + '${PlatformBinding.instance.getCommandToRunEdge()}')) + .path, ); } else { infoLog.writeln('Unsupported version $requestedVersion.'); throw UnimplementedError(); } } + +/// `MicrosoftEdgeLauncher` is an executable for launching Edge. +/// +/// It is useful for starting Edge from comand line or from a +/// batch script. +/// +/// See: https://github.com/MicrosoftEdge/edge-launcher +class EdgeLauncher { + /// Path to the directory that contains `MicrosoftEdgeLauncher.exe`. + io.Directory get launcherInstallationDir => io.Directory( + path.join(environment.webUiDartToolDir.path, 'microsoftedgelauncher', + version), + ); + + io.File get executable => io.File( + path.join(launcherInstallationDir.path, 'MicrosoftEdgeLauncher.exe')); + + bool get isInstalled => executable.existsSync(); + + /// Version number launcher executable `MicrosoftEdgeLauncher`. + final String version; + + /// Url for downloading `MicrosoftEdgeLauncher`. + /// + /// Only useful in Windows, hence not added to [PlatformBinding]. + String get windowsEdgeLauncherDownloadUrl => + 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/$version/MicrosoftEdgeLauncher.exe'; + + EdgeLauncher() + : version = + BrowserLock.instance.configuration['edge']['launcher_version']; + + /// Install the launcher if it does not exist in this system. + void install() async { + // Checks if the `MicrosoftEdgeLauncher` executable exists. + if (isInstalled) { + return; + } + + // Create directory for download. + if (!launcherInstallationDir.existsSync()) { + launcherInstallationDir.createSync(recursive: true); + } + + final Client client = Client(); + + try { + // Download executable from Github. + final StreamedResponse download = await client.send(Request( + 'GET', + Uri.parse(windowsEdgeLauncherDownloadUrl), + )); + + await download.stream.pipe(executable.openWrite()); + } finally { + client.close(); + } + } +}