1. 完善msg的处理工作。到了可以调试的步骤了
2. 准备增加屏幕和鼠标的获取相关代码,尚不能编译 通过
This commit is contained in:
		@@ -6,12 +6,14 @@ edition = "2021"
 | 
				
			|||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
tokio = { version = "1.39.2", features = ["macros", "rt-multi-thread"] }
 | 
					tokio = { version = "1.39.2", features = ["macros", "rt-multi-thread"] }
 | 
				
			||||||
tokio-macros = "2.4.0"
 | 
					tokio-macros = "2.4.0"
 | 
				
			||||||
reqwest="0.12.5"
 | 
					reqwest = "0.12.5"
 | 
				
			||||||
log="0.4.22"
 | 
					log = "0.4.22"
 | 
				
			||||||
env_logger="0.8"
 | 
					env_logger = "0.8"
 | 
				
			||||||
url = "2.2"
 | 
					url = "2.2"
 | 
				
			||||||
percent-encoding = "2.1"
 | 
					percent-encoding = "2.1"
 | 
				
			||||||
trust-dns-resolver = "0.20"
 | 
					trust-dns-resolver = "0.20"
 | 
				
			||||||
select = "0.5"
 | 
					select = "0.5"
 | 
				
			||||||
scraper = "0.12"
 | 
					scraper = "0.12"
 | 
				
			||||||
arboard = "3.4.0"
 | 
					arboard = "3.4.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					winapi = { version = "0.3.9", features = ["winnt"] }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										73
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -13,6 +13,7 @@ use std::collections::{BTreeMap, VecDeque};
 | 
				
			|||||||
extern crate log;
 | 
					extern crate log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod wclip;
 | 
					pub mod wclip;
 | 
				
			||||||
 | 
					pub mod sys_res;
 | 
				
			||||||
pub struct ClipboardSync {
 | 
					pub struct ClipboardSync {
 | 
				
			||||||
    user_name: String,
 | 
					    user_name: String,
 | 
				
			||||||
    password: String,
 | 
					    password: String,
 | 
				
			||||||
@@ -20,6 +21,8 @@ pub struct ClipboardSync {
 | 
				
			|||||||
    ip: String,
 | 
					    ip: String,
 | 
				
			||||||
    cookies: String,
 | 
					    cookies: String,
 | 
				
			||||||
    clip: wclip::Wclip,
 | 
					    clip: wclip::Wclip,
 | 
				
			||||||
 | 
					    //last message magic
 | 
				
			||||||
 | 
					    cache_magic: u8,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42";
 | 
					const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42";
 | 
				
			||||||
@@ -46,7 +49,7 @@ pub async fn start_msg_sync(ctx:Arc<Mutex<ClipboardSync>>) -> Result<task::JoinH
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
enum Msg <'a>{
 | 
					enum Msg <'a>{
 | 
				
			||||||
    Msg(&'a str),
 | 
					    Msg(&'a str),
 | 
				
			||||||
    Sub((i8, i8, i8, &'a str)),
 | 
					    Sub((u8, u8, u8, &'a str)),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl ClipboardSync {
 | 
					impl ClipboardSync {
 | 
				
			||||||
@@ -58,6 +61,7 @@ impl ClipboardSync {
 | 
				
			|||||||
            ip: ip.to_string(),
 | 
					            ip: ip.to_string(),
 | 
				
			||||||
            cookies: "".to_string(),
 | 
					            cookies: "".to_string(),
 | 
				
			||||||
            clip: wclip::Wclip::new(),
 | 
					            clip: wclip::Wclip::new(),
 | 
				
			||||||
 | 
					            cache_magic: 0xff,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,7 +136,6 @@ impl ClipboardSync {
 | 
				
			|||||||
            log::trace!("verify Response: {}", resp);
 | 
					            log::trace!("verify Response: {}", resp);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if resp.contains("<title>Copy & Paste</title>") {
 | 
					        if resp.contains("<title>Copy & Paste</title>") {
 | 
				
			||||||
            self.msg2clip(&resp).await;
 | 
					 | 
				
			||||||
            Ok(())
 | 
					            Ok(())
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            Err(Box::new(io::Error::new(io::ErrorKind::Other, "登录失败")))
 | 
					            Err(Box::new(io::Error::new(io::ErrorKind::Other, "登录失败")))
 | 
				
			||||||
@@ -164,46 +167,28 @@ impl ClipboardSync {
 | 
				
			|||||||
        //x|x|x| -> index|total|magic|
 | 
					        //x|x|x| -> index|total|magic|
 | 
				
			||||||
        let head = &msg[0..7];
 | 
					        let head = &msg[0..7];
 | 
				
			||||||
        let body = &msg[7..];
 | 
					        let body = &msg[7..];
 | 
				
			||||||
        let text = head.split('|').collect::<Vec<_>>();
 | 
					 | 
				
			||||||
        if text.len() == 3 && text[0].len() == 1 && text[1].len() == 1 && text[2].len() == 1{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let check = head.split('|').filter(|text| {
 | 
					        let check = head.split('|').filter(|text| {
 | 
				
			||||||
            let text = text.as_bytes();
 | 
					            let text = text.as_bytes();
 | 
				
			||||||
            if text.len() == 1 {
 | 
					            if text.len() == 1 {
 | 
				
			||||||
                    let text = text[0] as i8;
 | 
					                if text[0] >= b'!' && text[0] < b'|' {true} else {false}
 | 
				
			||||||
                    if text < '!' as i8 && text >= '|' as i8 {
 | 
					 | 
				
			||||||
                        true
 | 
					 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                false
 | 
					                false
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
                } else {
 | 
					        }).map(|x|x.as_bytes()[0] - b'!').collect::<Vec<_>>();
 | 
				
			||||||
                    false
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }).collect::<Vec<&str>>();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            let index = text[0].as_bytes()[0] as i8;
 | 
					        if check.len() != 3 {
 | 
				
			||||||
            if index < '!' as i8 && index >= '|' as i8 {
 | 
					 | 
				
			||||||
            return Msg::Msg(msg)
 | 
					            return Msg::Msg(msg)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
            let total = text[1].as_bytes()[1] as i8;
 | 
					
 | 
				
			||||||
            if total < '!' as i8 && total >= '|' as i8 {
 | 
					        return Msg::Sub((check[0], check[1], check[2], body));
 | 
				
			||||||
                return Msg::Msg(msg)
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            let magic = text[2].as_bytes()[1] as i8;
 | 
					 | 
				
			||||||
            if magic < '!' as i8 && magic >= '|' as i8 {
 | 
					 | 
				
			||||||
                return Msg::Msg(msg)
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return Msg::Sub((index, total, magic, body));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return Msg::Msg(msg)
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    pub async fn msg2clip(&mut self, html: &str) {
 | 
					    pub async fn msg2clip(&mut self, html: &str) {
 | 
				
			||||||
        // log::info!("html: {}", html);
 | 
					        // log::info!("html: {}", html);
 | 
				
			||||||
        let document = Html::parse_document(html);
 | 
					        let document = Html::parse_document(html);
 | 
				
			||||||
        let selector = Selector::parse("code").unwrap();
 | 
					        let selector = Selector::parse("code").unwrap();
 | 
				
			||||||
        let mut clip_text = String::new();
 | 
					 | 
				
			||||||
        let mut msg_map = BTreeMap::new();
 | 
					        let mut msg_map = BTreeMap::new();
 | 
				
			||||||
        let mut magic_ref = 0;
 | 
					        let mut magic_ref = 0xff;
 | 
				
			||||||
 | 
					        let mut is_first = true;
 | 
				
			||||||
        for element in document.select(&selector).into_iter() {
 | 
					        for element in document.select(&selector).into_iter() {
 | 
				
			||||||
            //let text = element.text().collect::<Vec<_>>().concat();
 | 
					            //let text = element.text().collect::<Vec<_>>().concat();
 | 
				
			||||||
            let text = element.text().collect::<String>();
 | 
					            let text = element.text().collect::<String>();
 | 
				
			||||||
@@ -211,27 +196,37 @@ impl ClipboardSync {
 | 
				
			|||||||
            let msg = ClipboardSync::parse_msg(text.as_str());
 | 
					            let msg = ClipboardSync::parse_msg(text.as_str());
 | 
				
			||||||
            match msg {
 | 
					            match msg {
 | 
				
			||||||
                Msg::Msg(msg) => {
 | 
					                Msg::Msg(msg) => {
 | 
				
			||||||
                    if magic_ref == 0 {
 | 
					                    if magic_ref == 0xff {
 | 
				
			||||||
                        self.clip.set(&msg);
 | 
					                        self.clip.set(&msg);
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                Msg::Sub((index, total, magic, body)) => {
 | 
					                Msg::Sub((index, total, magic, _body)) => {
 | 
				
			||||||
                    if magic_ref == 0{
 | 
					                    magic_ref = if magic_ref == 0xff {magic} else {magic_ref};
 | 
				
			||||||
                        magic_ref = magic;
 | 
					                    if magic_ref != magic { // other message ignore
 | 
				
			||||||
                    } else if magic_ref == magic {
 | 
					                        if is_first {
 | 
				
			||||||
                        msg_map.insert(index, element);
 | 
					                            break;
 | 
				
			||||||
                        if msg_map.len() == (total - 'a' as i8) as usize {
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        // clip_text.push_str(body);
 | 
					                        is_first = false;
 | 
				
			||||||
                    } else {
 | 
					                        continue
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if msg_map.len() == 0 && (
 | 
				
			||||||
 | 
					                        self.cache_magic == magic_ref // message is repeated ignore it
 | 
				
			||||||
 | 
					                        || !is_first // we only process the newest msg
 | 
				
			||||||
 | 
					                    ) {
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    // same msg pack, append to list
 | 
				
			||||||
 | 
					                    msg_map.insert(index, text);
 | 
				
			||||||
 | 
					                    if msg_map.len() as u8 == total {
 | 
				
			||||||
 | 
					                        let msg = msg_map.into_iter().map(|(_key, v)| v).collect::<String>();
 | 
				
			||||||
 | 
					                        self.cache_magic = magic_ref; // save for next msg
 | 
				
			||||||
 | 
					                        self.clip.set(&msg);
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					            is_first = false;
 | 
				
			||||||
        if clip_text.len() != 0 {
 | 
					 | 
				
			||||||
            self.clip.set(&clip_text);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								src/sys_res/mod.rs
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										17
									
								
								src/sys_res/mod.rs
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					extern crate winapi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use winapi::um::winuser::{GetCursorPos, GetSystemMetrics, SM_CXSCREEN, SM_CYSCREEN};
 | 
				
			||||||
 | 
					use winapi::shared::windef::POINT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn get_screen_size() -> (i32, i32) {
 | 
				
			||||||
 | 
					    let mut point = POINT { x: 0, y: 0 };
 | 
				
			||||||
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        GetCursorPos(&mut point);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let x = point.x;
 | 
				
			||||||
 | 
					    let y = point.y;
 | 
				
			||||||
 | 
					    let width = GetSystemMetrics(SM_CXSCREEN);
 | 
				
			||||||
 | 
					    let height = GetSystemMetrics(SM_CYSCREEN);
 | 
				
			||||||
 | 
					    (x, y, width, height)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user