mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-04-19 11:06:50 +00:00
Extract method to read click event from input
This commit is contained in:
parent
c7c3773f55
commit
84fee2495a
31
src/main.rs
31
src/main.rs
@ -59,6 +59,21 @@ async fn run_click_cmd(cmd: String) {
|
||||
};
|
||||
}
|
||||
|
||||
fn read_click_event() -> Result<ClickEvent, ()> {
|
||||
let stdin = std::io::stdin();
|
||||
let mut input = String::new();
|
||||
|
||||
if stdin.read_line(&mut input).is_ok() {
|
||||
// Return click event after removing leading comma
|
||||
if let Ok(click_event) =
|
||||
serde_json::from_str::<ClickEvent>(input.replace(",{", "{").as_str())
|
||||
{
|
||||
return Ok(click_event);
|
||||
}
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn main() {
|
||||
println!(
|
||||
@ -71,22 +86,8 @@ async fn main() {
|
||||
println!("[");
|
||||
|
||||
let inputs = task::spawn(async {
|
||||
let stdin = std::io::stdin();
|
||||
loop {
|
||||
let mut input = String::new();
|
||||
|
||||
if stdin.read_line(&mut input).is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if input.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove leading comma
|
||||
let input = input.replace(",{", "{");
|
||||
|
||||
if let Ok(click_event) = serde_json::from_str::<ClickEvent>(input.as_str()) {
|
||||
if let Ok(click_event) = read_click_event() {
|
||||
// Ignore click event if not left mouse button
|
||||
if click_event.button != 1 {
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user