mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: 处于后台时,定时关闭跳过弹窗询问,直接执行
This commit is contained in:
@@ -7,7 +7,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|||||||
|
|
||||||
import '../plugin/pl_player/controller.dart';
|
import '../plugin/pl_player/controller.dart';
|
||||||
|
|
||||||
class ShutdownTimerService {
|
class ShutdownTimerService with WidgetsBindingObserver {
|
||||||
static final ShutdownTimerService _instance =
|
static final ShutdownTimerService _instance =
|
||||||
ShutdownTimerService._internal();
|
ShutdownTimerService._internal();
|
||||||
Timer? _shutdownTimer;
|
Timer? _shutdownTimer;
|
||||||
@@ -17,10 +17,24 @@ class ShutdownTimerService {
|
|||||||
bool exitApp = false;
|
bool exitApp = false;
|
||||||
bool waitForPlayingCompleted = false;
|
bool waitForPlayingCompleted = false;
|
||||||
bool isWaiting = false;
|
bool isWaiting = false;
|
||||||
|
bool isInBackground = false;
|
||||||
factory ShutdownTimerService() => _instance;
|
factory ShutdownTimerService() => _instance;
|
||||||
|
|
||||||
ShutdownTimerService._internal();
|
ShutdownTimerService._internal() {
|
||||||
|
WidgetsBinding.instance.addObserver(this); // 添加观察者
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this); // 移除观察者
|
||||||
|
_shutdownTimer?.cancel();
|
||||||
|
_autoCloseDialogTimer?.cancel();
|
||||||
|
_instance.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
isInBackground = state == AppLifecycleState.paused;
|
||||||
|
}
|
||||||
|
|
||||||
void startShutdownTimer() {
|
void startShutdownTimer() {
|
||||||
cancelShutdownTimer(); // Cancel any previous timer
|
cancelShutdownTimer(); // Cancel any previous timer
|
||||||
@@ -55,6 +69,11 @@ class ShutdownTimerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showShutdownDialog() {
|
void _showShutdownDialog() {
|
||||||
|
if (isInBackground) {
|
||||||
|
print("app在后台运行,不弹窗");
|
||||||
|
_executeShutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
SmartDialog.show(
|
SmartDialog.show(
|
||||||
builder: (BuildContext dialogContext) {
|
builder: (BuildContext dialogContext) {
|
||||||
// Start the 10-second timer to auto close the dialog
|
// Start the 10-second timer to auto close the dialog
|
||||||
@@ -124,6 +143,7 @@ class ShutdownTimerService {
|
|||||||
|
|
||||||
void _executeShutdown() {
|
void _executeShutdown() {
|
||||||
if (exitApp) {
|
if (exitApp) {
|
||||||
|
PlPlayerController.pauseIfExists();
|
||||||
//退出app
|
//退出app
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -136,14 +156,6 @@ class ShutdownTimerService {
|
|||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast("当前未播放");
|
SmartDialog.showToast("当前未播放");
|
||||||
}
|
}
|
||||||
// PlPlayerController plPlayerController = PlPlayerController.getInstance();
|
|
||||||
// if (plPlayerController.playerStatus.playing) {
|
|
||||||
// plPlayerController.pause();
|
|
||||||
// waitForPlayingCompleted = true;
|
|
||||||
// SmartDialog.showToast("已暂停播放");
|
|
||||||
// } else {
|
|
||||||
// SmartDialog.showToast("当前未播放");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user