From 5d5adbc73fee687afc68b2f3471b5ca2f03bf555 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 2 Oct 2025 10:50:56 +0800 Subject: [PATCH] cache desktop volume Signed-off-by: bggRGjQaUbCoE --- lib/plugin/pl_player/controller.dart | 10 +++++++++- lib/utils/storage_key.dart | 3 ++- lib/utils/storage_pref.dart | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index df315d54..b9a8a364 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -94,7 +94,9 @@ class PlPlayerController { late double lastPlaybackSpeed = 1.0; final RxDouble _playbackSpeed = Pref.playSpeedDefault.obs; late final RxDouble _longPressSpeed = Pref.longPressSpeedDefault.obs; - final RxDouble _currentVolume = 1.0.obs; + final RxDouble _currentVolume = RxDouble( + Utils.isDesktop ? Pref.desktopVolume : 1.0, + ); final RxDouble _currentBrightness = (-1.0).obs; final RxBool _showControls = false.obs; @@ -779,6 +781,9 @@ class PlPlayerController { ); final pp = player.platform!; if (_videoPlayerController == null) { + if (Utils.isDesktop) { + pp.setVolume(this.volume.value * 100); + } if (isAnim) { setShader(superResolutionType.value, pp); } @@ -1330,6 +1335,9 @@ class PlPlayerController { volumeTimer = Timer(const Duration(milliseconds: 200), () { volumeIndicator.value = false; volumeInterceptEventStream.value = false; + if (Utils.isDesktop) { + setting.put(SettingBoxKey.desktopVolume, volume.toPrecision(3)); + } }); } diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index 4a357a9c..4fb76125 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -144,7 +144,8 @@ abstract class SettingBoxKey { windowSize = 'windowSize', windowPosition = 'windowPosition', isWindowMaximized = 'isWindowMaximized', - showWindowTitleBar = 'showWindowTitleBar'; + showWindowTitleBar = 'showWindowTitleBar', + desktopVolume = 'desktopVolume'; static const String subtitlePreferenceV2 = 'subtitlePreferenceV2', enableDragSubtitle = 'enableDragSubtitle', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 8382d3e8..06052309 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -844,4 +844,7 @@ abstract class Pref { static bool get showWindowTitleBar => _setting.get(SettingBoxKey.showWindowTitleBar, defaultValue: true); + + static double get desktopVolume => + _setting.get(SettingBoxKey.desktopVolume, defaultValue: 1.0); }