win_fix_multi_tab: win clipboard refactor

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-10-27 10:56:14 +08:00
parent 702c81cafe
commit db99eccbe0
10 changed files with 66 additions and 27 deletions

View File

@ -43,7 +43,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
void initState() { void initState() {
super.initState(); super.initState();
tabController.onRemove = (_, id) => onRemoveId(id); tabController.onRemoved = (_, id) => onRemoveId(id);
rustDeskWinManager.setMethodHandler((call, fromWindowId) async { rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print( print(

View File

@ -46,7 +46,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
void initState() { void initState() {
super.initState(); super.initState();
tabController.onRemove = (_, id) => onRemoveId(id); tabController.onRemoved = (_, id) => onRemoveId(id);
rustDeskWinManager.setMethodHandler((call, fromWindowId) async { rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
debugPrint( debugPrint(

View File

@ -59,11 +59,12 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
void initState() { void initState() {
super.initState(); super.initState();
tabController.onRemove = (_, id) => onRemoveId(id); tabController.onRemoved = (_, id) => onRemoveId(id);
tabController.onSelected = (_, id) => onSelectId(id);
rustDeskWinManager.setMethodHandler((call, fromWindowId) async { rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print( print(
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}"); "call ${call.method} with args ${call.arguments} from window $fromWindowId");
final RxBool fullscreen = Get.find(tag: 'fullscreen'); final RxBool fullscreen = Get.find(tag: 'fullscreen');
// for simplify, just replace connectionId // for simplify, just replace connectionId
@ -174,6 +175,10 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
_update_remote_count(); _update_remote_count();
} }
void onSelectId(String id) {
bind.setCurSessionId(id: id);
}
int windowId() { int windowId() {
return widget.params["windowId"]; return widget.params["windowId"];
} }

View File

@ -30,7 +30,7 @@ class _DesktopServerPageState extends State<DesktopServerPage>
void initState() { void initState() {
gFFI.ffiModel.updateEventListener(""); gFFI.ffiModel.updateEventListener("");
windowManager.addListener(this); windowManager.addListener(this);
tabController.onRemove = (_, id) => onRemoveId(id); tabController.onRemoved = (_, id) => onRemoveId(id);
super.initState(); super.initState();
} }
@ -99,7 +99,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
@override @override
void initState() { void initState() {
gFFI.serverModel.updateClientState(); gFFI.serverModel.updateClientState();
gFFI.serverModel.tabController.onSelected = (index) => gFFI.serverModel.tabController.onSelected = (index, _) =>
gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id); gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id);
super.initState(); super.initState();
} }

View File

@ -70,10 +70,11 @@ class DesktopTabController {
final DesktopTabType tabType; final DesktopTabType tabType;
/// index, key /// index, key
Function(int, String)? onRemove; Function(int, String)? onRemoved;
Function(int)? onSelected; Function(int, String)? onSelected;
DesktopTabController({required this.tabType}); DesktopTabController(
{required this.tabType, this.onRemoved, this.onSelected});
int get length => state.value.tabs.length; int get length => state.value.tabs.length;
@ -114,7 +115,7 @@ class DesktopTabController {
state.value.tabs.removeAt(index); state.value.tabs.removeAt(index);
state.value.scrollController.itemCount = state.value.tabs.length; state.value.scrollController.itemCount = state.value.tabs.length;
jumpTo(toIndex); jumpTo(toIndex);
onRemove?.call(index, key); onRemoved?.call(index, key);
} }
void jumpTo(int index) { void jumpTo(int index) {
@ -134,7 +135,8 @@ class DesktopTabController {
})); }));
}); });
if (state.value.tabs.length > index) { if (state.value.tabs.length > index) {
onSelected?.call(index); final key = state.value.tabs[index].key;
onSelected?.call(index, key);
} }
} }
@ -146,7 +148,7 @@ class DesktopTabController {
void closeBy(String? key) { void closeBy(String? key) {
if (!isDesktop) return; if (!isDesktop) return;
assert(onRemove != null); assert(onRemoved != null);
if (key == null) { if (key == null) {
if (state.value.selected < state.value.tabs.length) { if (state.value.selected < state.value.tabs.length) {
remove(state.value.selected); remove(state.value.selected);

View File

@ -78,8 +78,16 @@ lazy_static::lazy_static! {
static ref PROCESS_SIDE: RwLock<ProcessSide> = RwLock::new(ProcessSide::UnknownSide); static ref PROCESS_SIDE: RwLock<ProcessSide> = RwLock::new(ProcessSide::UnknownSide);
} }
#[inline] pub fn get_client_conn_id(peer_id: &str) -> Option<i32> {
pub fn get_rx_cliprdr_client<'a>( VEC_MSG_CHANNEL
.read()
.unwrap()
.iter()
.find(|x| x.peer_id == peer_id.to_owned())
.map(|x| x.conn_id)
}
pub fn get_rx_cliprdr_client(
peer_id: &str, peer_id: &str,
) -> (i32, Arc<TokioMutex<UnboundedReceiver<ClipbaordFile>>>) { ) -> (i32, Arc<TokioMutex<UnboundedReceiver<ClipbaordFile>>>) {
let mut lock = VEC_MSG_CHANNEL.write().unwrap(); let mut lock = VEC_MSG_CHANNEL.write().unwrap();
@ -102,10 +110,7 @@ pub fn get_rx_cliprdr_client<'a>(
} }
} }
#[inline] pub fn get_rx_cliprdr_server(conn_id: i32) -> Arc<TokioMutex<UnboundedReceiver<ClipbaordFile>>> {
pub fn get_rx_cliprdr_server<'a>(
conn_id: i32,
) -> Arc<TokioMutex<UnboundedReceiver<ClipbaordFile>>> {
let mut lock = VEC_MSG_CHANNEL.write().unwrap(); let mut lock = VEC_MSG_CHANNEL.write().unwrap();
match lock.iter().find(|x| x.conn_id == conn_id) { match lock.iter().find(|x| x.conn_id == conn_id) {
Some(msg_channel) => msg_channel.receiver.clone(), Some(msg_channel) => msg_channel.receiver.clone(),

View File

@ -1178,6 +1178,16 @@ impl<T: InvokeUiSession> Remote<T> {
#[cfg(windows)] #[cfg(windows)]
fn handle_cliprdr_msg(&self, clip: message_proto::Cliprdr) { fn handle_cliprdr_msg(&self, clip: message_proto::Cliprdr) {
if !self.handler.lc.read().unwrap().disable_clipboard { if !self.handler.lc.read().unwrap().disable_clipboard {
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
if let Some(message_proto::cliprdr::Union::FormatList(_)) = &clip.union {
if self.client_conn_id
!= clipboard::get_client_conn_id(&crate::flutter::get_cur_session_id())
.unwrap_or(0)
{
return;
}
}
if let Some(clip) = crate::clipboard_file::msg_2_clip(clip) { if let Some(clip) = crate::clipboard_file::msg_2_clip(clip) {
ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 { ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 {
clipboard::server_clip_file(context, self.client_conn_id, clip) clipboard::server_clip_file(context, self.client_conn_id, clip)

View File

@ -567,7 +567,7 @@ pub fn make_fd_flutter(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> S
} }
pub fn get_cur_session_id() -> String { pub fn get_cur_session_id() -> String {
*CUR_SESSION_ID.read().unwrap() CUR_SESSION_ID.read().unwrap().clone()
} }
pub fn set_cur_session_id(id: String) { pub fn set_cur_session_id(id: String) {

View File

@ -1052,6 +1052,10 @@ pub fn main_update_me() -> SyncReturn<bool> {
SyncReturn(true) SyncReturn(true)
} }
pub fn set_cur_session_id(id: String) {
super::flutter::set_cur_session_id(id)
}
pub fn install_show_run_without_install() -> SyncReturn<bool> { pub fn install_show_run_without_install() -> SyncReturn<bool> {
SyncReturn(show_run_without_install()) SyncReturn(show_run_without_install())
} }

View File

@ -259,7 +259,6 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
use hbb_common::config::LocalConfig; use hbb_common::config::LocalConfig;
// for tmp use, without real conn id // for tmp use, without real conn id
let conn_id_tmp = -1;
let mut write_jobs: Vec<fs::TransferJob> = Vec::new(); let mut write_jobs: Vec<fs::TransferJob> = Vec::new();
let mut close = true; let mut close = true;
@ -321,9 +320,8 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
log::info!("cm ipc connection disconnect"); log::info!("cm ipc connection disconnect");
break; break;
} }
Data::PrivacyModeState(_) => { Data::PrivacyModeState((id, _)) => {
self.conn_id = conn_id_tmp; cm_inner_send(id, data);
allow_err!(self.tx.send(data));
} }
Data::ClickTime(ms) => { Data::ClickTime(ms) => {
CLICK_TIME.store(ms, Ordering::SeqCst); CLICK_TIME.store(ms, Ordering::SeqCst);
@ -338,7 +336,6 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)] #[cfg(windows)]
{ {
let conn_id = self.conn_id; let conn_id = self.conn_id;
ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 { ContextSend::proc(|context: &mut Box<CliprdrClientContext>| -> u32 {
clipboard::server_clip_file(context, conn_id, _clip) clipboard::server_clip_file(context, conn_id, _clip)
}); });
@ -380,12 +377,10 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}, },
} }
} }
if self.conn_id != 0 && self.conn_id != conn_id_tmp {
self.cm.remove_connection(self.conn_id, close);
}
} }
async fn ipc_task(stream: Connection, cm: ConnectionManager<T>) { async fn ipc_task(stream: Connection, cm: ConnectionManager<T>) {
log::debug!("ipc task begin");
let (tx, rx) = mpsc::unbounded_channel::<Data>(); let (tx, rx) = mpsc::unbounded_channel::<Data>();
let mut task_runner = Self { let mut task_runner = Self {
stream, stream,
@ -401,6 +396,10 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
if task_runner.conn_id > 0 { if task_runner.conn_id > 0 {
task_runner.run().await; task_runner.run().await;
} }
if task_runner.conn_id > 0 {
task_runner.cm.remove_connection(task_runner.conn_id, close);
}
log::debug!("ipc task end");
} }
} }
@ -731,3 +730,17 @@ fn send_raw(msg: Message, tx: &UnboundedSender<Data>) {
err => allow_err!(err), err => allow_err!(err),
} }
} }
#[cfg(windows)]
fn cm_inner_send(id: i32, data: Data) {
let lock = CLIENTS.read().unwrap();
if id != 0 {
if let Some(s) = lock.get(&id) {
allow_err!(s.tx.send(data));
}
} else {
for s in lock.values() {
allow_err!(s.tx.send(data.clone()));
}
}
}