mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat(android): Filter Device To Force High Frame Rate (#880)
* fix(android): filter device to force HFR * fix(android): add failsafe in setHighRefreshRate
This commit is contained in:
parent
22a49e56a2
commit
6e41b106fa
@ -1,4 +1,5 @@
|
|||||||
import 'package:catcher_2/catcher_2.dart';
|
import 'package:catcher_2/catcher_2.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:dart_discord_rpc/dart_discord_rpc.dart';
|
import 'package:dart_discord_rpc/dart_discord_rpc.dart';
|
||||||
import 'package:device_preview/device_preview.dart';
|
import 'package:device_preview/device_preview.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -38,7 +39,7 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
import 'package:spotube/hooks/configurators/use_init_sys_tray.dart';
|
import 'package:spotube/hooks/configurators/use_init_sys_tray.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||||
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
import 'package:spotube/utils/android_utils.dart';
|
||||||
|
|
||||||
Future<void> main(List<String> rawArgs) async {
|
Future<void> main(List<String> rawArgs) async {
|
||||||
final arguments = await startCLI(rawArgs);
|
final arguments = await startCLI(rawArgs);
|
||||||
@ -53,7 +54,7 @@ Future<void> main(List<String> rawArgs) async {
|
|||||||
|
|
||||||
// force High Refresh Rate on some Android devices (like One Plus)
|
// force High Refresh Rate on some Android devices (like One Plus)
|
||||||
if (DesktopTools.platform.isAndroid) {
|
if (DesktopTools.platform.isAndroid) {
|
||||||
await FlutterDisplayMode.setHighRefreshRate();
|
await AndroidUtils.setHighRefreshRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DesktopTools.platform.isDesktop) {
|
if (DesktopTools.platform.isDesktop) {
|
||||||
|
39
lib/utils/android_utils.dart
Normal file
39
lib/utils/android_utils.dart
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
||||||
|
|
||||||
|
abstract class AndroidUtils {
|
||||||
|
|
||||||
|
/// Sets the device's display to the highest refresh rate available.
|
||||||
|
///
|
||||||
|
/// This method retrieves the list of supported display modes and the currently active display mode.
|
||||||
|
/// It then selects the display mode with the highest refresh rate that matches the current resolution.
|
||||||
|
/// The selected display mode is set as the preferred mode using the FlutterDisplayMode plugin.
|
||||||
|
/// After setting the new mode, it checks if the system is using the new mode.
|
||||||
|
/// If the system is not using the new mode, it reverts back to the original mode and returns false.
|
||||||
|
/// Otherwise, it returns true to indicate that the high refresh rate has been successfully set.
|
||||||
|
///
|
||||||
|
/// Returns true if the high refresh rate is set successfully, false otherwise.
|
||||||
|
static Future<bool> setHighRefreshRate() async {
|
||||||
|
final List<DisplayMode> modes = await FlutterDisplayMode.supported;
|
||||||
|
final DisplayMode activeMode = await FlutterDisplayMode.active;
|
||||||
|
|
||||||
|
DisplayMode newMode = activeMode;
|
||||||
|
for (final DisplayMode mode in modes) {
|
||||||
|
if (mode.height == newMode.height &&
|
||||||
|
mode.width == newMode.width &&
|
||||||
|
mode.refreshRate > newMode.refreshRate) {
|
||||||
|
newMode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await FlutterDisplayMode.setPreferredMode(newMode);
|
||||||
|
|
||||||
|
final display = await FlutterDisplayMode.active; // possibly altered by system
|
||||||
|
|
||||||
|
if (display.refreshRate < newMode.refreshRate) {
|
||||||
|
await FlutterDisplayMode.setPreferredMode(display);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user