refact, separate remote window, save session position
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
parent
773a74e2a9
commit
688ecef4cc
@ -1408,8 +1408,24 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
sz.width, sz.height, position.dx, position.dy, isMaximized);
|
sz.width, sz.height, position.dx, position.dy, isMaximized);
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}");
|
"Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}");
|
||||||
|
|
||||||
await bind.setLocalFlutterConfig(
|
await bind.setLocalFlutterConfig(
|
||||||
k: kWindowPrefix + type.name, v: pos.toString());
|
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 {
|
Future<Size> _adjustRestoreMainWindowSize(double? width, double? height) async {
|
||||||
@ -1499,7 +1515,7 @@ Future<Offset?> _adjustRestoreMainWindowOffset(
|
|||||||
|
|
||||||
/// Restore window position and size on start
|
/// Restore window position and size on start
|
||||||
/// Note that windowId must be provided if it's subwindow
|
/// 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
|
if (bind
|
||||||
.mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION")
|
.mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION")
|
||||||
.isNotEmpty) {
|
.isNotEmpty) {
|
||||||
@ -1508,8 +1524,16 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
|
|||||||
if (type != WindowType.Main && windowId == null) {
|
if (type != WindowType.Main && windowId == null) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"Error: windowId cannot be null when saving positions for sub window");
|
"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);
|
var lpos = LastWindowPosition.loadFromString(pos);
|
||||||
if (lpos == null) {
|
if (lpos == null) {
|
||||||
debugPrint("no window position saved, ignoring position restoration");
|
debugPrint("no window position saved, ignoring position restoration");
|
||||||
|
@ -36,6 +36,7 @@ const String kWindowEventNewRemoteDesktop = "new_remote_desktop";
|
|||||||
const String kWindowEventNewFileTransfer = "new_file_transfer";
|
const String kWindowEventNewFileTransfer = "new_file_transfer";
|
||||||
const String kWindowEventNewPortForward = "new_port_forward";
|
const String kWindowEventNewPortForward = "new_port_forward";
|
||||||
const String kWindowEventActiveSession = "active_session";
|
const String kWindowEventActiveSession = "active_session";
|
||||||
|
const String kWindowEventGetRemoteList = "get_remote_list";
|
||||||
|
|
||||||
const String kOptionSeparateRemoteWindow = "enable-separate-remote-window";
|
const String kOptionSeparateRemoteWindow = "enable-separate-remote-window";
|
||||||
|
|
||||||
|
@ -131,11 +131,22 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
windowOnTop(windowId());
|
windowOnTop(windowId());
|
||||||
}
|
}
|
||||||
return jumpOk;
|
return jumpOk;
|
||||||
|
} else if (call.method == kWindowEventGetRemoteList) {
|
||||||
|
return tabController.state.value.tabs
|
||||||
|
.map((e) => e.key)
|
||||||
|
.toList()
|
||||||
|
.join(',');
|
||||||
}
|
}
|
||||||
_update_remote_count();
|
_update_remote_count();
|
||||||
});
|
});
|
||||||
Future.delayed(Duration.zero, () {
|
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,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ void runMultiWindow(
|
|||||||
switch (appType) {
|
switch (appType) {
|
||||||
case kAppTypeDesktopRemote:
|
case kAppTypeDesktopRemote:
|
||||||
await restoreWindowPosition(WindowType.RemoteDesktop,
|
await restoreWindowPosition(WindowType.RemoteDesktop,
|
||||||
windowId: kWindowId!);
|
windowId: kWindowId!, peerId: argument['id'] as String?);
|
||||||
break;
|
break;
|
||||||
case kAppTypeDesktopFileTransfer:
|
case kAppTypeDesktopFileTransfer:
|
||||||
await restoreWindowPosition(WindowType.FileTransfer,
|
await restoreWindowPosition(WindowType.FileTransfer,
|
||||||
|
@ -70,7 +70,7 @@ class RustDeskMultiWindowManager {
|
|||||||
newSessionWindow() async {
|
newSessionWindow() async {
|
||||||
final windowController = await DesktopMultiWindow.createWindow(msg);
|
final windowController = await DesktopMultiWindow.createWindow(msg);
|
||||||
windowController
|
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()
|
..center()
|
||||||
..setTitle(getWindowNameWithId(
|
..setTitle(getWindowNameWithId(
|
||||||
remoteId,
|
remoteId,
|
||||||
|
@ -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> {
|
pub fn get_next_texture_key() -> SyncReturn<i32> {
|
||||||
let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1;
|
let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1;
|
||||||
SyncReturn(k)
|
SyncReturn(k)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user