mobile build

This commit is contained in:
csf 2022-09-05 20:05:23 +08:00
parent 7eeb0f7335
commit bd733bc108
5 changed files with 30 additions and 15 deletions

View File

@ -22,9 +22,9 @@ pub trait FileManager: Interface {
#[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
fn read_dir(&self, path: &str, include_hidden: bool) -> String {
use crate::common::make_fd_to_json;
use crate::flutter::make_fd_to_json;
match fs::read_dir(&fs::get_path(path), include_hidden) {
Ok(fd) => make_fd_to_json(fd),
Ok(fd) => make_fd_to_json(fd.id, fd.path, &fd.entries),
Err(_) => "".into(),
}
}

View File

@ -340,6 +340,7 @@ pub fn session_start_(id: &str, event_stream: StreamSink<EventToUI>) -> ResultTy
pub mod connection_manager {
use std::collections::HashMap;
use hbb_common::log;
#[cfg(any(target_os = "android"))]
use scrap::android::call_main_service_set_by_name;
@ -410,9 +411,18 @@ pub mod connection_manager {
}
#[cfg(target_os = "android")]
pub fn start_channel(rx: UnboundedReceiver<Data>, tx: UnboundedSender<Data>) {
use hbb_common::tokio::sync::mpsc::{UnboundedReceiver,UnboundedSender};
#[cfg(target_os = "android")]
pub fn start_channel(
rx: UnboundedReceiver<crate::ipc::Data>,
tx: UnboundedSender<crate::ipc::Data>,
) {
use crate::ui_cm_interface::start_listen;
std::thread::spawn(move || start_listen(rx, tx));
let cm = crate::ui_cm_interface::ConnectionManager {
ui_handler: FlutterHandler {},
};
std::thread::spawn(move || start_listen(cm, rx, tx));
}
}

View File

@ -754,7 +754,7 @@ pub fn main_set_home_dir(home: String) {
pub fn main_stop_service() {
#[cfg(target_os = "android")]
{
Config::set_option("stop-service".into(), "Y".into());
config::Config::set_option("stop-service".into(), "Y".into());
crate::rendezvous_mediator::RendezvousMediator::restart();
}
}
@ -762,7 +762,7 @@ pub fn main_stop_service() {
pub fn main_start_service() {
#[cfg(target_os = "android")]
{
Config::set_option("stop-service".into(), "".into());
config::Config::set_option("stop-service".into(), "".into());
crate::rendezvous_mediator::RendezvousMediator::restart();
}
#[cfg(not(target_os = "android"))]

View File

@ -114,13 +114,17 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
CLIENTS.write().unwrap().remove(&id);
#[cfg(any(target_os = "android"))]
if clients
if CLIENTS
.read()
.unwrap()
.iter()
.filter(|(_k, v)| !v.is_file_transfer)
.next()
.is_none()
{
if let Err(e) = call_main_service_set_by_name("stop_capture", None, None) {
if let Err(e) =
scrap::android::call_main_service_set_by_name("stop_capture", None, None)
{
log::debug!("stop_capture err:{}", e);
}
}
@ -312,7 +316,7 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
#[cfg(target_os = "android")]
#[tokio::main(flavor = "current_thread")]
pub async fn start_listen(mut rx: UnboundedReceiver<Data>, tx: UnboundedSender<Data>) {
pub async fn start_listen<T: InvokeUiCM>(cm: ConnectionManager<T>, mut rx: mpsc::UnboundedReceiver<Data>, tx: mpsc::UnboundedSender<Data>) {
let mut current_id = 0;
let mut write_jobs: Vec<fs::TransferJob> = Vec::new();
loop {
@ -332,7 +336,7 @@ pub async fn start_listen(mut rx: UnboundedReceiver<Data>, tx: UnboundedSender<D
..
}) => {
current_id = id;
on_login(
cm.add_connection(
id,
is_file_transfer,
port_forward,
@ -348,7 +352,7 @@ pub async fn start_listen(mut rx: UnboundedReceiver<Data>, tx: UnboundedSender<D
);
}
Some(Data::ChatMessage { text }) => {
cm.new_message(conn_id, text);
cm.new_message(current_id, text);
}
Some(Data::FS(fs)) => {
handle_fs(fs, &mut write_jobs, &tx).await;
@ -362,7 +366,7 @@ pub async fn start_listen(mut rx: UnboundedReceiver<Data>, tx: UnboundedSender<D
_ => {}
}
}
remove_connection(current_id);
cm.remove_connection(current_id);
}
async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &UnboundedSender<Data>) {

View File

@ -372,10 +372,11 @@ pub fn get_mouse_time() -> f64 {
return res;
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn check_mouse_time() {
let sender = SENDER.lock().unwrap();
allow_err!(sender.send(ipc::Data::MouseMoveTime(0)));
#[cfg(not(any(target_os = "android", target_os = "ios")))]{
let sender = SENDER.lock().unwrap();
allow_err!(sender.send(ipc::Data::MouseMoveTime(0)));
}
}
pub fn get_connect_status() -> Status {