diff --git a/lib/main.dart b/lib/main.dart index f8c3aa8c..45f99d61 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,7 @@ import 'package:spotube/services/audio_player/audio_player.dart'; import 'package:spotube/services/cli/cli.dart'; import 'package:spotube/services/connectivity_adapter.dart'; import 'package:spotube/themes/theme.dart'; +import 'package:spotube/utils/device_utils.dart'; import 'package:spotube/utils/persisted_state_notifier.dart'; import 'package:system_theme/system_theme.dart'; import 'package:path_provider/path_provider.dart'; @@ -44,7 +45,10 @@ Future main(List rawArgs) async { // force High Refresh Rate on some Android devices (like One Plus) if (DesktopTools.platform.isAndroid) { - await FlutterDisplayMode.setHighRefreshRate(); + final props = await buildProps; + if (isBuggyOs(props)) { + await FlutterDisplayMode.setHighRefreshRate(); + } } await DesktopTools.ensureInitialized( diff --git a/lib/utils/device_utils.dart b/lib/utils/device_utils.dart new file mode 100644 index 00000000..3111b687 --- /dev/null +++ b/lib/utils/device_utils.dart @@ -0,0 +1,32 @@ +import 'dart:io'; + +import 'package:collection/collection.dart'; + +Future> get buildProps async { + try { + final getProp = await Process.run('getprop', []); + return Map.fromEntries( + getProp.stdout + .toString() + .split('\n') + .where((x) => x.startsWith('[') && x.endsWith(']')) + .map((e) => e.replaceAll(RegExp(r'(^\[|\]$)'), '').split(']: [')) + .map((x) => MapEntry(x.first, x.last)) + .where((x) => x.value.isNotEmpty), + ); + } catch (e, s) { + return {}; + } +} + +bool isBuggyOs(Map props) { + final brand = [ + 'ro.product.brand', + 'ro.product.system.brand', + 'ro.product.system_ext.brand', + 'ro.product.vendor.brand', + ].map((x) => props[x]?.toLowerCase()).whereNotNull(); + final oppo = ['oppo', 'oplus', 'oneplus', 'realme']; + + return oppo.any(brand.contains); +}