[web] edge launcher for windows (flutter/engine#15690)

* edge launcher for windows

* addressing PR comments

* url mistake

* remove uncessary import

* initialization error fix

* format
This commit is contained in:
Nurhan Turgut
2020-01-16 14:48:13 -08:00
committed by GitHub
parent 3de56d8153
commit 8ca3dd95d8
3 changed files with 78 additions and 4 deletions

View File

@@ -6,3 +6,5 @@ chrome:
Win: 695655
firefox:
version: '71.0'
edge:
launcher_version: '1.2.0.0'

View File

@@ -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';
}

View File

@@ -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<BrowserInstallation> 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();
}
}
}