From dee03c0f9fa2a6a3a2237c1f3590328b7033da34 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Wed, 24 Sep 2025 01:47:29 -0500 Subject: [PATCH] fix: Center the main window on first run. (#13003) Signed-off-by: fufesou --- flutter/lib/common.dart | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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) {