From 96d95fa08a60a8041908a10363bed02e494e005a Mon Sep 17 00:00:00 2001 From: dignow Date: Thu, 22 Jun 2023 23:31:46 +0800 Subject: [PATCH 01/11] fix user login state Signed-off-by: dignow --- flutter/lib/common/widgets/address_book.dart | 1 + .../lib/desktop/pages/connection_page.dart | 41 +-------- flutter/lib/main.dart | 1 + flutter/lib/mobile/pages/connection_page.dart | 3 + flutter/lib/models/ab_model.dart | 1 + flutter/lib/models/state_model.dart | 49 ++++++++++ libs/hbb_common/src/config.rs | 7 +- src/flutter_ffi.rs | 35 ++++--- src/ipc.rs | 16 ++-- src/server/connection.rs | 11 +++ src/ui.rs | 6 +- src/ui_interface.rs | 92 +++++++++++++++---- 12 files changed, 182 insertions(+), 81 deletions(-) diff --git a/flutter/lib/common/widgets/address_book.dart b/flutter/lib/common/widgets/address_book.dart index 08df6d4e5..9a516653b 100644 --- a/flutter/lib/common/widgets/address_book.dart +++ b/flutter/lib/common/widgets/address_book.dart @@ -30,6 +30,7 @@ class _AddressBookState extends State { @override Widget build(BuildContext context) => Obx(() { + debugPrint('REMOVE ME =========================== AddressBook ${gFFI.userModel.userName.value} ${gFFI.abModel.abLoading} ${gFFI.abModel.abError} ${gFFI.abModel.fromServer} ${isDesktop}'); if (gFFI.userModel.userName.value.isEmpty) { return Center( child: ElevatedButton( diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 91d6b6032..f37bb8d9f 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -1,7 +1,5 @@ // main window right pane -import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:auto_size_text/auto_size_text.dart'; @@ -9,7 +7,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_hbb/consts.dart'; import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart'; import 'package:flutter_hbb/models/state_model.dart'; -import 'package:flutter_hbb/models/user_model.dart'; import 'package:get/get.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:window_manager/window_manager.dart'; @@ -37,13 +34,10 @@ class _ConnectionPageState extends State /// Nested scroll controller final _scrollController = ScrollController(); - Timer? _updateTimer; - final RxBool _idInputFocused = false.obs; final FocusNode _idFocusNode = FocusNode(); var svcStopped = Get.find(tag: 'stop-service'); - var svcIsUsingPublicServer = true.obs; bool isWindowMinimized = false; @@ -60,9 +54,7 @@ class _ConnectionPageState extends State } }(); } - _updateTimer = periodic_immediate(Duration(seconds: 1), () async { - updateStatus(); - }); + stateGlobal.startSvcStatusTimer(); _idFocusNode.addListener(() { _idInputFocused.value = _idFocusNode.hasFocus; // select all to faciliate removing text, just following the behavior of address input of chrome @@ -75,7 +67,7 @@ class _ConnectionPageState extends State @override void dispose() { _idController.dispose(); - _updateTimer?.cancel(); + stateGlobal.cancelSvcStatusTimer(); windowManager.removeListener(this); super.dispose(); } @@ -290,7 +282,7 @@ class _ConnectionPageState extends State child: Offstage( offstage: !(!svcStopped.value && stateGlobal.svcStatus.value == SvcStatus.ready && - svcIsUsingPublicServer.value), + stateGlobal.svcIsUsingPublicServer.value), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -329,31 +321,4 @@ class _ConnectionPageState extends State } }); } - - updateStatus() async { - final status = - jsonDecode(await bind.mainGetConnectStatus()) as Map; - final statusNum = status['status_num'] as int; - final preStatus = stateGlobal.svcStatus.value; - if (statusNum == 0) { - stateGlobal.svcStatus.value = SvcStatus.connecting; - } else if (statusNum == -1) { - stateGlobal.svcStatus.value = SvcStatus.notReady; - } else if (statusNum == 1) { - stateGlobal.svcStatus.value = SvcStatus.ready; - if (preStatus != SvcStatus.ready) { - gFFI.userModel.refreshCurrentUser(); - } - } else { - stateGlobal.svcStatus.value = SvcStatus.notReady; - } - if (stateGlobal.svcStatus.value != SvcStatus.ready) { - gFFI.userModel.isAdmin.value = false; - gFFI.groupModel.reset(); - } - if (preStatus != stateGlobal.svcStatus.value) { - UserModel.updateOtherModels(); - } - svcIsUsingPublicServer.value = await bind.mainIsUsingPublicServer(); - } } diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 14534613a..eb4901686 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -151,6 +151,7 @@ void runMobileApp() async { await initEnv(kAppTypeMain); if (isAndroid) androidChannelInit(); platformFFI.syncAndroidServiceAppDirConfigPath(); + gFFI.userModel.refreshCurrentUser(); runApp(App()); } diff --git a/flutter/lib/mobile/pages/connection_page.dart b/flutter/lib/mobile/pages/connection_page.dart index 5a581f0c7..df4a85233 100644 --- a/flutter/lib/mobile/pages/connection_page.dart +++ b/flutter/lib/mobile/pages/connection_page.dart @@ -11,6 +11,7 @@ import '../../common/widgets/login.dart'; import '../../common/widgets/peer_tab_page.dart'; import '../../consts.dart'; import '../../models/model.dart'; +import '../../models/state_model.dart'; import '../../models/platform_model.dart'; import 'home_page.dart'; import 'scan_page.dart'; @@ -54,6 +55,7 @@ class _ConnectionPageState extends State { } }(); } + stateGlobal.startSvcStatusTimer(); if (isAndroid) { Timer(const Duration(seconds: 5), () async { _updateUrl = await bind.mainGetSoftwareUpdateUrl(); @@ -180,6 +182,7 @@ class _ConnectionPageState extends State { @override void dispose() { _idController.dispose(); + stateGlobal.cancelSvcStatusTimer(); super.dispose(); } } diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 8bcb3f7a6..13b153891 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -57,6 +57,7 @@ class AbModel { return ""; } } catch (err) { + debugPrint('REMOVE ME ====================== err $err'); err.printError(); abError.value = err.toString(); } finally { diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index f7b4f8cc2..825a73751 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -1,10 +1,16 @@ +import 'dart:convert'; import 'dart:io'; +import 'dart:async'; import 'package:desktop_multi_window/desktop_multi_window.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../consts.dart'; +import '../common.dart'; + +import './platform_model.dart'; +import './user_model.dart'; enum SvcStatus { notReady, connecting, ready } @@ -18,7 +24,10 @@ class StateGlobal { final RxDouble _windowBorderWidth = RxDouble(kWindowBorderWidth); final RxBool showRemoteToolBar = false.obs; final RxInt displaysCount = 0.obs; + final svcStatus = SvcStatus.notReady.obs; + final svcIsUsingPublicServer = true.obs; + Timer? _svcStatusTimer; // Use for desktop -> remote toolbar -> resolution final Map> _lastResolutionGroupValues = {}; @@ -84,6 +93,46 @@ class StateGlobal { } } + startSvcStatusTimer() { + _svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async { + _updateSvcStatus(); + }); + } + + cancelSvcStatusTimer() { + _svcStatusTimer?.cancel(); + _svcStatusTimer = null; + } + + _updateSvcStatus() async { + final status = + jsonDecode(await bind.mainGetConnectStatus()) as Map; + final statusNum = status['status_num'] as int; + final preStatus = stateGlobal.svcStatus.value; + if (statusNum == 0) { + stateGlobal.svcStatus.value = SvcStatus.connecting; + } else if (statusNum == -1) { + stateGlobal.svcStatus.value = SvcStatus.notReady; + } else if (statusNum == 1) { + stateGlobal.svcStatus.value = SvcStatus.ready; + if (preStatus != SvcStatus.ready) { + gFFI.userModel.refreshCurrentUser(); + } + } else { + stateGlobal.svcStatus.value = SvcStatus.notReady; + } + if (stateGlobal.svcStatus.value != SvcStatus.ready) { + gFFI.userModel.isAdmin.value = false; + gFFI.groupModel.reset(); + } + debugPrint('REMOVE ME ========================== $preStatus -> ${stateGlobal.svcStatus.value}'); + if (preStatus != stateGlobal.svcStatus.value) { + UserModel.updateOtherModels(); + } + stateGlobal.svcIsUsingPublicServer.value = + await bind.mainIsUsingPublicServer(); + } + StateGlobal._(); static final StateGlobal instance = StateGlobal._(); diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index b6445eea7..785be96ee 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -44,7 +44,7 @@ lazy_static::lazy_static! { static ref CONFIG: Arc> = Arc::new(RwLock::new(Config::load())); static ref CONFIG2: Arc> = Arc::new(RwLock::new(Config2::load())); static ref LOCAL_CONFIG: Arc> = Arc::new(RwLock::new(LocalConfig::load())); - pub static ref ONLINE: Arc>> = Default::default(); + static ref ONLINE: Arc>> = Default::default(); pub static ref PROD_RENDEZVOUS_SERVER: Arc> = Arc::new(RwLock::new(match option_env!("RENDEZVOUS_SERVER") { Some(key) if !key.is_empty() => key, _ => "", @@ -309,6 +309,11 @@ pub struct TransferSerde { pub read_jobs: Vec, } +#[inline] +pub fn get_online_statue() -> i64 { + *ONLINE.lock().unwrap().values().max().unwrap_or(&0) +} + #[cfg(not(any(target_os = "android", target_os = "ios")))] fn patch(path: PathBuf) -> PathBuf { if let Some(_tmp) = path.to_str() { diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index b3c011c2b..73fbdc9d1 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -14,12 +14,11 @@ use flutter_rust_bridge::{StreamSink, SyncReturn}; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::allow_err; use hbb_common::{ - config::{self, LocalConfig, PeerConfig, PeerInfoSerde, ONLINE}, + config::{self, get_online_statue, LocalConfig, PeerConfig, PeerInfoSerde}, fs, log, message_proto::KeyboardMode, ResultType, }; -use serde_json::json; use std::{ collections::HashMap, ffi::{CStr, CString}, @@ -680,14 +679,18 @@ pub fn main_get_lan_peers() -> String { } pub fn main_get_connect_status() -> String { - let status = get_connect_status(); - // (status_num, key_confirmed, mouse_time, id) - let mut m = serde_json::Map::new(); - m.insert("status_num".to_string(), json!(status.0)); - m.insert("key_confirmed".to_string(), json!(status.1)); - m.insert("mouse_time".to_string(), json!(status.2)); - m.insert("id".to_string(), json!(status.3)); - serde_json::to_string(&m).unwrap_or("".to_string()) + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + serde_json::to_string(&get_connect_status()).unwrap_or("".to_string()) + } + #[cfg(any(target_os = "android", target_os = "ios"))] + { + let mut state = get_online_statue(); + if state > 0 { + state = 1; + } + serde_json::json!({ "status_num": get_online_statue() }).to_string() + } } pub fn main_check_connect_status() { @@ -996,7 +999,7 @@ pub fn main_get_fingerprint() -> String { } pub fn main_get_online_statue() -> i64 { - ONLINE.lock().unwrap().values().max().unwrap_or(&0).clone() + get_online_statue() } pub fn cm_get_clients_state() -> String { @@ -1194,7 +1197,15 @@ pub fn main_check_mouse_time() { } pub fn main_get_mouse_time() -> f64 { - get_mouse_time() + let mut mouse_time = 0.0; + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] + { + mouse_time = get_mouse_time(); + } + mouse_time } pub fn main_wol(id: String) { diff --git a/src/ipc.rs b/src/ipc.rs index 83a48107c..29adb6740 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -186,6 +186,10 @@ pub enum Data { }, SystemInfo(Option), ClickTime(i64), + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] MouseMoveTime(i64), Authorize, Close, @@ -332,6 +336,10 @@ async fn handle(data: Data, stream: &mut Connection) { let t = crate::server::CLICK_TIME.load(Ordering::SeqCst); allow_err!(stream.send(&Data::ClickTime(t)).await); } + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] Data::MouseMoveTime(_) => { let t = crate::server::MOUSE_MOVE_TIME.load(Ordering::SeqCst); allow_err!(stream.send(&Data::MouseMoveTime(t)).await); @@ -345,13 +353,7 @@ async fn handle(data: Data, stream: &mut Connection) { } } Data::OnlineStatus(_) => { - let x = config::ONLINE - .lock() - .unwrap() - .values() - .max() - .unwrap_or(&0) - .clone(); + let x = config::get_online_statue(); let confirmed = Config::get_key_confirmed(); allow_err!(stream.send(&Data::OnlineStatus(Some((x, confirmed)))).await); } diff --git a/src/server/connection.rs b/src/server/connection.rs index 88d7220eb..5eb86808a 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -63,6 +63,10 @@ lazy_static::lazy_static! { static ref SWITCH_SIDES_UUID: Arc::>> = Default::default(); } pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0); +#[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" +))] pub static MOUSE_MOVE_TIME: AtomicI64 = AtomicI64::new(0); #[cfg(all(feature = "flutter", feature = "plugin_framework"))] @@ -163,6 +167,7 @@ pub struct Connection { // by peer disable_audio: bool, // by peer + #[cfg(windows)] enable_file_transfer: bool, // by peer audio_sender: Option, @@ -291,6 +296,7 @@ impl Connection { show_remote_cursor: false, ip: "".to_owned(), disable_audio: false, + #[cfg(windows)] enable_file_transfer: false, disable_clipboard: false, disable_keyboard: false, @@ -1112,6 +1118,7 @@ impl Connection { self.audio && !self.disable_audio } + #[cfg(windows)] fn file_transfer_enabled(&self) -> bool { self.file && self.enable_file_transfer } @@ -1563,6 +1570,10 @@ impl Connection { if is_left_up(&me) { CLICK_TIME.store(get_time(), Ordering::SeqCst); } else { + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst); } self.input_mouse(me, self.inner.id()); diff --git a/src/ui.rs b/src/ui.rs index 94ae30cf6..10eab22cb 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -362,9 +362,9 @@ impl UI { fn get_connect_status(&mut self) -> Value { let mut v = Value::array(0); let x = get_connect_status(); - v.push(x.0); - v.push(x.1); - v.push(x.3); + v.push(x.status_num); + v.push(x.key_confirmed); + v.push(x.id); v } diff --git a/src/ui_interface.rs b/src/ui_interface.rs index e298e1167..7ce9a0000 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -1,9 +1,3 @@ -use std::{ - collections::HashMap, - process::Child, - sync::{Arc, Mutex}, -}; - #[cfg(any(target_os = "android", target_os = "ios"))] use hbb_common::password_security; use hbb_common::{ @@ -16,6 +10,12 @@ use hbb_common::{ sleep, tokio::{sync::mpsc, time}, }; +use serde_derive::Serialize; +use std::{ + collections::HashMap, + process::Child, + sync::{Arc, Mutex}, +}; use hbb_common::{ config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT}, @@ -32,10 +32,34 @@ use crate::ipc; type Message = RendezvousMessage; pub type Children = Arc)>>; -type Status = (i32, bool, i64, String); // (status_num, key_confirmed, mouse_time, id) + +#[derive(Clone, Debug, Serialize)] +pub struct UiStatus { + pub status_num: i32, + #[cfg(not(feature = "flutter"))] + pub key_confirmed: bool, + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] + pub mouse_time: i64, + #[cfg(not(feature = "flutter"))] + pub id: String, +} lazy_static::lazy_static! { - static ref UI_STATUS : Arc> = Arc::new(Mutex::new((0, false, 0, "".to_owned()))); + static ref UI_STATUS : Arc> = Arc::new(Mutex::new(UiStatus{ + status_num: 0, + #[cfg(not(feature = "flutter"))] + key_confirmed: false, + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] + mouse_time: 0, + #[cfg(not(feature = "flutter"))] + id: "".to_owned(), + })); static ref OPTIONS : Arc>> = Arc::new(Mutex::new(Config::get_options())); static ref ASYNC_JOB_STATUS : Arc> = Default::default(); static ref TEMPORARY_PASSWD : Arc> = Arc::new(Mutex::new("".to_owned())); @@ -393,15 +417,20 @@ pub fn is_installed_lower_version() -> bool { } #[inline] +#[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" +))] pub fn get_mouse_time() -> f64 { - let ui_status = UI_STATUS.lock().unwrap(); - let res = ui_status.2 as f64; - return res; + UI_STATUS.lock().unwrap().mouse_time as f64 } #[inline] pub fn check_mouse_time() { - #[cfg(not(any(target_os = "android", target_os = "ios")))] + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] { let sender = SENDER.lock().unwrap(); allow_err!(sender.send(ipc::Data::MouseMoveTime(0))); @@ -409,10 +438,8 @@ pub fn check_mouse_time() { } #[inline] -pub fn get_connect_status() -> Status { - let ui_statue = UI_STATUS.lock().unwrap(); - let res = ui_statue.clone(); - res +pub fn get_connect_status() -> UiStatus { + UI_STATUS.lock().unwrap().clone() } #[inline] @@ -874,9 +901,13 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver { mouse_time = v; - UI_STATUS.lock().unwrap().2 = v; + UI_STATUS.lock().unwrap().mouse_time = v; } Ok(Some(ipc::Data::Options(Some(v)))) => { *OPTIONS.lock().unwrap() = v; @@ -902,8 +933,18 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver 0 { x = 1 } - key_confirmed = c; - *UI_STATUS.lock().unwrap() = (x as _, key_confirmed, mouse_time, id.clone()); + *UI_STATUS.lock().unwrap() = UiStatus { + status_num: x as _, + #[cfg(not(feature = "flutter"))] + key_confirmed: c, + #[cfg(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + ))] + mouse_time, + #[cfg(not(feature = "flutter"))] + id: id.clone(), + }; } _ => {} } @@ -927,7 +968,18 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver Date: Fri, 23 Jun 2023 00:11:57 +0800 Subject: [PATCH 02/11] tmp commit Signed-off-by: dignow --- flutter/lib/common/widgets/address_book.dart | 1 - flutter/lib/models/ab_model.dart | 1 - flutter/lib/models/state_model.dart | 4 ---- src/ui_interface.rs | 4 ++-- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/flutter/lib/common/widgets/address_book.dart b/flutter/lib/common/widgets/address_book.dart index 9a516653b..08df6d4e5 100644 --- a/flutter/lib/common/widgets/address_book.dart +++ b/flutter/lib/common/widgets/address_book.dart @@ -30,7 +30,6 @@ class _AddressBookState extends State { @override Widget build(BuildContext context) => Obx(() { - debugPrint('REMOVE ME =========================== AddressBook ${gFFI.userModel.userName.value} ${gFFI.abModel.abLoading} ${gFFI.abModel.abError} ${gFFI.abModel.fromServer} ${isDesktop}'); if (gFFI.userModel.userName.value.isEmpty) { return Center( child: ElevatedButton( diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart index 13b153891..8bcb3f7a6 100644 --- a/flutter/lib/models/ab_model.dart +++ b/flutter/lib/models/ab_model.dart @@ -57,7 +57,6 @@ class AbModel { return ""; } } catch (err) { - debugPrint('REMOVE ME ====================== err $err'); err.printError(); abError.value = err.toString(); } finally { diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index 825a73751..2a457881d 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -125,10 +125,6 @@ class StateGlobal { gFFI.userModel.isAdmin.value = false; gFFI.groupModel.reset(); } - debugPrint('REMOVE ME ========================== $preStatus -> ${stateGlobal.svcStatus.value}'); - if (preStatus != stateGlobal.svcStatus.value) { - UserModel.updateOtherModels(); - } stateGlobal.svcIsUsingPublicServer.value = await bind.mainIsUsingPublicServer(); } diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 7ce9a0000..39930fa4b 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -929,14 +929,14 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver { + Ok(Some(ipc::Data::OnlineStatus(Some((mut x, _c))))) => { if x > 0 { x = 1 } *UI_STATUS.lock().unwrap() = UiStatus { status_num: x as _, #[cfg(not(feature = "flutter"))] - key_confirmed: c, + key_confirmed: _c, #[cfg(all( not(any(target_os = "android", target_os = "ios")), feature = "flutter" From ed53fa37fc110868a1de48e93ac3d05e4e053db9 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 11:28:51 +0800 Subject: [PATCH 03/11] debug, refact, connection state Signed-off-by: dignow --- src/flutter_ffi.rs | 13 +++++++++---- src/ui_interface.rs | 13 ++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 73fbdc9d1..8f1b2005d 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -689,7 +689,7 @@ pub fn main_get_connect_status() -> String { if state > 0 { state = 1; } - serde_json::json!({ "status_num": get_online_statue() }).to_string() + serde_json::json!({ "status_num": state }).to_string() } } @@ -1197,15 +1197,20 @@ pub fn main_check_mouse_time() { } pub fn main_get_mouse_time() -> f64 { - let mut mouse_time = 0.0; #[cfg(all( not(any(target_os = "android", target_os = "ios")), feature = "flutter" ))] { - mouse_time = get_mouse_time(); + get_mouse_time() + } + #[cfg(not(all( + not(any(target_os = "android", target_os = "ios")), + feature = "flutter" + )))] + { + 0.0 } - mouse_time } pub fn main_wol(id: String) { diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 39930fa4b..ffffc3778 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -438,6 +438,7 @@ pub fn check_mouse_time() { } #[inline] +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn get_connect_status() -> UiStatus { UI_STATUS.lock().unwrap().clone() } @@ -884,10 +885,13 @@ pub fn get_hostname() -> String { #[cfg(not(any(target_os = "android", target_os = "ios")))] #[tokio::main(flavor = "current_thread")] async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver) { + #[cfg(not(feature = "flutter"))] let mut key_confirmed = false; let mut rx = rx; let mut mouse_time = 0; + #[cfg(not(feature = "flutter"))] let mut id = "".to_owned(); + #[cfg(target_os="windows")] let mut enable_file_transfer = "".to_owned(); loop { @@ -924,7 +928,10 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver { if name == "id" { - id = value; + #[cfg(not(feature = "flutter"))] + { + id = value; + } } else if name == "temporary-password" { *TEMPORARY_PASSWD.lock().unwrap() = value; } @@ -933,6 +940,10 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver 0 { x = 1 } + #[cfg(not(feature = "flutter"))] + { + key_confirmed = _c; + } *UI_STATUS.lock().unwrap() = UiStatus { status_num: x as _, #[cfg(not(feature = "flutter"))] From 71db0e99b5c40281d7c348812845da40b1c54419 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 12:49:36 +0800 Subject: [PATCH 04/11] debug, mobile, connection login state Signed-off-by: dignow --- src/flutter_ffi.rs | 10 ++-------- src/hbbs_http/account.rs | 2 +- src/ui_interface.rs | 37 ++++++++----------------------------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 8f1b2005d..f3a7239f7 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -1197,17 +1197,11 @@ pub fn main_check_mouse_time() { } pub fn main_get_mouse_time() -> f64 { - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] { get_mouse_time() } - #[cfg(not(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - )))] + #[cfg(any(target_os = "android", target_os = "ios"))] { 0.0 } diff --git a/src/hbbs_http/account.rs b/src/hbbs_http/account.rs index a2ef53029..e958bf636 100644 --- a/src/hbbs_http/account.rs +++ b/src/hbbs_http/account.rs @@ -216,7 +216,7 @@ impl OidcSession { let query_timeout = OIDC_SESSION.read().unwrap().query_timeout; while OIDC_SESSION.read().unwrap().keep_querying && begin.elapsed() < query_timeout { match Self::query(&code_url.code, &id, &uuid) { - Ok(HbbHttpResponse::<_>::Data(mut auth_body)) => { + Ok(HbbHttpResponse::<_>::Data(auth_body)) => { if remember_me { LocalConfig::set_option( "access_token".to_owned(), diff --git a/src/ui_interface.rs b/src/ui_interface.rs index ffffc3778..16d26b48f 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -38,10 +38,7 @@ pub struct UiStatus { pub status_num: i32, #[cfg(not(feature = "flutter"))] pub key_confirmed: bool, - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] pub mouse_time: i64, #[cfg(not(feature = "flutter"))] pub id: String, @@ -52,10 +49,7 @@ lazy_static::lazy_static! { status_num: 0, #[cfg(not(feature = "flutter"))] key_confirmed: false, - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] mouse_time: 0, #[cfg(not(feature = "flutter"))] id: "".to_owned(), @@ -417,20 +411,14 @@ pub fn is_installed_lower_version() -> bool { } #[inline] -#[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" -))] +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn get_mouse_time() -> f64 { UI_STATUS.lock().unwrap().mouse_time as f64 } #[inline] pub fn check_mouse_time() { - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] { let sender = SENDER.lock().unwrap(); allow_err!(sender.send(ipc::Data::MouseMoveTime(0))); @@ -891,7 +879,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver { mouse_time = v; UI_STATUS.lock().unwrap().mouse_time = v; @@ -948,10 +933,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver Date: Fri, 23 Jun 2023 13:09:22 +0800 Subject: [PATCH 05/11] refact, mobile, connection state Signed-off-by: dignow --- flutter/lib/mobile/pages/server_page.dart | 46 ++++++++++++----------- flutter/lib/models/server_model.dart | 12 ------ src/flutter_ffi.rs | 4 -- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/flutter/lib/mobile/pages/server_page.dart b/flutter/lib/mobile/pages/server_page.dart index ae61c91a7..b79b5bdb2 100644 --- a/flutter/lib/mobile/pages/server_page.dart +++ b/flutter/lib/mobile/pages/server_page.dart @@ -11,6 +11,7 @@ import '../../common/widgets/dialog.dart'; import '../../consts.dart'; import '../../models/platform_model.dart'; import '../../models/server_model.dart'; +import '../../models/state_model.dart'; import 'home_page.dart'; class ServerPage extends StatefulWidget implements PageShape { @@ -216,28 +217,29 @@ class ServerInfo extends StatelessWidget { showToast(translate('Copied')); } - Widget ConnectionStateNotification() { - if (serverModel.connectStatus == -1) { - return Row(children: [ - const Icon(Icons.warning_amber_sharp, - color: colorNegative, size: iconSize) - .marginOnly(right: iconMarginRight), - Expanded(child: Text(translate('not_ready_status'))) - ]); - } else if (serverModel.connectStatus == 0) { - return Row(children: [ - SizedBox(width: 20, height: 20, child: CircularProgressIndicator()) - .marginOnly(left: 4, right: iconMarginRight), - Expanded(child: Text(translate('connecting_status'))) - ]); - } else { - return Row(children: [ - const Icon(Icons.check, color: colorPositive, size: iconSize) - .marginOnly(right: iconMarginRight), - Expanded(child: Text(translate('Ready'))) - ]); - } - } + Widget ConnectionStateNotification() => Obx(() { + if (stateGlobal.svcStatus.value == SvcStatus.notReady) { + return Row(children: [ + const Icon(Icons.warning_amber_sharp, + color: colorNegative, size: iconSize) + .marginOnly(right: iconMarginRight), + Expanded(child: Text(translate('not_ready_status'))) + ]); + } else if (stateGlobal.svcStatus.value == SvcStatus.connecting) { + return Row(children: [ + SizedBox( + width: 20, height: 20, child: CircularProgressIndicator()) + .marginOnly(left: 4, right: iconMarginRight), + Expanded(child: Text(translate('connecting_status'))) + ]); + } else { + return Row(children: [ + const Icon(Icons.check, color: colorPositive, size: iconSize) + .marginOnly(right: iconMarginRight), + Expanded(child: Text(translate('Ready'))) + ]); + } + }); return PaddingCard( title: translate('Your Device'), diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 2ca608bd6..765725537 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -31,7 +31,6 @@ class ServerModel with ChangeNotifier { bool _fileOk = false; bool _showElevation = false; bool _hideCm = false; - int _connectStatus = 0; // Rendezvous Server status String _verificationMethod = ""; String _temporaryPasswordLength = ""; String _approveMode = ""; @@ -61,8 +60,6 @@ class ServerModel with ChangeNotifier { bool get hideCm => _hideCm; - int get connectStatus => _connectStatus; - String get verificationMethod { final index = [ kUseTemporaryPassword, @@ -120,15 +117,6 @@ class ServerModel with ChangeNotifier { _serverId = IDTextEditingController(text: _emptyIdShow); timerCallback() async { - var status = await bind.mainGetOnlineStatue(); - if (status > 0) { - status = 1; - } - if (status != _connectStatus) { - _connectStatus = status; - notifyListeners(); - } - if (desktopType == DesktopType.cm) { final res = await bind.cmCheckClientsLength(length: _clients.length); if (res != null) { diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index f3a7239f7..8abd911cc 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -998,10 +998,6 @@ pub fn main_get_fingerprint() -> String { get_fingerprint() } -pub fn main_get_online_statue() -> i64 { - get_online_statue() -} - pub fn cm_get_clients_state() -> String { crate::ui_cm_interface::get_clients_state() } From 72cfea92023d0b3fb6ad6bbea8b5198432708ec3 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 13:15:18 +0800 Subject: [PATCH 06/11] remove warns Signed-off-by: dignow --- src/flutter_ffi.rs | 2 +- src/ui_cm_interface.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 8abd911cc..3a8cfd447 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -14,7 +14,7 @@ use flutter_rust_bridge::{StreamSink, SyncReturn}; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::allow_err; use hbb_common::{ - config::{self, get_online_statue, LocalConfig, PeerConfig, PeerInfoSerde}, + config::{self, LocalConfig, PeerConfig, PeerInfoSerde}, fs, log, message_proto::KeyboardMode, ResultType, diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 7e46fd314..b61598251 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -454,10 +454,10 @@ impl IpcTaskRunner { } } Some(data) = self.rx.recv() => { - if let Data::SwitchPermission{name, enabled} = &data { + if let Data::SwitchPermission{name: _name, enabled: _enabled} = &data { #[cfg(windows)] - if name == "file" { - self.file_transfer_enabled = *enabled; + if _name == "file" { + self.file_transfer_enabled = *_enabled; } } if self.stream.send(&data).await.is_err() { From e6c3c55b3910b2f099b8b6648b3ac299a58724ac Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 13:22:05 +0800 Subject: [PATCH 07/11] fix build Signed-off-by: dignow --- src/flutter_ffi.rs | 2 +- src/ipc.rs | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 3a8cfd447..9a3f1abab 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -685,7 +685,7 @@ pub fn main_get_connect_status() -> String { } #[cfg(any(target_os = "android", target_os = "ios"))] { - let mut state = get_online_statue(); + let mut state = hbb_common::config::get_online_statue(); if state > 0 { state = 1; } diff --git a/src/ipc.rs b/src/ipc.rs index 29adb6740..6a426e37d 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -186,10 +186,7 @@ pub enum Data { }, SystemInfo(Option), ClickTime(i64), - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] MouseMoveTime(i64), Authorize, Close, @@ -336,10 +333,7 @@ async fn handle(data: Data, stream: &mut Connection) { let t = crate::server::CLICK_TIME.load(Ordering::SeqCst); allow_err!(stream.send(&Data::ClickTime(t)).await); } - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] Data::MouseMoveTime(_) => { let t = crate::server::MOUSE_MOVE_TIME.load(Ordering::SeqCst); allow_err!(stream.send(&Data::MouseMoveTime(t)).await); From ef102bdf94205e1bfe9bb6f29d0b1883ef1b6ff4 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 14:29:58 +0800 Subject: [PATCH 08/11] debug, mobile, connection state Signed-off-by: dignow --- flutter/lib/mobile/pages/connection_page.dart | 3 --- flutter/lib/mobile/pages/server_page.dart | 1 - flutter/lib/models/server_model.dart | 4 +++- flutter/lib/models/state_model.dart | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/flutter/lib/mobile/pages/connection_page.dart b/flutter/lib/mobile/pages/connection_page.dart index df4a85233..5a581f0c7 100644 --- a/flutter/lib/mobile/pages/connection_page.dart +++ b/flutter/lib/mobile/pages/connection_page.dart @@ -11,7 +11,6 @@ import '../../common/widgets/login.dart'; import '../../common/widgets/peer_tab_page.dart'; import '../../consts.dart'; import '../../models/model.dart'; -import '../../models/state_model.dart'; import '../../models/platform_model.dart'; import 'home_page.dart'; import 'scan_page.dart'; @@ -55,7 +54,6 @@ class _ConnectionPageState extends State { } }(); } - stateGlobal.startSvcStatusTimer(); if (isAndroid) { Timer(const Duration(seconds: 5), () async { _updateUrl = await bind.mainGetSoftwareUpdateUrl(); @@ -182,7 +180,6 @@ class _ConnectionPageState extends State { @override void dispose() { _idController.dispose(); - stateGlobal.cancelSvcStatusTimer(); super.dispose(); } } diff --git a/flutter/lib/mobile/pages/server_page.dart b/flutter/lib/mobile/pages/server_page.dart index b79b5bdb2..0b0b8cc5c 100644 --- a/flutter/lib/mobile/pages/server_page.dart +++ b/flutter/lib/mobile/pages/server_page.dart @@ -201,7 +201,6 @@ class ServerInfo extends StatelessWidget { @override Widget build(BuildContext context) { final isPermanent = model.verificationMethod == kUsePermanentPassword; - final serverModel = Provider.of(context); const Color colorPositive = Colors.green; const Color colorNegative = Colors.red; diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 765725537..4eddee2b6 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -15,7 +15,8 @@ import '../common/formatter/id_formatter.dart'; import '../desktop/pages/server_page.dart' as desktop; import '../desktop/widgets/tabbar_widget.dart'; import '../mobile/pages/server_page.dart'; -import 'model.dart'; +import './model.dart'; +import './state_model.dart'; const kLoginDialogTag = "LOGIN"; @@ -117,6 +118,7 @@ class ServerModel with ChangeNotifier { _serverId = IDTextEditingController(text: _emptyIdShow); timerCallback() async { + stateGlobal.updateSvcStatus(); if (desktopType == DesktopType.cm) { final res = await bind.cmCheckClientsLength(length: _clients.length); if (res != null) { diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index 2a457881d..842404ac2 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -95,7 +95,7 @@ class StateGlobal { startSvcStatusTimer() { _svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async { - _updateSvcStatus(); + updateSvcStatus(); }); } @@ -104,7 +104,7 @@ class StateGlobal { _svcStatusTimer = null; } - _updateSvcStatus() async { + updateSvcStatus() async { final status = jsonDecode(await bind.mainGetConnectStatus()) as Map; final statusNum = status['status_num'] as int; From 53cd380a2386ec6e369dc7523027ef1970d6b6c7 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 14:37:21 +0800 Subject: [PATCH 09/11] fix build Signed-off-by: dignow --- src/server/connection.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/server/connection.rs b/src/server/connection.rs index 5eb86808a..4992bb416 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -63,10 +63,7 @@ lazy_static::lazy_static! { static ref SWITCH_SIDES_UUID: Arc::>> = Default::default(); } pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0); -#[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" -))] +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub static MOUSE_MOVE_TIME: AtomicI64 = AtomicI64::new(0); #[cfg(all(feature = "flutter", feature = "plugin_framework"))] @@ -1570,10 +1567,7 @@ impl Connection { if is_left_up(&me) { CLICK_TIME.store(get_time(), Ordering::SeqCst); } else { - #[cfg(all( - not(any(target_os = "android", target_os = "ios")), - feature = "flutter" - ))] + #[cfg(not(any(target_os = "android", target_os = "ios")))] MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst); } self.input_mouse(me, self.inner.id()); From 105a7741358efad9e7718bd0fc2a435e3c721dbe Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 14:42:24 +0800 Subject: [PATCH 10/11] simple refactor Signed-off-by: dignow --- flutter/lib/desktop/pages/connection_page.dart | 10 ++++++++-- flutter/lib/models/state_model.dart | 13 ------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index f37bb8d9f..2ce80232d 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -1,5 +1,6 @@ // main window right pane +import 'dart:async'; import 'dart:io'; import 'package:auto_size_text/auto_size_text.dart'; @@ -34,6 +35,8 @@ class _ConnectionPageState extends State /// Nested scroll controller final _scrollController = ScrollController(); + Timer? _svcStatusTimer; + final RxBool _idInputFocused = false.obs; final FocusNode _idFocusNode = FocusNode(); @@ -54,7 +57,9 @@ class _ConnectionPageState extends State } }(); } - stateGlobal.startSvcStatusTimer(); + _svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async { + stateGlobal.updateSvcStatus(); + }); _idFocusNode.addListener(() { _idInputFocused.value = _idFocusNode.hasFocus; // select all to faciliate removing text, just following the behavior of address input of chrome @@ -67,7 +72,8 @@ class _ConnectionPageState extends State @override void dispose() { _idController.dispose(); - stateGlobal.cancelSvcStatusTimer(); + _svcStatusTimer?.cancel(); + _svcStatusTimer = null; windowManager.removeListener(this); super.dispose(); } diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index 842404ac2..d73ddb643 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -10,7 +10,6 @@ import '../consts.dart'; import '../common.dart'; import './platform_model.dart'; -import './user_model.dart'; enum SvcStatus { notReady, connecting, ready } @@ -27,7 +26,6 @@ class StateGlobal { final svcStatus = SvcStatus.notReady.obs; final svcIsUsingPublicServer = true.obs; - Timer? _svcStatusTimer; // Use for desktop -> remote toolbar -> resolution final Map> _lastResolutionGroupValues = {}; @@ -93,17 +91,6 @@ class StateGlobal { } } - startSvcStatusTimer() { - _svcStatusTimer = periodic_immediate(Duration(seconds: 1), () async { - updateSvcStatus(); - }); - } - - cancelSvcStatusTimer() { - _svcStatusTimer?.cancel(); - _svcStatusTimer = null; - } - updateSvcStatus() async { final status = jsonDecode(await bind.mainGetConnectStatus()) as Map; From 6a010e89c9e4f32c9519551200e0e5a5c05c5377 Mon Sep 17 00:00:00 2001 From: dignow Date: Fri, 23 Jun 2023 17:12:53 +0800 Subject: [PATCH 11/11] remove unused code Signed-off-by: dignow --- src/server/connection.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/connection.rs b/src/server/connection.rs index 4992bb416..f747e47c1 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1567,7 +1567,6 @@ impl Connection { if is_left_up(&me) { CLICK_TIME.store(get_time(), Ordering::SeqCst); } else { - #[cfg(not(any(target_os = "android", target_os = "ios")))] MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst); } self.input_mouse(me, self.inner.id());