feat: Implement window size save scheduling to enhance window management
This commit is contained in:
+27
-3
@@ -41,6 +41,7 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
static const Duration _screenTransitionDuration = Duration(milliseconds: 280);
|
static const Duration _screenTransitionDuration = Duration(milliseconds: 280);
|
||||||
static const Duration _biometricInactivityTimeout = Duration(minutes: 5);
|
static const Duration _biometricInactivityTimeout = Duration(minutes: 5);
|
||||||
static const Duration _syncInterval = 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';
|
static const String _themeSeedColorKey = 'theme_seed_color_v1';
|
||||||
|
|
||||||
final LocalVaultService _vaultService = LocalVaultService.instance;
|
final LocalVaultService _vaultService = LocalVaultService.instance;
|
||||||
@@ -56,6 +57,7 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
bool _biometricGateEnabled = false;
|
bool _biometricGateEnabled = false;
|
||||||
int _biometricGateSession = 0;
|
int _biometricGateSession = 0;
|
||||||
Timer? _biometricLockTimer;
|
Timer? _biometricLockTimer;
|
||||||
|
Timer? _windowSizeSaveTimer;
|
||||||
Timer? _syncTimer;
|
Timer? _syncTimer;
|
||||||
bool _isHandlingWindowClose = false;
|
bool _isHandlingWindowClose = false;
|
||||||
_AppPhase _phase = _AppPhase.loading;
|
_AppPhase _phase = _AppPhase.loading;
|
||||||
@@ -88,6 +90,7 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
windowManager.setPreventClose(false);
|
windowManager.setPreventClose(false);
|
||||||
}
|
}
|
||||||
_biometricLockTimer?.cancel();
|
_biometricLockTimer?.cancel();
|
||||||
|
_windowSizeSaveTimer?.cancel();
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
_database?.close();
|
_database?.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -123,7 +126,8 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
// Cached ThemeData to avoid recomputing on every build.
|
// Cached ThemeData to avoid recomputing on every build.
|
||||||
ThemeData? _themeData;
|
ThemeData? _themeData;
|
||||||
|
|
||||||
ThemeData get _theme => _themeData ??= AppTheme.theme(seedColor: _themeSeedColor);
|
ThemeData get _theme =>
|
||||||
|
_themeData ??= AppTheme.theme(seedColor: _themeSeedColor);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
@@ -667,6 +671,22 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
await WindowStateStore.instance.saveWindowSize(currentSize);
|
await WindowStateStore.instance.saveWindowSize(currentSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _scheduleWindowSizeSave() {
|
||||||
|
if (!isDesktop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_windowSizeSaveTimer?.cancel();
|
||||||
|
_windowSizeSaveTimer = Timer(_windowSizeSaveDelay, () {
|
||||||
|
_windowSizeSaveTimer = null;
|
||||||
|
if (!mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unawaited(_saveWindowSize());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _startPeriodicSync() {
|
void _startPeriodicSync() {
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
_syncTimer = Timer.periodic(_syncInterval, (_) {
|
_syncTimer = Timer.periodic(_syncInterval, (_) {
|
||||||
@@ -888,12 +908,12 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onWindowResize() {
|
void onWindowResize() {
|
||||||
_saveWindowSize();
|
_scheduleWindowSizeSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onWindowResized() {
|
void onWindowResized() {
|
||||||
_saveWindowSize();
|
_scheduleWindowSizeSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -912,6 +932,10 @@ class _NotesAppState extends State<NotesApp>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_windowSizeSaveTimer?.cancel();
|
||||||
|
_windowSizeSaveTimer = null;
|
||||||
|
unawaited(_saveWindowSize());
|
||||||
|
|
||||||
if (!_needsBiometricLock) {
|
if (!_needsBiometricLock) {
|
||||||
unawaited(_allowWindowClose());
|
unawaited(_allowWindowClose());
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user