feat: general wake lock (#347)

This commit is contained in:
lollipopkit
2024-05-07 15:48:08 +08:00
parent d0523c1e54
commit f70449d67d
9 changed files with 59 additions and 40 deletions

View File

@@ -33,6 +33,7 @@ import 'package:toolbox/view/widget/appbar.dart';
import 'package:toolbox/view/widget/cardx.dart';
import 'package:toolbox/view/widget/markdown.dart';
import 'package:toolbox/view/widget/val_builder.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
part 'appbar.dart';
@@ -68,6 +69,9 @@ class _HomePageState extends State<HomePage>
_selectIndex.value = 0;
}
_pageController = PageController(initialPage: _selectIndex.value);
if (Stores.setting.generalWakeLock.fetch()) {
WakelockPlus.enable();
}
}
@override
@@ -82,6 +86,7 @@ class _HomePageState extends State<HomePage>
WidgetsBinding.instance.removeObserver(this);
Pros.server.closeServer();
_pageController.dispose();
WakelockPlus.disable();
}
@override

View File

@@ -176,7 +176,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildSSH() {
return Column(
children: [
_buildWakeLock(),
_buildSSHWakeLock(),
_buildTermTheme(),
_buildFont(),
_buildTermFontSize(),
@@ -1076,6 +1076,7 @@ class _SettingPageState extends State<SettingPage> {
leading: const Icon(MingCute.more_3_fill),
title: Text(l10n.more),
children: [
_buildWakeLock(),
if (isAndroid || isIOS) _buildCollectUsage(),
_buildCollapseUI(),
_buildCupertinoRoute(),
@@ -1136,7 +1137,15 @@ class _SettingPageState extends State<SettingPage> {
return ListTile(
leading: const Icon(MingCute.lock_fill),
title: Text(l10n.wakeLock),
trailing: StoreSwitch(prop: _setting.wakeLock),
trailing: StoreSwitch(prop: _setting.generalWakeLock),
);
}
Widget _buildSSHWakeLock() {
return ListTile(
leading: const Icon(MingCute.lock_fill),
title: Text(l10n.wakeLock),
trailing: StoreSwitch(prop: _setting.sshWakeLock),
);
}
}

View File

@@ -80,7 +80,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
_showHelp();
await _initTerminal();
if (Stores.setting.wakeLock.fetch()) WakelockPlus.enable();
if (Stores.setting.sshWakeLock.fetch()) WakelockPlus.enable();
});
}
@@ -90,7 +90,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
_virtKeyLongPressTimer?.cancel();
_terminalController.dispose();
_discontinuityTimer?.cancel();
WakelockPlus.disable();
if (!Stores.setting.generalWakeLock.fetch()) WakelockPlus.disable();
}
@override