mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-18 14:05:37 +00:00
Centralize debounce of save window pos and save window pos on close (#12987)
* Added method equals to class LastWindowPosition to compare the contents of instances. Added storage to common.dart for remembering what window position data has previously been written. Factored the actual save code from saveWindowPosition to _saveWindowPositionActual and updated saveWindowPosition to call it through a debouncer, and only if the window position data has actually changed since the last call in the same instance. Added named parameter 'flush' to saveWindowPosition in common.dart, and to _saveFrame in tabbar_widget.dart, and updated the onWindowClosed handler in tabbar_widget.dart to call _saveFrame with flush: true, forcing an immediate save on close. Removed the _saveFrame debouncer from tabbar_widget.dart. * saveWindowPosition: don't reschedule debounce if it's already in flight * Reworked the logic in saveWindowPosition to collapse a rapid series of updates into one save at the end.
This commit is contained in:
@@ -292,7 +292,6 @@ class DesktopTab extends StatefulWidget {
|
||||
// ignore: must_be_immutable
|
||||
class _DesktopTabState extends State<DesktopTab>
|
||||
with MultiWindowListener, WindowListener {
|
||||
final _saveFrameDebounce = Debouncer(delay: Duration(seconds: 1));
|
||||
Timer? _macOSCheckRestoreTimer;
|
||||
int _macOSCheckRestoreCounter = 0;
|
||||
|
||||
@@ -370,7 +369,7 @@ class _DesktopTabState extends State<DesktopTab>
|
||||
|
||||
void _setMaximized(bool maximize) {
|
||||
stateGlobal.setMaximized(maximize);
|
||||
_saveFrameDebounce.call(_saveFrame);
|
||||
_saveFrame();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -405,23 +404,23 @@ class _DesktopTabState extends State<DesktopTab>
|
||||
super.onWindowUnmaximize();
|
||||
}
|
||||
|
||||
_saveFrame() async {
|
||||
_saveFrame({bool? flush}) async {
|
||||
if (tabType == DesktopTabType.main) {
|
||||
await saveWindowPosition(WindowType.Main);
|
||||
await saveWindowPosition(WindowType.Main, flush: flush);
|
||||
} else if (kWindowType != null && kWindowId != null) {
|
||||
await saveWindowPosition(kWindowType!, windowId: kWindowId);
|
||||
await saveWindowPosition(kWindowType!, windowId: kWindowId, flush: flush);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMoved() {
|
||||
_saveFrameDebounce.call(_saveFrame);
|
||||
_saveFrame();
|
||||
super.onWindowMoved();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowResized() {
|
||||
_saveFrameDebounce.call(_saveFrame);
|
||||
_saveFrame();
|
||||
super.onWindowResized();
|
||||
}
|
||||
|
||||
@@ -460,6 +459,8 @@ class _DesktopTabState extends State<DesktopTab>
|
||||
});
|
||||
}
|
||||
|
||||
await _saveFrame(flush: true);
|
||||
|
||||
// hide window on close
|
||||
if (isMainWindow) {
|
||||
if (rustDeskWinManager.getActiveWindows().contains(kMainWindowId)) {
|
||||
|
||||
Reference in New Issue
Block a user