refactor windows specific session (#7170)

1. Modify the process to have the control side lead the session switching: After the control side sends a `LoginRequest`, the controlled side will add all session information and the current session ID in the `LoginResponse`. Upon receiving the `LoginResponse`, the control side will check if the current session ID matches the ID in the `LoginConfigHandler`. If they match, the control side will send the current session ID. If they don't match, a session selection dialog will pop up, the selected session id will be sent. Upon receiving this message, the controlled side will restart if different or sub service if same .
2. Always show physical console session on the top
3. Show running session and distinguish sessions with the same name
4. Not sub service until correct session id is ensured
5. Fix switch sides not work for multisession session
6. Remove all session string join/split except get_available_sessions in
   windows.rs
7. Fix prelogin, when share rdp is enabled and there is a rdp session,
   the console is in login screen, get_active_username will be the rdp's
   username and prelogin will be false, cm can't be created an that
   causes disconnection in a loop
8. Rename all user session to windows session

Known issue:
1. Use current process session id for `run_as_user`, sahil says it can
   be wrong but I didn't reproduce.
2. Have not change tray process to current session
3. File transfer doesn't update home directory when session changed
4. When it's in login screen, remote file directory is empty, because cm
   have not start up

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2024-02-18 22:08:25 +08:00
committed by GitHub
parent 4f1a4dc6a5
commit 0f44de7dc3
18 changed files with 376 additions and 416 deletions

View File

@@ -304,21 +304,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width=
return;
}
};
} else if (type === "multiple-sessions") {
var parts = content.split("-");
var ids = parts[0].split(",");
var names = parts[1].split(",");
var sessionData = [];
for (var i = 0; i < ids.length; i++) {
sessionData.push({ id: ids[i], name: names[i] });
}
content = <MultipleSessionComponent sessions={sessionData} />;
callback = function () {
retryConnect();
return;
};
height += 50;
}
}
last_msgbox_tag = type + "-" + title + "-" + content + "-" + link;
$(#msgbox).content(<MsgboxComponent width={width} height={height} autoLogin={autoLogin} type={type} title={title} content={content} link={link} remember={remember} callback={callback} contentStyle={contentStyle} hasRetry={hasRetry} />);
}
@@ -353,7 +339,7 @@ handler.msgbox_retry = function(type, title, text, link, hasRetry) {
function retryConnect(cancelTimer=false) {
if (cancelTimer) self.timer(0, retryConnect);
if (!is_port_forward) connecting();
handler.reconnect(false, "");
handler.reconnect(false);
}
/******************** end of msgbox ****************************************/
@@ -474,19 +460,12 @@ function awake() {
class MultipleSessionComponent extends Reactor.Component {
this var sessions = [];
this var selectedSessionId = null;
this var sessionlength = 0;
this var messageText = translate("Please select the user you want to connect to");
function this(params) {
if (params && params.sessions) {
this.sessions = params.sessions;
this.selectedSessionId = params.sessions[0].id;
this.sessions.map(session => {
this.sessionlength += session.name.length;
});
}
handler.set_selected_user_session_id(this.selectedSessionId);
}
function render() {
@@ -494,15 +473,9 @@ class MultipleSessionComponent extends Reactor.Component {
<div .title>{this.messageText}</div>
<select>
{this.sessions.map(session =>
<option value={session.id}>{session.name}</option>
<option value={session.sid}>{session.name}</option>
)}
</select>
</div>;
}
event change {
var selectedSessionName = this.value.substr(this.messageText.length + this.sessionlength);
this.selectedSessionId = this.sessions.find(session => session.name == selectedSessionName).id;
handler.set_selected_user_session_id(this.selectedSessionId);
}
}

View File

@@ -527,8 +527,15 @@ handler.updateDisplays = function(v) {
}
}
handler.setMultipleUserSession = function(usid,uname) {
msgbox("multiple-sessions", translate("Multiple active user sessions found"), usid+"-"+uname, "", function(res) {});
handler.setMultipleWindowsSession = function(sessions) {
// It will be covered by other message box if the timer is not used,
self.timer(1000ms, function() {
msgbox("multiple-sessions-nocancel", translate("Multiple active user sessions found"), <MultipleSessionComponent sessions={sessions} />, "", function(res) {
if (res && res.sid) {
handler.set_selected_windows_session_id("" + res.sid);
}
}, 230);
});
}
function updatePrivacyMode() {

View File

@@ -312,6 +312,9 @@ class MsgboxComponent: Reactor.Component {
return;
}
}
if (this.type == "multiple-sessions-nocancel") {
values.sid = (this.$$(select))[0].value;
}
return values;
}

View File

@@ -259,14 +259,17 @@ impl InvokeUiSession for SciterHandler {
// Ignore for sciter version.
}
fn set_multiple_user_session(&self, sessions: Vec<hbb_common::message_proto::RdpUserSession>) {
let formatted_sessions: Vec<String> = sessions.iter()
.map(|session| format!("{}-{}", session.user_session_id, session.user_name))
.collect();
let u_sids: String = formatted_sessions.iter().map(|s| s.split("-").next().unwrap().to_string()).collect::<Vec<String>>().join(",");
let u_names:String = formatted_sessions.iter().map(|s| s.split("-").nth(1).unwrap().to_string()).collect::<Vec<String>>().join(",");
self.call("setMultipleUserSession", &make_args!(u_sids, u_names));
}
fn set_multiple_windows_session(&self, sessions: Vec<WindowsSession>) {
let mut v = Value::array(0);
let mut sessions = sessions;
for s in sessions.drain(..) {
let mut obj = Value::map();
obj.set_item("sid", s.sid.to_string());
obj.set_item("name", s.name);
v.push(obj);
}
self.call("setMultipleWindowsSession", &make_args!(v));
}
fn on_connected(&self, conn_type: ConnType) {
match conn_type {
@@ -355,7 +358,6 @@ impl sciter::EventHandler for SciterSession {
}
fn detached(&mut self, _root: HELEMENT) {
self.set_selected_user_session_id("".to_string());
*self.element.lock().unwrap() = None;
self.sender.write().unwrap().take().map(|sender| {
sender.send(Data::Close).ok();
@@ -386,7 +388,7 @@ impl sciter::EventHandler for SciterSession {
let site = AssetPtr::adopt(ptr as *mut video_destination);
log::debug!("[video] start video");
*VIDEO.lock().unwrap() = Some(site);
self.reconnect(false, "".to_string());
self.reconnect(false);
}
}
BEHAVIOR_EVENTS::VIDEO_INITIALIZED => {
@@ -436,7 +438,7 @@ impl sciter::EventHandler for SciterSession {
fn transfer_file();
fn tunnel();
fn lock_screen();
fn reconnect(bool, String);
fn reconnect(bool);
fn get_chatbox();
fn get_icon();
fn get_home_dir();
@@ -487,7 +489,7 @@ impl sciter::EventHandler for SciterSession {
fn request_voice_call();
fn close_voice_call();
fn version_cmp(String, String);
fn set_selected_user_session_id(String);
fn set_selected_windows_session_id(String);
}
}
@@ -591,8 +593,8 @@ impl SciterSession {
log::info!("size saved");
}
fn set_selected_user_session_id(&mut self, u_sid: String) {
self.lc.write().unwrap().selected_user_session_id = u_sid;
fn set_selected_windows_session_id(&mut self, u_sid: String) {
self.send_selected_session_id(u_sid);
}
fn get_port_forwards(&mut self) -> Value {