From edab909fb0d92fee4ddb461a32ac9b90028b6969 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Thu, 9 Mar 2023 19:11:22 +0100 Subject: [PATCH] screensaver: init fix --- lib/model/device.dart | 8 +++++++- lib/widgets/viewer/entry_viewer_stack.dart | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/model/device.dart b/lib/model/device.dart index 1601324ab..22ce40c16 100644 --- a/lib/model/device.dart +++ b/lib/model/device.dart @@ -1,6 +1,7 @@ import 'package:aves/services/common/services.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:floating/floating.dart'; +import 'package:flutter/services.dart'; import 'package:local_auth/local_auth.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -57,7 +58,12 @@ class Device { _canAuthenticateUser = await auth.canCheckBiometrics || await auth.isDeviceSupported(); final floating = Floating(); - _supportPictureInPicture = await floating.isPipAvailable; + try { + _supportPictureInPicture = await floating.isPipAvailable; + } on PlatformException catch (_) { + // as of floating v2.0.0, plugin assumes activity and fails when bound via service + _supportPictureInPicture = false; + } floating.dispose(); final capabilities = await deviceService.getCapabilities(); diff --git a/lib/widgets/viewer/entry_viewer_stack.dart b/lib/widgets/viewer/entry_viewer_stack.dart index 9cf35d55d..427755218 100644 --- a/lib/widgets/viewer/entry_viewer_stack.dart +++ b/lib/widgets/viewer/entry_viewer_stack.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:aves/app_mode.dart'; import 'package:aves/model/actions/entry_actions.dart'; import 'package:aves/model/actions/move_type.dart'; +import 'package:aves/model/device.dart'; import 'package:aves/model/entry.dart'; import 'package:aves/model/filters/filters.dart'; import 'package:aves/model/filters/trash.dart'; @@ -241,7 +242,9 @@ class _EntryViewerStackState extends State with EntryViewContr onViewDisposed: (mainEntry, pageEntry) => viewStateConductor.reset(pageEntry ?? mainEntry), ); return StreamBuilder( - stream: _floating.pipStatus$, + // as of floating v2.0.0, plugin assumes activity and fails when bound via service + // so we do not access status stream directly, but check for support first + stream: device.supportPictureInPicture ? _floating.pipStatus$ : Stream.value(PiPStatus.disabled), builder: (context, snapshot) { var pipEnabled = snapshot.data == PiPStatus.enabled; return Stack(