Skip to content

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

fix: restore window, on connection (#8129)

fufesou1efce5122222
diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart
index 1c7f31e4f..a13fabace 100644
--- a/flutter/lib/common.dart
+++ b/flutter/lib/common.dart
@@ -1567,8 +1567,7 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
late Offset position;
late Size sz;
late bool isMaximized;
- bool isFullscreen = stateGlobal.fullscreen.isTrue ||
- (isMacOS && stateGlobal.closeOnFullscreen == true);
+ bool isFullscreen = stateGlobal.fullscreen.isTrue;
setPreFrame() {
final pos = bind.getLocalFlutterOption(k: windowFramePrefix + type.name);
var lpos = LastWindowPosition.loadFromString(pos);
@@ -1890,7 +1889,6 @@ Future<bool> restoreWindowPosition(WindowType type,
}
if (lpos.isFullscreen == true) {
if (!isMacOS) {
- stateGlobal.setFullscreen(false);
await restoreFrame();
}
// An duration is needed to avoid the window being restored after fullscreen.
@@ -2906,10 +2904,10 @@ openMonitorInNewTabOrWindow(int i, String peerId, PeerInfo pi,
setNewConnectWindowFrame(int windowId, String peerId, Rect? screenRect) async {
if (screenRect == null) {
- restoreWindowPosition(WindowType.RemoteDesktop,
+ await restoreWindowPosition(WindowType.RemoteDesktop,
windowId: windowId, peerId: peerId);
} else {
- tryMoveToScreenAndSetFullscreen(screenRect);
+ await tryMoveToScreenAndSetFullscreen(screenRect);
}
}
diff --git a/flutter/lib/desktop/pages/remote_tab_page.dart b/flutter/lib/desktop/pages/remote_tab_page.dart
index 624403cfe..4affd7b07 100644
--- a/flutter/lib/desktop/pages/remote_tab_page.dart
+++ b/flutter/lib/desktop/pages/remote_tab_page.dart
@@ -350,15 +350,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
void onRemoveId(String id) async {
if (tabController.state.value.tabs.isEmpty) {
- if (stateGlobal.fullscreen.isTrue) {
- if (isLinux) {
- // If the window is left fullscreen and then reuse, the frame state will be incorrect when exit fullscreen the next time.
- // State `fullscreen -> hide -> show -> exit fullscreen`, then the window will be maximized and overlapped.
- // No idea how the strange state comes, just a **workaround**.
- await WindowController.fromWindowId(windowId()).setFullscreen(false);
- }
- stateGlobal.setFullscreen(false, procWnd: false);
- }
// Keep calling until the window status is hidden.
//
// Workaround for Windows:
@@ -424,16 +415,16 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
final display = args['display'];
final displays = args['displays'];
final screenRect = parseParamScreenRect(args);
- windowOnTop(windowId());
- setNewConnectWindowFrame(windowId(), id!, screenRect);
- if (tabController.length == 0) {
- // Show the hidden window.
- if (isMacOS && stateGlobal.closeOnFullscreen == true) {
- stateGlobal.setFullscreen(true);
+ Future.delayed(Duration.zero, () async {
+ if (stateGlobal.fullscreen.isTrue) {
+ await WindowController.fromWindowId(windowId()).setFullscreen(false);
+ stateGlobal.setFullscreen(false, procWnd: false);
}
- // Reset the state
- stateGlobal.closeOnFullscreen = null;
- }
+ await setNewConnectWindowFrame(windowId(), id!, screenRect);
+ Future.delayed(Duration(milliseconds: isWindows ? 100 : 0), () async {
+ await windowOnTop(windowId());
+ });
+ });
ConnectionTypeState.init(id);
_toolbarState.setShow(
bind.mainGetUserDefaultOption(key: kOptionCollapseToolbar) != 'Y');
diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart
index e89d50c30..27bae1a29 100644
--- a/flutter/lib/desktop/widgets/tabbar_widget.dart
+++ b/flutter/lib/desktop/widgets/tabbar_widget.dart
@@ -641,14 +641,12 @@ class WindowActionPanelState extends State<WindowActionPanel>
}
// macOS specific workaround, the window is not hiding when in fullscreen.
if (isMacOS && await windowManager.isFullScreen()) {
- stateGlobal.closeOnFullscreen ??= true;
await windowManager.setFullScreen(false);
await macOSWindowClose(
() async => await windowManager.isFullScreen(),
mainWindowClose,
);
} else {
- stateGlobal.closeOnFullscreen ??= false;
await mainWindowClose();
}
} else {
@@ -660,7 +658,6 @@ class WindowActionPanelState extends State<WindowActionPanel>
if (await widget.onClose?.call() ?? true) {
if (await controller.isFullScreen()) {
- stateGlobal.closeOnFullscreen ??= true;
await controller.setFullscreen(false);
stateGlobal.setFullscreen(false, procWnd: false);
await macOSWindowClose(
@@ -668,7 +665,6 @@ class WindowActionPanelState extends State<WindowActionPanel>
() async => await notMainWindowClose(controller),
);
} else {
- stateGlobal.closeOnFullscreen ??= false;
await notMainWindowClose(controller);
}
}
diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart
index a885eae8f..3c514aaaa 100644
--- a/flutter/lib/models/state_model.dart
+++ b/flutter/lib/models/state_model.dart
@@ -18,8 +18,6 @@ class StateGlobal {
final RxDouble _windowBorderWidth = RxDouble(kWindowBorderWidth);
final RxBool showRemoteToolBar = false.obs;
final svcStatus = SvcStatus.notReady.obs;
- // Only used for macOS
- bool? closeOnFullscreen;
final RxBool isFocused = false.obs;
String _inputSource = '';
diff --git a/flutter/lib/utils/multi_window_manager.dart b/flutter/lib/utils/multi_window_manager.dart
index 5aa59ee6a..f07db39aa 100644
--- a/flutter/lib/utils/multi_window_manager.dart
+++ b/flutter/lib/utils/multi_window_manager.dart
@@ -174,7 +174,9 @@ class RustDeskMultiWindowManager {
windowId: windowId, peerId: remoteId);
}
await DesktopMultiWindow.invokeMethod(windowId, methodName, msg);
- WindowController.fromWindowId(windowId).show();
+ if (methodName != kWindowEventNewRemoteDesktop) {
+ WindowController.fromWindowId(windowId).show();
+ }
registerActiveWindow(windowId);
return MultiWindowCallResult(windowId, null);
}
diff --git a/flutter/lib/web/bridge.dart b/flutter/lib/web/bridge.dart
index 540867ec9..3439fb97e 100644
--- a/flutter/lib/web/bridge.dart
+++ b/flutter/lib/web/bridge.dart
@@ -203,12 +203,6 @@ class RustdeskImpl {
]));
}
- Future<String?> sessionGetFlutterOptionByPeerId(
- {required String id, required String k, dynamic hint}) {
- return Future(
- () => js.context.callMethod('getByName', ['option:flutter:peer', k]));
- }
-
int getNextTextureKey({dynamic hint}) {
return 0;
}
diff --git a/flutter/pubspec.lock b/flutter/pubspec.lock
index 2cd1c6169..517d04391 100644
--- a/flutter/pubspec.lock
+++ b/flutter/pubspec.lock
@@ -335,7 +335,7 @@ packages:
description:
path: "."
ref: HEAD
- resolved-ref: ef03db52a20a7899da135d694c071fa3866c8fb1
+ resolved-ref: 965b6ceba095b120c37c368abc2e4dbc8a71e09c
url: "https://github.com/rustdesk-org/rustdesk_desktop_multi_window"
source: git
version: "0.1.0"
diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs
index c3a4335bd..35c436f2b 100644
--- a/src/flutter_ffi.rs
+++ b/src/flutter_ffi.rs
@@ -278,15 +278,6 @@ pub fn session_set_flutter_option(session_id: SessionID, k: String, v: String) {
}
}
-// This function is only used for the default connection session.
-pub fn session_get_flutter_option_by_peer_id(id: String, k: String) -> Option<String> {
- if let Some(session) = sessions::get_session_by_peer_id(id, ConnType::DEFAULT_CONN) {
- Some(session.get_flutter_option(k))
- } else {
- None
- }
-}
-
pub fn get_next_texture_key() -> SyncReturn<i32> {
let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1;
SyncReturn(k)