refact, separate remote window, save session position

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-08-02 22:02:18 +08:00
parent 773a74e2a9
commit 688ecef4cc
6 changed files with 60 additions and 5 deletions

View File

@ -1408,8 +1408,24 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
sz.width, sz.height, position.dx, position.dy, isMaximized);
debugPrint(
"Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}");
await bind.setLocalFlutterConfig(
k: kWindowPrefix + type.name, v: pos.toString());
if (type == WindowType.RemoteDesktop && windowId != null) {
await _saveSessionWindowPosition(windowId, pos);
}
}
Future _saveSessionWindowPosition(int windowId, LastWindowPosition pos) async {
final remoteList = await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventGetRemoteList, null);
if (remoteList != null) {
for (final peerId in remoteList.split(',')) {
bind.sessionSetFlutterConfigByPeerId(
id: peerId, k: kWindowPrefix, v: pos.toString());
}
}
}
Future<Size> _adjustRestoreMainWindowSize(double? width, double? height) async {
@ -1499,7 +1515,7 @@ Future<Offset?> _adjustRestoreMainWindowOffset(
/// Restore window position and size on start
/// Note that windowId must be provided if it's subwindow
Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
Future<bool> restoreWindowPosition(WindowType type, {int? windowId, String? peerId}) async {
if (bind
.mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION")
.isNotEmpty) {
@ -1508,8 +1524,16 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
if (type != WindowType.Main && windowId == null) {
debugPrint(
"Error: windowId cannot be null when saving positions for sub window");
return false;
}
final pos = bind.getLocalFlutterConfig(k: kWindowPrefix + type.name);
String? pos;
if (type == WindowType.RemoteDesktop && windowId != null && peerId != null) {
pos = await bind.sessionGetFlutterConfigByPeerId(id: peerId, k: kWindowPrefix);
}
pos ??= bind.getLocalFlutterConfig(k: kWindowPrefix + type.name);
var lpos = LastWindowPosition.loadFromString(pos);
if (lpos == null) {
debugPrint("no window position saved, ignoring position restoration");

View File

@ -36,6 +36,7 @@ const String kWindowEventNewRemoteDesktop = "new_remote_desktop";
const String kWindowEventNewFileTransfer = "new_file_transfer";
const String kWindowEventNewPortForward = "new_port_forward";
const String kWindowEventActiveSession = "active_session";
const String kWindowEventGetRemoteList = "get_remote_list";
const String kOptionSeparateRemoteWindow = "enable-separate-remote-window";

View File

@ -131,11 +131,22 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
windowOnTop(windowId());
}
return jumpOk;
} else if (call.method == kWindowEventGetRemoteList) {
return tabController.state.value.tabs
.map((e) => e.key)
.toList()
.join(',');
}
_update_remote_count();
});
Future.delayed(Duration.zero, () {
restoreWindowPosition(WindowType.RemoteDesktop, windowId: windowId());
restoreWindowPosition(
WindowType.RemoteDesktop,
windowId: windowId(),
peerId: tabController.state.value.tabs.isEmpty
? null
: tabController.state.value.tabs[0].key,
);
});
}

View File

@ -197,7 +197,7 @@ void runMultiWindow(
switch (appType) {
case kAppTypeDesktopRemote:
await restoreWindowPosition(WindowType.RemoteDesktop,
windowId: kWindowId!);
windowId: kWindowId!, peerId: argument['id'] as String?);
break;
case kAppTypeDesktopFileTransfer:
await restoreWindowPosition(WindowType.FileTransfer,

View File

@ -70,7 +70,7 @@ class RustDeskMultiWindowManager {
newSessionWindow() async {
final windowController = await DesktopMultiWindow.createWindow(msg);
windowController
..setFrame(const Offset(0, 0) & const Size(1280, 720))
..setFrame(const Offset(0, 0) & Size(1280 + windowController.windowId * 20, 720 + windowController.windowId * 20))
..center()
..setTitle(getWindowNameWithId(
remoteId,

View File

@ -205,6 +205,25 @@ pub fn session_set_flutter_config(session_id: SessionID, k: String, v: String) {
}
}
pub fn session_get_flutter_config_by_peer_id(id: String, k: String) -> Option<String> {
if let Some((_, session)) = SESSIONS.read().unwrap().iter().find(|(_, s)| s.id == id) {
Some(session.get_flutter_config(k))
} else {
None
}
}
pub fn session_set_flutter_config_by_peer_id(id: String, k: String, v: String) {
if let Some((_, session)) = SESSIONS
.write()
.unwrap()
.iter_mut()
.find(|(_, s)| s.id == id)
{
session.save_flutter_config(k, v);
}
}
pub fn get_next_texture_key() -> SyncReturn<i32> {
let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1;
SyncReturn(k)