Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/web_ui/dev/browser_lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ chrome:
Win: 695655
firefox:
version: '71.0'
edge:
launcher_version: '1.2.0.0'
3 changes: 0 additions & 3 deletions lib/web_ui/dev/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
77 changes: 76 additions & 1 deletion lib/web_ui/dev/edge_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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._();
Expand Down Expand Up @@ -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 {
/// 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',
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;

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