Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: Center the main window on first run. (#13003)

fufesoudee03c0f9fa2
diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart
index 5f5f11eef..e516c02be 100644
--- a/flutter/lib/common.dart
+++ b/flutter/lib/common.dart
@@ -1949,8 +1949,24 @@ Future<bool> restoreWindowPosition(WindowType type,
var lpos = LastWindowPosition.loadFromString(pos);
if (lpos == null) {
- debugPrint("no window position saved, ignoring position restoration");
- return false;
+ debugPrint("No window position saved, trying to center the window.");
+ switch (type) {
+ case WindowType.Main:
+ // Center the main window only if no position is saved (on first run).
+ if (isWindows || isLinux) {
+ await windowManager.center();
+ }
+ // For MacOS, the window is already centered by default.
+ // See https://github.com/rustdesk/rustdesk/blob/9b9276e7524523d7f667fefcd0694d981443df0e/flutter/macos/Runner/Base.lproj/MainMenu.xib#L333
+ // If `<windowPositionMask>` in `<window>` is not set, the window will be centered.
+ break;
+ default:
+ // No need to change the position of a sub window if no position is saved,
+ // since the default position is already centered.
+ // https://github.com/rustdesk/rustdesk/blob/317639169359936f7f9f85ef445ec9774218772d/flutter/lib/utils/multi_window_manager.dart#L163
+ break;
+ }
+ return true;
}
if (type == WindowType.RemoteDesktop || type == WindowType.ViewCamera) {
if (!isRemotePeerPos && windowId != null) {