From 4945605009a7b8f21b3c531e037c16cf487d942b Mon Sep 17 00:00:00 2001 From: open-trade Date: Wed, 9 Feb 2022 16:06:44 +0800 Subject: [PATCH] fix on cm (connectin not closed somehow) and refactor isEnterKey --- src/server/connection.rs | 7 ++++++- src/ui/cm.css | 18 ++++++++++++++++-- src/ui/cm.rs | 4 ++++ src/ui/cm.tis | 21 +++++++++++---------- src/ui/common.tis | 12 ++++++++---- src/ui/file_transfer.tis | 3 +-- src/ui/grid.tis | 3 +-- src/ui/index.tis | 4 +--- src/ui/msgbox.tis | 4 +--- 9 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/server/connection.rs b/src/server/connection.rs index cb063d49d..0e899ec1c 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -335,6 +335,7 @@ impl Connection { let _ = crate::platform::block_input(false); crate::platform::toggle_blank_screen(false); + log::info!("#{} connection loop exited", id); } fn handle_input(receiver: std_mpsc::Receiver, tx: Sender) { @@ -933,7 +934,10 @@ impl Connection { } } Some(misc::Union::video_received(_)) => { - video_service::notify_video_frame_feched(self.inner.id, Some(Instant::now().into())); + video_service::notify_video_frame_feched( + self.inner.id, + Some(Instant::now().into()), + ); } _ => {} }, @@ -1039,6 +1043,7 @@ impl Connection { crate::platform::lock_screen(); super::video_service::switch_to_primary(); } + self.tx_to_cm.send(ipc::Data::Close).ok(); self.port_forward_socket.take(); } diff --git a/src/ui/cm.css b/src/ui/cm.css index 45f02d116..59a745029 100644 --- a/src/ui/cm.css +++ b/src/ui/cm.css @@ -18,6 +18,7 @@ div.left-panel { div.chaticon svg { size: 24px; margin: 4px; + opacity: 0.66; } div.chaticon { @@ -25,10 +26,11 @@ div.chaticon { right: 0; top: 0; size: 32px; + background-color: color(gray-bg); } -div.chaticon.active { - opacity: 0.5; +div.chaticon:hover svg { + opacity: 1; } div.chaticon:active { @@ -209,6 +211,7 @@ div.tab-arrows { position: absolute; right: 2px; font-weight: bold; + background: white; } div.tab-arrows span { @@ -216,4 +219,15 @@ div.tab-arrows span { height: *; margin: 0; padding: 6px 2px; + line-height: 20px; + opacity: 0.66; } + +div.tab-arrows span:hover { + opacity: 1; +} + +div.tab-arrows span:active { + opacity: 1; + background-color: #ddd; +} \ No newline at end of file diff --git a/src/ui/cm.rs b/src/ui/cm.rs index 340196ada..32f7fc6d1 100644 --- a/src/ui/cm.rs +++ b/src/ui/cm.rs @@ -349,6 +349,10 @@ async fn start_ipc(cm: ConnectionManager) { conn_id = id; cm.add_connection(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, tx.clone()); } + Data::Close => { + log::info!("cm ipc connection closed from connection request"); + break; + } _ => { cm.handle_data(conn_id, data, &mut write_jobs, &mut stream).await; } diff --git a/src/ui/cm.tis b/src/ui/cm.tis index 71a8e39a6..8fdb3f17e 100644 --- a/src/ui/cm.tis +++ b/src/ui/cm.tis @@ -22,7 +22,6 @@ class Body: Reactor.Component var callback = function(msg) { me.sendMsg(msg); }; - self.timer(1ms, adaptSize); var right_style = show_chat ? "" : "display: none"; return
@@ -153,8 +152,8 @@ class Header: Reactor.Component {tabs}
- < - > + < + >
; } @@ -181,13 +180,13 @@ class Header: Reactor.Component this.update_cur(idx); } - event click $(span.left-arrow) { + event click $(span#left-arrow) { var cur = body.cur; if (cur == 0) return; this.update_cur(cur - 1); } - event click $(span.right-arrow) { + event click $(span#right-arrow) { var cur = body.cur; if (cur == connections.length - 1) return; this.update_cur(cur + 1); @@ -205,7 +204,7 @@ if (is_osx) { event click $(div.chaticon) { checkClickTime(function() { show_chat = !show_chat; - adaptSize(); + adaptSizeForChat(); }); } @@ -213,12 +212,10 @@ function checkClickTime(callback) { callback(); } -function adaptSize() { +function adaptSizeForChat() { $(div.right-panel).style.set { display: show_chat ? "block" : "none", }; - var el = $(div.chaticon); - if (el) el.attributes.toggleClass("active", show_chat); var (x, y, w, h) = view.box(#rectw, #border, #screen); if (show_chat && w < 600) { view.move(x - (600 - w), y, 600, h); @@ -298,7 +295,11 @@ handler.newMessage = function(id, text) { if (!conn) return; conn.msgs.push({name: conn.name, text: text, time: getNowStr()}); bring_to_top(idx); - if (idx == body.cur) show_chat = true; + if (idx == body.cur) { + var shouldAdapt = !show_chat; + show_chat = true; + if (shouldAdapt) adaptSizeForChat(); + } conn.unreaded += 1; update(); } diff --git a/src/ui/common.tis b/src/ui/common.tis index 7075e9ca3..46fb1f7db 100644 --- a/src/ui/common.tis +++ b/src/ui/common.tis @@ -10,6 +10,11 @@ var is_file_transfer; var is_xfce = false; try { is_xfce = handler.is_xfce(); } catch(e) {} +function isEnterKey(evt) { + return (evt.keyCode == Event.VK_ENTER || + (is_osx && evt.keyCode == 0x4C) || + (is_linux && evt.keyCode == 65421)); +} function translate(name) { try { @@ -195,10 +200,9 @@ class ChatBox: Reactor.Component { event keydown $(input) (evt) { if (!evt.shortcutKey) { - if (evt.keyCode == Event.VK_ENTER || - (view.mediaVar("platform") == "OSX" && evt.keyCode == 0x4C)) { - this.send(); - } + if (isEnterKey(evt)) { + this.send(); + } } } diff --git a/src/ui/file_transfer.tis b/src/ui/file_transfer.tis index c5d500e15..0223e6d87 100644 --- a/src/ui/file_transfer.tis +++ b/src/ui/file_transfer.tis @@ -510,8 +510,7 @@ class FolderView : Reactor.Component { } event keydown $(.select-dir) (evt, me) { - if (evt.keyCode == Event.VK_ENTER || - (view.mediaVar("platform") == "OSX" && evt.keyCode == 0x4C)) { + if (isEnterKey(evt)) { this.goto(me.value, true); } } diff --git a/src/ui/grid.tis b/src/ui/grid.tis index 68aa68e49..82d385746 100644 --- a/src/ui/grid.tis +++ b/src/ui/grid.tis @@ -250,8 +250,7 @@ class Grid: Behavior { idx += 1; } } - if (evt.keyCode == Event.VK_ENTER || - (view.mediaVar("platform") == "OSX" && evt.keyCode == 0x4C)) { + if (isEnterKey(evt)) { this.onRowDoubleClick(this.getCurrentRow()); } return false; diff --git a/src/ui/index.tis b/src/ui/index.tis index acf8dae00..8c2fb061d 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -665,9 +665,7 @@ event keydown (evt) { return; } if (!evt.shortcutKey) { - if (evt.keyCode == Event.VK_ENTER || - (is_osx && evt.keyCode == 0x4C) || - (is_linux && evt.keyCode == 65421)) { + if (isEnterKey(evt)) { var el = $(button#connect); view.focus = el; el.sendEvent("click"); diff --git a/src/ui/msgbox.tis b/src/ui/msgbox.tis index 1da5700b0..e1c2d8e27 100644 --- a/src/ui/msgbox.tis +++ b/src/ui/msgbox.tis @@ -174,9 +174,7 @@ class MsgboxComponent: Reactor.Component { event keydown (evt) { if (!evt.shortcutKey) { - if (evt.keyCode == Event.VK_ENTER || - (is_osx && evt.keyCode == 0x4C) || - (is_linux && evt.keyCode == 65421)) { + if (isEnterKey(evt)) { this.submit(); } if (evt.keyCode == Event.VK_ESCAPE) {