fix window save pos, debug win

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-07-26 00:40:03 +08:00
parent eb8b264b18
commit 5e9841e7ab
2 changed files with 29 additions and 5 deletions

View File

@ -1383,12 +1383,17 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
return;
}
final position = frame.topLeft;
if (position.dx < 0 || position.dy < 0) {
debugPrint("Window $windowId is hidden, ignoring position restoration");
return;
}
final sz = frame.size;
final isMaximized = await wc.isMaximized();
final pos = LastWindowPosition(
sz.width, sz.height, position.dx, position.dy, isMaximized);
debugPrint(
"saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}");
"Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}");
await bind.setLocalFlutterConfig(
k: kWindowPrefix + type.name, v: pos.toString());
break;
@ -1864,10 +1869,7 @@ Future<void> onActiveWindowChanged() async {
if (rustDeskWinManager.getActiveWindows().isEmpty) {
// close all sub windows
try {
await Future.wait([
saveWindowPosition(WindowType.Main),
rustDeskWinManager.closeAllSubWindows()
]);
await rustDeskWinManager.closeAllSubWindows();
} catch (err) {
debugPrintStack(label: "$err");
} finally {

View File

@ -478,6 +478,8 @@ class WindowActionPanel extends StatefulWidget {
class WindowActionPanelState extends State<WindowActionPanel>
with MultiWindowListener, WindowListener {
final _saveFrameDebounce = Debouncer(delay: Duration(seconds: 1));
@override
void initState() {
super.initState();
@ -537,6 +539,26 @@ class WindowActionPanelState extends State<WindowActionPanel>
super.onWindowUnmaximize();
}
_saveFrame() async {
if (widget.tabType == DesktopTabType.main) {
await saveWindowPosition(WindowType.Main);
} else if (kWindowType != null && kWindowId != null) {
await saveWindowPosition(kWindowType!, windowId: kWindowId);
}
}
@override
void onWindowMoved() {
_saveFrameDebounce.call(_saveFrame);
super.onWindowMoved();
}
@override
void onWindowResized() {
_saveFrameDebounce.call(_saveFrame);
super.onWindowMoved();
}
@override
void onWindowClose() async {
// hide window on close