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 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 `` in `` 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) {