From 109519a9e31e0d0f10d8d257b0aad5f5b1b8d882 Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 09:13:39 -0800 Subject: [PATCH 1/6] edge launcher for windows --- lib/web_ui/dev/common.dart | 3 -- lib/web_ui/dev/edge_installation.dart | 66 ++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) 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..858af3b024793 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,73 @@ 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(); } } + +class EdgeLauncher { + /// Url for downloading `MicrosoftEdgeLauncher`. + /// + /// Only useful in Windows, hence not added to [PlatformBinding]. + final String windowsEdgeLauncherDownloadUrl = + 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/1.2.0.0/MicrosoftEdgeLauncher.exe'; + + /// Path to the directory contains `MicrosoftEdgeLauncher.exe`. + io.Directory get launcherInstallationDir => io.Directory( + path.join(environment.webUiDartToolDir.path, 'microsoftedgelauncher'), + ); + + io.File get executable => io.File( + path.join(launcherInstallationDir.path, 'MicrosoftEdgeLauncher.exe')); + + bool get isInstalled => executable.existsSync(); + + /// For running Edge from a batch script executable `MicrosoftEdgeLauncher` + /// is used. + /// Install it if it does not exists in this system. + /// See: https://github.com/MicrosoftEdge/edge-launcher + 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(); + } + } +} From 1e692192db916e3dc708383f1538aa2b808917db Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 10:31:51 -0800 Subject: [PATCH 2/6] addressing PR comments --- lib/web_ui/dev/browser_lock.yaml | 2 ++ lib/web_ui/dev/edge_installation.dart | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) 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/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index 858af3b024793..7acc6a58e79b6 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -8,6 +8,7 @@ import 'dart:io' as io; import 'package:args/args.dart'; import 'package:http/http.dart'; import 'package:path/path.dart' as path; +import 'package:yaml/yaml.dart'; import 'common.dart'; import 'environment.dart'; @@ -94,6 +95,12 @@ Future getEdgeInstallation( } } +/// `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 { /// Url for downloading `MicrosoftEdgeLauncher`. /// @@ -101,9 +108,10 @@ class EdgeLauncher { final String windowsEdgeLauncherDownloadUrl = 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/1.2.0.0/MicrosoftEdgeLauncher.exe'; - /// Path to the directory contains `MicrosoftEdgeLauncher.exe`. + /// Path to the directory that contains `MicrosoftEdgeLauncher.exe`. io.Directory get launcherInstallationDir => io.Directory( - path.join(environment.webUiDartToolDir.path, 'microsoftedgelauncher'), + path.join(environment.webUiDartToolDir.path, 'microsoftedgelauncher', + version), ); io.File get executable => io.File( @@ -111,10 +119,14 @@ class EdgeLauncher { bool get isInstalled => executable.existsSync(); - /// For running Edge from a batch script executable `MicrosoftEdgeLauncher` - /// is used. - /// Install it if it does not exists in this system. - /// See: https://github.com/MicrosoftEdge/edge-launcher + /// Version number launcher executable `MicrosoftEdgeLauncher`. + final String version; + + 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) { From b111858dd7eae5b7cda75da719acd744f3ef233f Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 10:40:22 -0800 Subject: [PATCH 3/6] url mistake --- lib/web_ui/dev/edge_installation.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web_ui/dev/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index 7acc6a58e79b6..0b6ac1b8b5abd 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -106,7 +106,7 @@ class EdgeLauncher { /// /// Only useful in Windows, hence not added to [PlatformBinding]. final String windowsEdgeLauncherDownloadUrl = - 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/1.2.0.0/MicrosoftEdgeLauncher.exe'; + 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/$version/MicrosoftEdgeLauncher.exe'; /// Path to the directory that contains `MicrosoftEdgeLauncher.exe`. io.Directory get launcherInstallationDir => io.Directory( From dab0182a993dda941bd0e32d9909818d07167e51 Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 10:41:51 -0800 Subject: [PATCH 4/6] remove uncessary import --- lib/web_ui/dev/edge_installation.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/web_ui/dev/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index 0b6ac1b8b5abd..c27f0e1444f25 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -8,7 +8,6 @@ import 'dart:io' as io; import 'package:args/args.dart'; import 'package:http/http.dart'; import 'package:path/path.dart' as path; -import 'package:yaml/yaml.dart'; import 'common.dart'; import 'environment.dart'; From 28b5b378d4ff2cfcdb8f343dc54deb7a89d0c9e1 Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 11:06:29 -0800 Subject: [PATCH 5/6] initialization error fix --- lib/web_ui/dev/edge_installation.dart | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/web_ui/dev/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index c27f0e1444f25..a1e3c9ea359f3 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -101,12 +101,6 @@ Future getEdgeInstallation( /// /// See: https://github.com/MicrosoftEdge/edge-launcher class EdgeLauncher { - /// Url for downloading `MicrosoftEdgeLauncher`. - /// - /// Only useful in Windows, hence not added to [PlatformBinding]. - final String windowsEdgeLauncherDownloadUrl = - 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/$version/MicrosoftEdgeLauncher.exe'; - /// Path to the directory that contains `MicrosoftEdgeLauncher.exe`. io.Directory get launcherInstallationDir => io.Directory( path.join(environment.webUiDartToolDir.path, 'microsoftedgelauncher', @@ -121,9 +115,13 @@ class EdgeLauncher { /// Version number launcher executable `MicrosoftEdgeLauncher`. final String version; - EdgeLauncher() - : version = - BrowserLock.instance.configuration['edge']['launcher_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 { From 0e72756f15887249da79705d40689b83f44ea3ae Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Thu, 16 Jan 2020 11:07:24 -0800 Subject: [PATCH 6/6] format --- lib/web_ui/dev/edge_installation.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/web_ui/dev/edge_installation.dart b/lib/web_ui/dev/edge_installation.dart index a1e3c9ea359f3..0f7c7b5be4afd 100644 --- a/lib/web_ui/dev/edge_installation.dart +++ b/lib/web_ui/dev/edge_installation.dart @@ -118,10 +118,12 @@ class EdgeLauncher { /// Url for downloading `MicrosoftEdgeLauncher`. /// /// Only useful in Windows, hence not added to [PlatformBinding]. - String get windowsEdgeLauncherDownloadUrl => + String get windowsEdgeLauncherDownloadUrl => 'https://github.com/MicrosoftEdge/edge-launcher/releases/download/$version/MicrosoftEdgeLauncher.exe'; - EdgeLauncher() : version = BrowserLock.instance.configuration['edge']['launcher_version']; + EdgeLauncher() + : version = + BrowserLock.instance.configuration['edge']['launcher_version']; /// Install the launcher if it does not exist in this system. void install() async {