diff --git a/lib/main.dart b/lib/main.dart index 7fb50b5..8dbc765 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -158,7 +158,7 @@ class InputSyncPage extends StatefulWidget { } class _InputSyncPageState extends State - with TickerProviderStateMixin { + with TickerProviderStateMixin, WidgetsBindingObserver { static const _hostKey = 'server_host'; static const _portKey = 'server_port'; static const _historyKey = 'send_history'; @@ -188,6 +188,7 @@ class _InputSyncPageState extends State @override void initState() { super.initState(); + WidgetsBinding.instance.addObserver(this); statusPulseController = AnimationController( vsync: this, duration: const Duration(milliseconds: 1300), @@ -206,6 +207,7 @@ class _InputSyncPageState extends State @override void dispose() { + WidgetsBinding.instance.removeObserver(this); stateSubscription?.cancel(); statusPulseController.dispose(); radarPulseController.dispose(); @@ -216,8 +218,16 @@ class _InputSyncPageState extends State super.dispose(); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + unawaited(_syncAppendEnterFromPrefs()); + } + } + Future _loadSavedState() async { final prefs = await SharedPreferences.getInstance(); + await prefs.reload(); final nativeState = await api.getState(); if (!mounted) { return; @@ -449,6 +459,19 @@ class _InputSyncPageState extends State }); } + Future _syncAppendEnterFromPrefs() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.reload(); + final nextAppendEnter = prefs.getBool(_appendEnterKey) ?? false; + if (!mounted || nextAppendEnter == appendEnter) { + return; + } + + setState(() { + appendEnter = nextAppendEnter; + }); + } + void _restoreHistory(String text) { inputController.text = text; inputController.selection = TextSelection.collapsed(offset: text.length);