mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
feat: disable screen wake lock on Android
This commit is contained in:
@@ -62,12 +62,17 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
|
||||
|
||||
bool _advanced = false;
|
||||
|
||||
/// On Android the foreground service keeps the process and the connection alive,
|
||||
/// so there is no reason to also keep the screen on.
|
||||
bool get _useWakelock => checkPlatformIsNot([TargetPlatform.android]);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// init
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_useWakelock) {
|
||||
try {
|
||||
unawaited(WakelockPlus.enable());
|
||||
} catch (_) {}
|
||||
@@ -89,6 +94,7 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
|
||||
} catch (_) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (ref.read(settingsProvider).autoFinish) {
|
||||
_finishTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
@@ -174,10 +180,12 @@ class _ProgressPageState extends State<ProgressPage> with Refena {
|
||||
_finishTimer?.cancel();
|
||||
_wakelockPlusTimer?.cancel();
|
||||
TaskbarHelper.clearProgressBar(); // ignore: discarded_futures
|
||||
if (_useWakelock) {
|
||||
try {
|
||||
WakelockPlus.disable(); // ignore: discarded_futures
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user