Skip to content

Commit

Permalink
fix: restore window, on connection (#8129)
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <linlong1266@gmail.com>
  • Loading branch information
fufesou committed May 23, 2024
1 parent 7da09f6 commit 1efce51
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 46 deletions.
8 changes: 3 additions & 5 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand Down
27 changes: 9 additions & 18 deletions flutter/lib/desktop/pages/remote_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 0 additions & 4 deletions flutter/lib/desktop/widgets/tabbar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -660,15 +658,13 @@ 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(
() async => await controller.isFullScreen(),
() async => await notMainWindowClose(controller),
);
} else {
stateGlobal.closeOnFullscreen ??= false;
await notMainWindowClose(controller);
}
}
Expand Down
2 changes: 0 additions & 2 deletions flutter/lib/models/state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
4 changes: 3 additions & 1 deletion flutter/lib/utils/multi_window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions flutter/lib/web/bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions src/flutter_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1efce51

Please sign in to comment.