refact is_peer_version_ge, and fix version comparation > to >=
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
		
							parent
							
								
									eb0acc33e2
								
							
						
					
					
						commit
						d6c8fb2b28
					
				@ -818,3 +818,21 @@ pub async fn get_key(sync: bool) -> String {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    key
 | 
					    key
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn is_peer_version_ge(v: &str) -> bool {
 | 
				
			||||||
 | 
					    #[cfg(not(any(feature = "flutter", feature = "cli")))]
 | 
				
			||||||
 | 
					    if let Some(session) = crate::ui::CUR_SESSION.lock().unwrap().as_ref() {
 | 
				
			||||||
 | 
					        return session.get_peer_version() >= hbb_common::get_version_number(v);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[cfg(feature = "flutter")]
 | 
				
			||||||
 | 
					    if let Some(session) = crate::flutter::SESSIONS
 | 
				
			||||||
 | 
					        .read()
 | 
				
			||||||
 | 
					        .unwrap()
 | 
				
			||||||
 | 
					        .get(&*crate::flutter::CUR_SESSION_ID.read().unwrap())
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return session.get_peer_version() >= hbb_common::get_version_number(v);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -339,24 +339,8 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode {
 | 
				
			|||||||
        "translate" => KeyboardMode::Translate,
 | 
					        "translate" => KeyboardMode::Translate,
 | 
				
			||||||
        "legacy" => KeyboardMode::Legacy,
 | 
					        "legacy" => KeyboardMode::Legacy,
 | 
				
			||||||
        _ => {
 | 
					        _ => {
 | 
				
			||||||
            // Set "map" as default mode if version > 1.2.0.
 | 
					            // Set "map" as default mode if version >= 1.2.0.
 | 
				
			||||||
            let mut is_peer_version_gt_1_2_0 = false;
 | 
					            if crate::is_peer_version_ge("1.2.0") {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            #[cfg(not(any(feature = "flutter", feature = "cli")))]
 | 
					 | 
				
			||||||
            if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
 | 
					 | 
				
			||||||
                is_peer_version_gt_1_2_0 =
 | 
					 | 
				
			||||||
                    session.get_peer_version() > hbb_common::get_version_number("1.2.0");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            #[cfg(feature = "flutter")]
 | 
					 | 
				
			||||||
            if let Some(session) = SESSIONS
 | 
					 | 
				
			||||||
                .read()
 | 
					 | 
				
			||||||
                .unwrap()
 | 
					 | 
				
			||||||
                .get(&*CUR_SESSION_ID.read().unwrap())
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                is_peer_version_gt_1_2_0 =
 | 
					 | 
				
			||||||
                    session.get_peer_version() > hbb_common::get_version_number("1.2.0");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if is_peer_version_gt_1_2_0 {
 | 
					 | 
				
			||||||
                KeyboardMode::Map
 | 
					                KeyboardMode::Map
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                KeyboardMode::Legacy
 | 
					                KeyboardMode::Legacy
 | 
				
			||||||
 | 
				
			|||||||
@ -43,13 +43,15 @@ use sha2::{Digest, Sha256};
 | 
				
			|||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
					#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
use std::sync::atomic::Ordering;
 | 
					use std::sync::atomic::Ordering;
 | 
				
			||||||
use std::{
 | 
					use std::{
 | 
				
			||||||
    collections::HashSet,
 | 
					 | 
				
			||||||
    num::NonZeroI64,
 | 
					    num::NonZeroI64,
 | 
				
			||||||
    sync::{atomic::AtomicI64, mpsc as std_mpsc},
 | 
					    sync::{atomic::AtomicI64, mpsc as std_mpsc},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
					#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
use system_shutdown;
 | 
					use system_shutdown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
 | 
					use std::collections::HashSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>;
 | 
					pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
lazy_static::lazy_static! {
 | 
					lazy_static::lazy_static! {
 | 
				
			||||||
@ -153,6 +155,7 @@ pub struct Connection {
 | 
				
			|||||||
    voice_call_request_timestamp: Option<NonZeroI64>,
 | 
					    voice_call_request_timestamp: Option<NonZeroI64>,
 | 
				
			||||||
    audio_input_device_before_voice_call: Option<String>,
 | 
					    audio_input_device_before_voice_call: Option<String>,
 | 
				
			||||||
    options_in_login: Option<OptionMessage>,
 | 
					    options_in_login: Option<OptionMessage>,
 | 
				
			||||||
 | 
					    #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
    pressed_modifiers: HashSet<rdev::Key>,
 | 
					    pressed_modifiers: HashSet<rdev::Key>,
 | 
				
			||||||
    #[cfg(all(target_os = "linux", feature = "linux_headless"))]
 | 
					    #[cfg(all(target_os = "linux", feature = "linux_headless"))]
 | 
				
			||||||
    rx_cm_stream_ready: mpsc::Receiver<()>,
 | 
					    rx_cm_stream_ready: mpsc::Receiver<()>,
 | 
				
			||||||
@ -273,6 +276,7 @@ impl Connection {
 | 
				
			|||||||
            voice_call_request_timestamp: None,
 | 
					            voice_call_request_timestamp: None,
 | 
				
			||||||
            audio_input_device_before_voice_call: None,
 | 
					            audio_input_device_before_voice_call: None,
 | 
				
			||||||
            options_in_login: None,
 | 
					            options_in_login: None,
 | 
				
			||||||
 | 
					            #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
            pressed_modifiers: Default::default(),
 | 
					            pressed_modifiers: Default::default(),
 | 
				
			||||||
            #[cfg(all(target_os = "linux", feature = "linux_headless"))]
 | 
					            #[cfg(all(target_os = "linux", feature = "linux_headless"))]
 | 
				
			||||||
            rx_cm_stream_ready: _rx_cm_stream_ready,
 | 
					            rx_cm_stream_ready: _rx_cm_stream_ready,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user