diff --git a/lib/main.dart b/lib/main.dart index d44ed5e..4135dc8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -140,10 +140,6 @@ void main() async { appSettingsCubit.stream.listen((event) => languageHeaderInterceptor .preferredLocaleSubtag = event.preferredLocaleSubtag); - // Temporary Fix: Can be removed if the flutter engine implements the fix itself - // Activate the highest availabe refresh rate on the device - await FlutterDisplayMode.setHighRefreshRate(); - runApp( MultiProvider( providers: [ @@ -201,6 +197,21 @@ void main() async { ); } +Future setOptimalDisplayMode() async { + final List supported = await FlutterDisplayMode.supported; + final DisplayMode active = await FlutterDisplayMode.active; + + final List sameResolution = supported + .where((m) => m.width == active.width && m.height == active.height) + .toList() + ..sort((a, b) => b.refreshRate.compareTo(a.refreshRate)); + + final DisplayMode mostOptimalMode = + sameResolution.isNotEmpty ? sameResolution.first : active; + + await FlutterDisplayMode.setPreferredMode(mostOptimalMode); +} + class PaperlessMobileEntrypoint extends StatefulWidget { const PaperlessMobileEntrypoint({ Key? key, @@ -282,11 +293,15 @@ class _AuthenticationWrapperState extends State { @override void initState() { super.initState(); + // Temporary Fix: Can be removed if the flutter engine implements the fix itself + // Activate the highest supported refresh rate on the device + setOptimalDisplayMode(); initializeDateFormatting(); // For sharing files coming from outside the app while the app is still opened ReceiveSharingIntent.getMediaStream() .listen(ShareIntentQueue.instance.addAll); // For sharing files coming from outside the app while the app is closed + // TODO: This does not work currently, app does not have permission to access the shared file ReceiveSharingIntent.getInitialMedia() .then(ShareIntentQueue.instance.addAll); }