Refact/android input changed notify clients (#8494)

* refact: android, input control changed, notify clients

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: android init input perm

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-06-27 13:05:45 +08:00 committed by GitHub
parent 9c7d4ef1f7
commit b047730830
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 0 deletions

View File

@ -177,6 +177,11 @@ class ServerModel with ChangeNotifier {
await timerCallback();
});
}
// Initial keyboard status is off on mobile
if (isMobile) {
bind.mainSetOption(key: kOptionEnableKeyboard, value: 'N');
}
}
/// 1. check android permission

View File

@ -786,6 +786,13 @@ pub fn main_show_option(_key: String) -> SyncReturn<bool> {
}
pub fn main_set_option(key: String, value: String) {
#[cfg(target_os = "android")]
if key.eq(config::keys::OPTION_ENABLE_KEYBOARD) {
crate::ui_cm_interface::notify_input_control(config::option2bool(
config::keys::OPTION_ENABLE_KEYBOARD,
&value,
));
}
if key.eq("custom-rendezvous-server") {
set_option(key, value.clone());
#[cfg(target_os = "android")]

View File

@ -189,6 +189,8 @@ pub enum Data {
MouseMoveTime(i64),
Authorize,
Close,
#[cfg(target_os = "android")]
InputControl(bool),
#[cfg(windows)]
SAS,
UserSid(Option<u32>),

View File

@ -400,6 +400,9 @@ impl Connection {
}
#[cfg(target_os = "android")]
start_channel(rx_to_cm, tx_from_cm);
#[cfg(target_os = "android")]
conn.send_permission(Permission::Keyboard, conn.keyboard).await;
#[cfg(not(target_os = "android"))]
if !conn.keyboard {
conn.send_permission(Permission::Keyboard, false).await;
}
@ -457,6 +460,11 @@ impl Connection {
conn.on_close("connection manager", true).await;
break;
}
#[cfg(target_os = "android")]
ipc::Data::InputControl(v) => {
conn.keyboard = v;
conn.send_permission(Permission::Keyboard, v).await;
}
ipc::Data::CmErr(e) => {
if e != "expected" {
// cm closed before connection

View File

@ -279,6 +279,15 @@ pub fn close(id: i32) {
};
}
#[inline]
#[cfg(target_os = "android")]
pub fn notify_input_control(v: bool) {
for (_, mut client) in CLIENTS.write().unwrap().iter_mut() {
client.keyboard = v;
allow_err!(client.tx.send(Data::InputControl(v)));
}
}
#[inline]
pub fn remove(id: i32) {
CLIENTS.write().unwrap().remove(&id);