launch method
Launch a URL. Opens in the native app if it handles the URL, otherwise opens in the default browser.
On Android, androidPackageName targets the specific app package
so the system resolver doesn't open a different app (e.g. Go vs Maps).
Complete only once handoff is accepted. Throw MapHandoffException only
for confirmed rejection; other exceptions stop fallback because the
outcome is unknown. A blocked popup must be marked blocked, not retried.
Implementation
@override
Future<void> launch(String url, {String? androidPackageName}) async {
final uri = Uri.tryParse(url);
if (uri == null ||
(uri.scheme != 'https' && uri.scheme != 'http') ||
uri.host.isEmpty ||
url.contains('\u0000')) {
throw ArgumentError.value(
url,
'url',
'Desktop maps require an HTTP(S) URL',
);
}
final ProcessResult result;
if (Platform.isMacOS) {
result = await Process.run('open', [url]);
} else if (Platform.isWindows) {
result = await Process.run('powershell.exe', windowsLaunchArguments(url));
} else if (Platform.isLinux) {
result = await Process.run('xdg-open', [url]);
} else {
throw UnsupportedError(
'MapLauncherDesktop does not support ${Platform.operatingSystem}',
);
}
if (result.exitCode != 0) {
throw Exception('Failed to launch URL: ${result.stderr}');
}
}