Unverified Commit 60314646 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Find the target platform more accurately on the web. (#61587)

parent d95f79f9
...@@ -7,9 +7,9 @@ import 'platform.dart' as platform; ...@@ -7,9 +7,9 @@ import 'platform.dart' as platform;
/// The dart:html implementation of [platform.defaultTargetPlatform]. /// The dart:html implementation of [platform.defaultTargetPlatform].
platform.TargetPlatform get defaultTargetPlatform { platform.TargetPlatform get defaultTargetPlatform {
// To getter a better guess at the targetPlatform we need to be able to // To get a better guess at the targetPlatform we need to be able to reference
// reference the window, but that won't be available until we fix the // the window, but that won't be available until we fix the platforms
// platforms configuration for Flutter. // configuration for Flutter.
platform.TargetPlatform result = _browserPlatform(); platform.TargetPlatform result = _browserPlatform();
if (platform.debugDefaultTargetPlatformOverride != null) if (platform.debugDefaultTargetPlatformOverride != null)
result = platform.debugDefaultTargetPlatformOverride!; result = platform.debugDefaultTargetPlatformOverride!;
...@@ -21,10 +21,24 @@ platform.TargetPlatform _browserPlatform() { ...@@ -21,10 +21,24 @@ platform.TargetPlatform _browserPlatform() {
if (navigatorPlatform.startsWith('mac')) { if (navigatorPlatform.startsWith('mac')) {
return platform.TargetPlatform.macOS; return platform.TargetPlatform.macOS;
} }
if (navigatorPlatform.startsWith('win')) {
return platform.TargetPlatform.windows;
}
if (navigatorPlatform.contains('iphone') || if (navigatorPlatform.contains('iphone') ||
navigatorPlatform.contains('ipad') || navigatorPlatform.contains('ipad') ||
navigatorPlatform.contains('ipod')) { navigatorPlatform.contains('ipod')) {
return platform.TargetPlatform.iOS; return platform.TargetPlatform.iOS;
} }
if (navigatorPlatform.contains('android')) {
return platform.TargetPlatform.android;
}
// Since some phones can report a window.navigator.platform as Linux, fall
// back to use CSS to disambiguate Android vs Linux desktop. If the CSS
// indicates that a device has a "fine pointer" (mouse) as the primary
// pointing device, then we'll assume desktop linux, and otherwise we'll
// assume Android.
if (html.window.matchMedia('only screen and (pointer: fine)').matches) {
return platform.TargetPlatform.linux;
}
return platform.TargetPlatform.android; return platform.TargetPlatform.android;
} }
...@@ -23,9 +23,12 @@ import '_platform_io.dart' ...@@ -23,9 +23,12 @@ import '_platform_io.dart'
/// adaptations for iOS later). Tests can check iOS behavior by using the /// adaptations for iOS later). Tests can check iOS behavior by using the
/// platform override APIs (such as [ThemeData.platform] in the material /// platform override APIs (such as [ThemeData.platform] in the material
/// library) or by setting [debugDefaultTargetPlatformOverride]. /// library) or by setting [debugDefaultTargetPlatformOverride].
///
/// Tests can also create specific platform tests by and adding a `variant:`
/// argument to the test and using a [TargetPlatformVariant].
// //
// When adding support for a new platform (e.g. Windows Phone, macOS), first // When adding support for a new platform (e.g. Windows Phone, Rasberry Pi),
// create a new value on the [TargetPlatform] enum, then add a rule for // first create a new value on the [TargetPlatform] enum, then add a rule for
// selecting that platform here. // selecting that platform here.
// //
// It would be incorrect to make a platform that isn't supported by // It would be incorrect to make a platform that isn't supported by
...@@ -42,7 +45,7 @@ enum TargetPlatform { ...@@ -42,7 +45,7 @@ enum TargetPlatform {
/// Android: <https://www.android.com/> /// Android: <https://www.android.com/>
android, android,
/// Fuchsia: <https://fuchsia.googlesource.com/> /// Fuchsia: <https://fuchsia.dev/fuchsia-src/concepts>
fuchsia, fuchsia,
/// iOS: <https://www.apple.com/ios/> /// iOS: <https://www.apple.com/ios/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment