defaultExternalUrlLauncher function
Default desktop URL launcher used by ready-made fresh-install UI.
Implementation
Future<void> defaultExternalUrlLauncher(Uri url) async {
final scheme = url.scheme.toLowerCase();
if (scheme != "http" && scheme != "https") {
throw ArgumentError.value(url, "url", "Only http(s) URLs can be opened.");
}
final urlText = url.toString();
final executable = switch (Platform.operatingSystem) {
"macos" => "open",
"windows" => "rundll32",
_ => "xdg-open",
};
final arguments = switch (Platform.operatingSystem) {
"windows" => ["url.dll,FileProtocolHandler", urlText],
_ => [urlText],
};
final result = await Process.run(executable, arguments);
if (result.exitCode != 0) {
throw ProcessException(
executable,
arguments,
"${result.stdout}\n${result.stderr}",
result.exitCode,
);
}
}