From f595f33f4a388c76fcdec99fee7aca2403bd077b Mon Sep 17 00:00:00 2001 From: Marck64 Date: Thu, 21 May 2026 21:27:46 +0200 Subject: [PATCH] feat: Implement window size save scheduling to enhance window management --- lib/app.dart | 56 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 3cfa326..dacd5a7 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -41,6 +41,7 @@ class _NotesAppState extends State static const Duration _screenTransitionDuration = Duration(milliseconds: 280); static const Duration _biometricInactivityTimeout = Duration(minutes: 5); static const Duration _syncInterval = Duration(minutes: 5); + static const Duration _windowSizeSaveDelay = Duration(milliseconds: 350); static const String _themeSeedColorKey = 'theme_seed_color_v1'; final LocalVaultService _vaultService = LocalVaultService.instance; @@ -56,6 +57,7 @@ class _NotesAppState extends State bool _biometricGateEnabled = false; int _biometricGateSession = 0; Timer? _biometricLockTimer; + Timer? _windowSizeSaveTimer; Timer? _syncTimer; bool _isHandlingWindowClose = false; _AppPhase _phase = _AppPhase.loading; @@ -88,6 +90,7 @@ class _NotesAppState extends State windowManager.setPreventClose(false); } _biometricLockTimer?.cancel(); + _windowSizeSaveTimer?.cancel(); _syncTimer?.cancel(); _database?.close(); super.dispose(); @@ -123,7 +126,8 @@ class _NotesAppState extends State // Cached ThemeData to avoid recomputing on every build. ThemeData? _themeData; - ThemeData get _theme => _themeData ??= AppTheme.theme(seedColor: _themeSeedColor); + ThemeData get _theme => + _themeData ??= AppTheme.theme(seedColor: _themeSeedColor); @override void didChangeAppLifecycleState(AppLifecycleState state) { @@ -667,6 +671,22 @@ class _NotesAppState extends State await WindowStateStore.instance.saveWindowSize(currentSize); } + void _scheduleWindowSizeSave() { + if (!isDesktop) { + return; + } + + _windowSizeSaveTimer?.cancel(); + _windowSizeSaveTimer = Timer(_windowSizeSaveDelay, () { + _windowSizeSaveTimer = null; + if (!mounted) { + return; + } + + unawaited(_saveWindowSize()); + }); + } + void _startPeriodicSync() { _syncTimer?.cancel(); _syncTimer = Timer.periodic(_syncInterval, (_) { @@ -859,20 +879,20 @@ class _NotesAppState extends State switchOutCurve: Curves.easeInCubic, transitionBuilder: (Widget child, Animation animation) { - final Animation offsetAnimation = - Tween( - begin: const Offset(0.08, 0.0), - end: Offset.zero, - ).animate(animation); + final Animation offsetAnimation = + Tween( + begin: const Offset(0.08, 0.0), + end: Offset.zero, + ).animate(animation); - return FadeTransition( - opacity: animation, - child: SlideTransition( - position: offsetAnimation, - child: child, - ), - ); - }, + return FadeTransition( + opacity: animation, + child: SlideTransition( + position: offsetAnimation, + child: child, + ), + ); + }, child: activeScreen, ), ), @@ -888,12 +908,12 @@ class _NotesAppState extends State @override void onWindowResize() { - _saveWindowSize(); + _scheduleWindowSizeSave(); } @override void onWindowResized() { - _saveWindowSize(); + _scheduleWindowSizeSave(); } @override @@ -912,6 +932,10 @@ class _NotesAppState extends State return; } + _windowSizeSaveTimer?.cancel(); + _windowSizeSaveTimer = null; + unawaited(_saveWindowSize()); + if (!_needsBiometricLock) { unawaited(_allowWindowClose()); return;