Handle edge case where on disposing media_kit player, wakelock state if enabled across app sessions is not respected

This commit is contained in:
ashilkn
2025-04-22 11:59:19 +05:30
parent 879f16a2dd
commit 9f3c4c8542
2 changed files with 10 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ enum WakeLockFor {
videoPlayback,
fasterBackupsOniOSByKeepingScreenAwake,
machineLearningSettingsScreen,
handlingMediaKitEdgeCase,
}
/// Use this class to enable/disable wakelock. This class makes sure that
@@ -34,7 +35,8 @@ class EnteWakeLockService {
required bool enable,
required WakeLockFor wakeLockFor,
}) {
if (wakeLockFor == WakeLockFor.fasterBackupsOniOSByKeepingScreenAwake) {
if (wakeLockFor == WakeLockFor.fasterBackupsOniOSByKeepingScreenAwake ||
wakeLockFor == WakeLockFor.handlingMediaKitEdgeCase) {
WakelockPlus.toggle(enable: enable);
_prefs.setBool(kKeepAppAwakeAcrossSessions, enable);
} else {

View File

@@ -16,6 +16,7 @@ import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
import "package:photos/services/wake_lock_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/ui/actions/file/file_actions.dart";
import "package:photos/ui/common/loading_widget.dart";
@@ -161,6 +162,12 @@ class _VideoWidgetMediaKitNewState extends State<VideoWidgetMediaKitNew>
WidgetsBinding.instance.removeObserver(this);
player.dispose();
_captionUpdatedSubscription.cancel();
if (EnteWakeLockService.instance.shouldKeepAppAwakeAcrossSessions()) {
EnteWakeLockService.instance.updateWakeLock(
enable: true,
wakeLockFor: WakeLockFor.handlingMediaKitEdgeCase,
);
}
super.dispose();
}