feat: Implement window size save scheduling to enhance window management

This commit is contained in:
2026-05-21 21:27:46 +02:00
parent d7495a461a
commit f595f33f4a
+40 -16
View File
@@ -41,6 +41,7 @@ class _NotesAppState extends State<NotesApp>
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<NotesApp>
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<NotesApp>
windowManager.setPreventClose(false);
}
_biometricLockTimer?.cancel();
_windowSizeSaveTimer?.cancel();
_syncTimer?.cancel();
_database?.close();
super.dispose();
@@ -123,7 +126,8 @@ class _NotesAppState extends State<NotesApp>
// 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<NotesApp>
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<NotesApp>
switchOutCurve: Curves.easeInCubic,
transitionBuilder:
(Widget child, Animation<double> animation) {
final Animation<Offset> offsetAnimation =
Tween<Offset>(
begin: const Offset(0.08, 0.0),
end: Offset.zero,
).animate(animation);
final Animation<Offset> offsetAnimation =
Tween<Offset>(
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<NotesApp>
@override
void onWindowResize() {
_saveWindowSize();
_scheduleWindowSizeSave();
}
@override
void onWindowResized() {
_saveWindowSize();
_scheduleWindowSizeSave();
}
@override
@@ -912,6 +932,10 @@ class _NotesAppState extends State<NotesApp>
return;
}
_windowSizeSaveTimer?.cancel();
_windowSizeSaveTimer = null;
unawaited(_saveWindowSize());
if (!_needsBiometricLock) {
unawaited(_allowWindowClose());
return;