fix on cm (connectin not closed somehow) and refactor isEnterKey

This commit is contained in:
open-trade 2022-02-09 16:06:44 +08:00
parent d313fa92e1
commit 4945605009
9 changed files with 49 additions and 27 deletions

View File

@ -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<MessageInput>, 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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 <div .content>
<div .left-panel>
@ -153,8 +152,8 @@ class Header: Reactor.Component
{tabs}
</div>
<div .tab-arrows>
<span .left-arrow>&lt;</span>
<span .right-arrow>&gt;</span>
<span #left-arrow>&lt;</span>
<span #right-arrow>&gt;</span>
</div>
</div>;
}
@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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");

View File

@ -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) {