From 934b5b760f4f3a9b10fcd91ca8434c5d5247ccfb Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 15 Mar 2021 18:56:05 +0530 Subject: [PATCH 01/13] [Refactoring] Ownership & Borrowing principles --- src/back/device.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/back/device.rs b/src/back/device.rs index 98ecbe8..a9e2fa3 100644 --- a/src/back/device.rs +++ b/src/back/device.rs @@ -1,6 +1,9 @@ use std::process::Command; use regex::Regex; +use std::io::stdin; +use std::process::exit; +#[derive(Clone, Copy)] pub enum Status { ONLINE, OFFLINE, @@ -13,6 +16,9 @@ pub struct Device { } impl Device { + + const DEVICE_NOT_CONNECTED: &'static str = "- Error: No device is connected\n\nHint: If devices are connected but not visible then check your USB cable & see if USB Debugging option is enabled."; + pub fn get_list_of_devices() -> Vec { let output = Command::new("adb").arg("devices").output().expect(""); let output = String::from_utf8_lossy(&output.stdout); @@ -51,4 +57,40 @@ impl Device { None } + + pub fn choose_a_device(v: &Vec) -> Option<&Device> { + for (i,x) in v.iter().enumerate() { + println!("{}. {}", i+1, x.device_id); + } + println!("Choose a device: "); + let mut buffer = String::new(); + stdin().read_line(&mut buffer).expect("Failed to read input."); + let input: usize = match buffer.trim().parse() { + Ok(v) => { v } + Err(_) => { 0 } + }; + if input == 0 { + println!("Error: Index cannot be 0 or unknown!"); + exit(1) + } + return Some(&v[input-1]) + } + + pub fn get_or_choose_connected_device() -> Option { + let device_list = Device::get_list_of_devices(); + if device_list.len() == 0 { + println!("{}", Device::DEVICE_NOT_CONNECTED); + return None + } + + let device: &Device = if device_list.len() > 1 { + Device::choose_a_device(&device_list).unwrap() + } else { + device_list.first().unwrap() + }; + + let n: Device = Device { device_id: device.device_id.to_owned(), status: device.status.to_owned() }; + + return Some(n); + } } \ No newline at end of file From 08b0050388b8970ea6e9b41e0d5f16c76593f9d4 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 15 Mar 2021 18:56:24 +0530 Subject: [PATCH 02/13] [Refactoring] Ownership & Borrowing principles --- src/main.rs | 51 ++++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21140f8..53883c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,16 +2,15 @@ mod back; use { std::process::{Command, Stdio}, - back::device::Device, - std::io::{stdin}, std::env, back::{ + device::Device, connect::connect_device, command::parse_command, update::fetch_new_version, }, }; -use std::process::exit; +use std::borrow::Borrow; #[tokio::main] async fn main() { @@ -28,47 +27,25 @@ async fn main() { let result = run(); match result { Ok(_) => {} - Err(value) => { - println!("{}", value) + Err(_) => { + //error will be printed } } fetch_new_version().await; } -fn run() -> Result { - let device_list = Device::get_list_of_devices(); - if device_list.len() == 0 { - return Err(String::from("- Error: No device is connected\n\nHint: If devices are connected but not visible then check your USB cable & see if USB Debugging option is enabled.")); - } - - println!("Finding appropriate device..."); - - let device: &Device = if device_list.len() > 1 { - choose_a_device(&device_list).unwrap() - } else { - device_list.first().unwrap() - }; - connect_device(device); - return Ok(true) -} - -fn choose_a_device(v: &Vec) -> Option<&Device> { - for (i,x) in v.iter().enumerate() { - println!("{}. {}", i+1, x.device_id); - } - println!("Choose a device: "); - let mut buffer = String::new(); - stdin().read_line(&mut buffer).expect("Failed to read input."); - let input: usize = match buffer.trim().parse() { - Ok(v) => { v } - Err(_) => { 0 } - }; - if input == 0 { - println!("Error: Index cannot be 0 or unknown!"); - exit(1) +fn run() -> Result { + let result: Option = Device::get_or_choose_connected_device(); + return match result { + Some(device) => { + connect_device(device.borrow()); + Ok(true) + } + None => { + Err(()) + } } - return Some(&v[input-1]) } fn is_adb_installed() -> bool { From 827c28f99744c9eb4a27da2b87e50a0991a0f349 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 15 Mar 2021 20:34:33 +0530 Subject: [PATCH 03/13] [Added] Taking screenshot feature --- Cargo.lock | 11 +++++ Cargo.toml | 1 + src/back/command.rs | 55 +++++++++++++++++++++ src/back/connect.rs | 114 +++++++++++++++++++------------------------- src/back/device.rs | 34 ++++++++++--- 5 files changed, 145 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6da8ff4..fefef0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,7 @@ dependencies = [ "serde_json", "tokio", "wait-timeout", + "wfd", ] [[package]] @@ -1216,6 +1217,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wfd" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e713040b67aae5bf1a0ae3e1ebba8cc29ab2b90da9aa1bff6e09031a8a41d7a8" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 294110a..6e9731e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ tokio = { version = "0.2", features = ["full"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4.19" +wfd = "0.1.2" # Only change version when you are about to release because the next CI # build will automatically create a draft release & publish to chocolatey. \ No newline at end of file diff --git a/src/back/command.rs b/src/back/command.rs index 72925df..3009c83 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -1,5 +1,9 @@ +extern crate wfd; use crate::back::device::Device; use crate::back::connect::disconnect; +use std::process::{Command, exit}; +use std::path::Path; +use self::wfd::{DialogError, DialogParams}; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -10,6 +14,12 @@ pub fn parse_command(c: &Vec) { let _ = show_connected_device(); } else if c[1].eq("-v") || c[1].eq("--version") { println!("{}", VERSION) + } else if c[1].eq("snap") { + if c.len() == 3 { + take_snap(c[2].as_str()); + } else { + take_snap(""); + } } else if c[1].eq("-d") || c[1].eq("--disconnect") { let result = show_connected_device(); match result { @@ -37,6 +47,50 @@ fn show_connected_device() -> Result, bool> { } } +fn take_snap(file_path: &str) { + let result = Device::get_or_choose_connected_device(); + match result { + Some(device) => { + Command::new("adb").arg("-s").arg(device.device_id.as_str()).arg("shell").arg("screencap").arg("-p").arg("/data/local/tmp/file.png").spawn().unwrap().wait().ok(); + let save_path: String = if file_path != "" { + String::from(file_path) + } else { + // show save dialog + let params = DialogParams { + file_name: "file.png", + file_types: vec![("png", "*.png")], + title: "Choose a path to save", + ..Default::default() + }; + let result = wfd::save_dialog(params); + let path: String = match result { + Ok(file) => { + String::from(file.selected_file_path.to_str().unwrap()) + } + Err(e) => { + match e { + DialogError::HResultFailed { hresult, error_method} => { + println!("- Error: HResult Failed - HRESULT: {:X}, Method: {}", hresult, error_method); + } + DialogError::UnsupportedFilepath => { println!("- Error: Unsupported file path"); } + DialogError::UserCancelled => { } + } + exit(1); + } + }; + path + }; + Command::new("adb").arg("-s").arg(device.device_id.as_str()).arg("pull").arg("/data/local/tmp/file.png").arg(save_path.as_str()).spawn().unwrap().wait().ok(); + if Path::new(save_path.as_str()).exists() { + println!("Saved to: {}", save_path); + } else { + println!("Unknown error while saving file"); + } + } + None => {} + } +} + fn print_all_commands() { println!("ADB Over Wifi (aow) v{} - A command line tool to connect devices over wifi (requires ADB).", VERSION); println!("Copyright 2020 Kaustubh Patange - https://github.com/KaustubhPatange/aow"); @@ -49,6 +103,7 @@ fn print_all_commands() { println!(" -d, --disconnect Disconnect the connected device (if any)."); println!(" -v, --version Prints the current version of tool"); println!(" -h, --help Prints this help message."); + println!(" snap [file-path] Take a screenshot. Optionally, you can specify a path to save it."); println!(); println!("Examples:"); println!(" aow"); diff --git a/src/back/connect.rs b/src/back/connect.rs index 8d48462..fb245af 100644 --- a/src/back/connect.rs +++ b/src/back/connect.rs @@ -1,5 +1,5 @@ use { - crate::back::device::{Device, Status}, + crate::back::device::{Device}, regex::Regex, std::io::Read, std::process::{Command, Stdio}, @@ -8,83 +8,69 @@ use { }; pub fn connect_device(d: &Device) { - match d.status { - Status::ONLINE => { - if !is_device_connected_to_wifi(d) { - println!("- Error: Device {} is not connected to Wifi", d.device_id); - return; - } - - let re = Regex::new(r"inet\s?([\d]{3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})").unwrap(); + if !is_device_connected_to_wifi(d) { + println!("- Error: Device {} is not connected to Wifi", d.device_id); + return; + } - let out = Command::new("adb") - .args(&["-s", &d.device_id[..], "shell", "ip", "addr", "show", "wlan0"]) - .output() - .unwrap(); + let re = Regex::new(r"inet\s?([\d]{3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})").unwrap(); - let ip = String::from_utf8_lossy(&out.stdout); - let captures = re.captures(&ip); - match captures { - Some(value) => { - let ip = &value[1]; + let out = Command::new("adb") + .args(&["-s", &d.device_id[..], "shell", "ip", "addr", "show", "wlan0"]) + .output() + .unwrap(); - println!("- address: {}", ip); - println!("Making a connection..."); + let ip = String::from_utf8_lossy(&out.stdout); + let captures = re.captures(&ip); + match captures { + Some(value) => { + let ip = &value[1]; - let mut child = Command::new("adb") - .arg("connect") - .arg(format!("{}:5555", ip)) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); + println!("- address: {}", ip); + println!("Making a connection..."); - let _status_code = match child.wait_timeout(Duration::from_secs(5)).unwrap() { - Some(status) => { - let mut buffer = String::new(); - child.stdout.unwrap().read_to_string(&mut buffer).unwrap(); + let mut child = Command::new("adb") + .arg("connect") + .arg(format!("{}:5555", ip)) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); - println!("- {}", buffer); - if !buffer.starts_with("cannot connect") { - println!("Hint: Safe to remove the USB cable along with device."); - }else { - println!("Applying fix: killing server"); - Command::new("adb").arg("kill-server").spawn().unwrap().wait().ok(); - Command::new("adb").arg("tcpip").arg("5555").spawn().unwrap().wait().ok(); - println!(); - println!("Hint: Try running the command 'aow' again to see if error is fixed."); - } + let _status_code = match child.wait_timeout(Duration::from_secs(5)).unwrap() { + Some(status) => { + let mut buffer = String::new(); + child.stdout.unwrap().read_to_string(&mut buffer).unwrap(); - status.code() - } - None => { - println!("- Error: Connection timeout!"); - println!(); - println!("Hint:\n1. {}\n2. {}", - "Disconnect & re-connect your wifi of client device.", - "Check if mobile data is ON along with Wifi (this may sometimes causes a reason for connection failure)."); + println!("- {}", buffer); + if !buffer.starts_with("cannot connect") { + println!("Hint: Safe to remove the USB cable along with device."); + } else { + println!("Applying fix: killing server"); + Command::new("adb").arg("kill-server").spawn().unwrap().wait().ok(); + Command::new("adb").arg("tcpip").arg("5555").spawn().unwrap().wait().ok(); + println!(); + println!("Hint: Try running the command 'aow' again to see if error is fixed."); + } - child.kill().unwrap(); - child.wait().unwrap().code() - } - }; + status.code() } None => { - println!("- Error: Couldn't find IP address"); + println!("- Error: Connection timeout!"); println!(); - println!("Hint: If your device is connected to WIFI & still you are getting this error, contact me quickly on Github."); - return; + println!("Hint:\n1. {}\n2. {}", + "Disconnect & re-connect your wifi of client device.", + "Check if mobile data is ON along with Wifi (this may sometimes causes a reason for connection failure)."); + + child.kill().unwrap(); + child.wait().unwrap().code() } - } - } - Status::OFFLINE => { - println!("- Error: Device {} is offline", d.device_id); - println!(); - println!("Hint: Try disconnecting & re-connecting device or use aow -d to disconnect from all devices.") + }; } - Status::UNAUTHORIZED => { - println!("- Error: Device {} is unauthorized", d.device_id); + None => { + println!("- Error: Couldn't find IP address"); println!(); - println!("Hint: Accept the prompt in your device & re run the command.") + println!("Hint: If your device is connected to WIFI & still you are getting this error, contact me quickly on Github."); + return; } } } diff --git a/src/back/device.rs b/src/back/device.rs index a9e2fa3..4389ad2 100644 --- a/src/back/device.rs +++ b/src/back/device.rs @@ -10,6 +10,7 @@ pub enum Status { UNAUTHORIZED, } +#[derive(Clone)] pub struct Device { pub device_id: String, pub status: Status, @@ -17,8 +18,6 @@ pub struct Device { impl Device { - const DEVICE_NOT_CONNECTED: &'static str = "- Error: No device is connected\n\nHint: If devices are connected but not visible then check your USB cable & see if USB Debugging option is enabled."; - pub fn get_list_of_devices() -> Vec { let output = Command::new("adb").arg("devices").output().expect(""); let output = String::from_utf8_lossy(&output.stdout); @@ -73,13 +72,13 @@ impl Device { println!("Error: Index cannot be 0 or unknown!"); exit(1) } - return Some(&v[input-1]) + return Some(&v[input-1]); } pub fn get_or_choose_connected_device() -> Option { let device_list = Device::get_list_of_devices(); if device_list.len() == 0 { - println!("{}", Device::DEVICE_NOT_CONNECTED); + println!("- Error: No device is connected\n\nHint: If devices are connected but not visible then check your USB cable & see if USB Debugging option is enabled."); return None } @@ -89,8 +88,31 @@ impl Device { device_list.first().unwrap() }; - let n: Device = Device { device_id: device.device_id.to_owned(), status: device.status.to_owned() }; + // This guarantees that device with "Online" status are sent back. + return match device.status { + Status::ONLINE => { + Some(device.clone()) + } + Status::OFFLINE => { + Device::print_device_offline(device.device_id.as_str()); + None + } + Status::UNAUTHORIZED => { + Device::print_device_unauthorized(device.device_id.as_str()); + None + } + }; + } + + fn print_device_unauthorized(device_id: &str) { + println!("- Error: Device {} is unauthorized", device_id); + println!(); + println!("Hint: Accept the prompt in your device & re run the command.") + } - return Some(n); + fn print_device_offline(device_id: &str) { + println!("- Error: Device {} is offline", device_id); + println!(); + println!("Hint: Try disconnecting & re-connecting device or use aow -d to disconnect from all devices.") } } \ No newline at end of file From 2c9ba892a8824ba5106cd068dee1b56f01581a5f Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Mon, 15 Mar 2021 22:15:12 +0530 Subject: [PATCH 04/13] [Added] Firing deeplink feature --- src/back/command.rs | 32 +++++++++++++++++++++++++------- src/back/device.rs | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/back/command.rs b/src/back/command.rs index 3009c83..4df95ad 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -14,12 +14,18 @@ pub fn parse_command(c: &Vec) { let _ = show_connected_device(); } else if c[1].eq("-v") || c[1].eq("--version") { println!("{}", VERSION) - } else if c[1].eq("snap") { + } else if c[1].eq("snap") { // snap if c.len() == 3 { take_snap(c[2].as_str()); } else { take_snap(""); } + } else if c[1].eq("dlk") || c[1].eq("deeplink") { // deeplink + if c.len() == 3 { + deeplink(c[2].as_str()) + } else { + println!("- Error: No url attached to the command") + } } else if c[1].eq("-d") || c[1].eq("--disconnect") { let result = show_connected_device(); match result { @@ -91,6 +97,16 @@ fn take_snap(file_path: &str) { } } +fn deeplink(link: &str) { + match Device::get_or_choose_connected_device() { + None => {} + Some(device) => { + println!("Launching => {}", link); + Command::new("adb").args(&["-s", device.device_id.as_str(), "shell", "am", "start", "-d", link]).spawn().unwrap().wait().ok(); + } + } +} + fn print_all_commands() { println!("ADB Over Wifi (aow) v{} - A command line tool to connect devices over wifi (requires ADB).", VERSION); println!("Copyright 2020 Kaustubh Patange - https://github.com/KaustubhPatange/aow"); @@ -98,12 +114,14 @@ fn print_all_commands() { println!("Usage: aow [options]"); println!(); println!("Options:"); - println!(" [null] Connects a device over wifi (see demo on Github)"); - println!(" -s, --show Shows the list of connected device over wifi (if any)."); - println!(" -d, --disconnect Disconnect the connected device (if any)."); - println!(" -v, --version Prints the current version of tool"); - println!(" -h, --help Prints this help message."); - println!(" snap [file-path] Take a screenshot. Optionally, you can specify a path to save it."); + println!(" [null] Connects a device over wifi (see demo on Github)"); + println!(" -s, --show Shows the list of connected device over wifi (if any)."); + println!(" -d, --disconnect Disconnect the connected device (if any)."); + println!(" -v, --version Prints the current version of tool"); + println!(" -h, --help Prints this help message."); + println!(" snap [file-path] Take a screenshot. Optionally, you can specify a path to save it otherwise"); + println!(" the program will open native save dialog to save the file."); + println!(" dlk, deeplink [url] Fires a deeplink with the \"url\"."); println!(); println!("Examples:"); println!(" aow"); diff --git a/src/back/device.rs b/src/back/device.rs index 4389ad2..f9f9f5c 100644 --- a/src/back/device.rs +++ b/src/back/device.rs @@ -69,7 +69,7 @@ impl Device { Err(_) => { 0 } }; if input == 0 { - println!("Error: Index cannot be 0 or unknown!"); + println!("- Error: Index cannot be 0 or unknown!"); exit(1) } return Some(&v[input-1]); From ef1bfcc383c76addc58f68b73d55ff758a6bd589 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 11:54:00 +0530 Subject: [PATCH 05/13] [Fixed] Native file dialog --- Cargo.lock | 26 +++++++++++++++----------- Cargo.toml | 2 +- README.md | 8 +++----- src/back/command.rs | 34 +++++++++++++--------------------- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fefef0c..812adb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,13 +14,13 @@ name = "aow" version = "0.1.4" dependencies = [ "chrono", + "nfd", "regex", "reqwest", "serde", "serde_json", "tokio", "wait-timeout", - "wfd", ] [[package]] @@ -201,6 +201,12 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "getrandom" version = "0.1.15" @@ -520,6 +526,14 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nfd" +version = "0.0.4" +source = "git+https://github.com/saurvs/nfd-rs.git#07578c5fea4d7b1f35fbf128f04b6264c3bf3c5a" +dependencies = [ + "gcc", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1217,16 +1231,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "wfd" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e713040b67aae5bf1a0ae3e1ebba8cc29ab2b90da9aa1bff6e09031a8a41d7a8" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 6e9731e..1274814 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ tokio = { version = "0.2", features = ["full"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4.19" -wfd = "0.1.2" +nfd = { git = "https://github.com/saurvs/nfd-rs.git" } # Only change version when you are about to release because the next CI # build will automatically create a draft release & publish to chocolatey. \ No newline at end of file diff --git a/README.md b/README.md index 7964b10..24df131 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,11 @@ cargo ![CI](https://github.com/KaustubhPatange/aow/workflows/CI/badge.svg) -A command line tool written in `Rust` for adb to connect device to your machine over wifi. +A command line tool written in **Rust** for adb to connect device to your machine over wifi. -I generally made this to satisfy my purpose _"to not use a cable when debugging app in Android studio"_. The tool is still in it's early stage & will be actively developed as this is my to-go program to quickly connect a device over wifi. +On top of that it can do a lot of things (check full menu [here](https://github.com/KaustubhPatange/aow/wiki/Command-line-options)) for eg Taking a snapshot & testing deeplinks. -The program also verifies whether your device is not connected over wifi or some similar checks with _Hints_ on how to fix them. It can smartly notify you about the new version available. - -If it detects more than one device then the menu will change to "choose a device" mode. +The program is made to handle multiple connected devices & also provide some _Hints_ if any error occurs with `adb`. It can smartly notify you about the new version available. The usage of the program (after [installation](#Installation)) is pretty simple. Just connect a device > open a terminal & type `aow`. For more options read [here](https://github.com/KaustubhPatange/aow/wiki/Command-line-options). diff --git a/src/back/command.rs b/src/back/command.rs index 4df95ad..f13b1e0 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -1,9 +1,9 @@ -extern crate wfd; use crate::back::device::Device; use crate::back::connect::disconnect; use std::process::{Command, exit}; use std::path::Path; -use self::wfd::{DialogError, DialogParams}; +extern crate nfd; +use nfd::Response; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -61,26 +61,18 @@ fn take_snap(file_path: &str) { let save_path: String = if file_path != "" { String::from(file_path) } else { - // show save dialog - let params = DialogParams { - file_name: "file.png", - file_types: vec![("png", "*.png")], - title: "Choose a path to save", - ..Default::default() - }; - let result = wfd::save_dialog(params); - let path: String = match result { - Ok(file) => { - String::from(file.selected_file_path.to_str().unwrap()) - } - Err(e) => { - match e { - DialogError::HResultFailed { hresult, error_method} => { - println!("- Error: HResult Failed - HRESULT: {:X}, Method: {}", hresult, error_method); - } - DialogError::UnsupportedFilepath => { println!("- Error: Unsupported file path"); } - DialogError::UserCancelled => { } + let result1 = nfd::dialog_save().filter("png").open().unwrap_or_else(|e| { + panic!(e); + }); + let path = match result1 { + Response::Okay(file_path) => { + if !file_path.ends_with(".png") { + file_path + ".png" + } else { + file_path } + } + _ => { exit(1); } }; From ecd8b2d9a29c7c1d8a650879d247177c34bc781f Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 13:18:09 +0530 Subject: [PATCH 06/13] [Fixing] Native dialogs (windows only) --- Cargo.lock | 26 ++++++++++------------- Cargo.toml | 4 +++- src/back/command.rs | 52 +++++++++++++++++++++++++++++---------------- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 812adb1..fefef0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,13 +14,13 @@ name = "aow" version = "0.1.4" dependencies = [ "chrono", - "nfd", "regex", "reqwest", "serde", "serde_json", "tokio", "wait-timeout", + "wfd", ] [[package]] @@ -201,12 +201,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "getrandom" version = "0.1.15" @@ -526,14 +520,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "nfd" -version = "0.0.4" -source = "git+https://github.com/saurvs/nfd-rs.git#07578c5fea4d7b1f35fbf128f04b6264c3bf3c5a" -dependencies = [ - "gcc", -] - [[package]] name = "num-integer" version = "0.1.44" @@ -1231,6 +1217,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wfd" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e713040b67aae5bf1a0ae3e1ebba8cc29ab2b90da9aa1bff6e09031a8a41d7a8" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 1274814..26c5fb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,9 @@ tokio = { version = "0.2", features = ["full"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4.19" -nfd = { git = "https://github.com/saurvs/nfd-rs.git" } + +[target.'cfg(windows)'.dependencies] +wfd = "0.1.7" # Only change version when you are about to release because the next CI # build will automatically create a draft release & publish to chocolatey. \ No newline at end of file diff --git a/src/back/command.rs b/src/back/command.rs index f13b1e0..007efce 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -2,8 +2,11 @@ use crate::back::device::Device; use crate::back::connect::disconnect; use std::process::{Command, exit}; use std::path::Path; -extern crate nfd; -use nfd::Response; + +#[cfg(target_os = "windows")] +extern crate wfd; +#[cfg(target_os = "windows")] +use self::wfd::{DialogError, DialogParams}; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -61,22 +64,35 @@ fn take_snap(file_path: &str) { let save_path: String = if file_path != "" { String::from(file_path) } else { - let result1 = nfd::dialog_save().filter("png").open().unwrap_or_else(|e| { - panic!(e); - }); - let path = match result1 { - Response::Okay(file_path) => { - if !file_path.ends_with(".png") { - file_path + ".png" - } else { - file_path + // show save dialog for windows only + if cfg!(target_os="windows") { + let params = DialogParams { + file_name: "file.png", + file_types: vec![("png", "*.png")], + title: "Choose a path to save", + ..Default::default() + }; + let result = wfd::save_dialog(params); + let path: String = match result { + Ok(file) => { + String::from(file.selected_file_path.to_str().unwrap()) + } + Err(e) => { + match e { + DialogError::HResultFailed { hresult, error_method} => { + println!("- Error: HResult Failed - HRESULT: {:X}, Method: {}", hresult, error_method); + } + DialogError::UnsupportedFilepath => { println!("- Error: Unsupported file path"); } + DialogError::UserCancelled => { } + } + exit(1); } - } - _ => { - exit(1); - } - }; - path + }; + path + } else { + println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); + exit(1); + } }; Command::new("adb").arg("-s").arg(device.device_id.as_str()).arg("pull").arg("/data/local/tmp/file.png").arg(save_path.as_str()).spawn().unwrap().wait().ok(); if Path::new(save_path.as_str()).exists() { @@ -112,7 +128,7 @@ fn print_all_commands() { println!(" -v, --version Prints the current version of tool"); println!(" -h, --help Prints this help message."); println!(" snap [file-path] Take a screenshot. Optionally, you can specify a path to save it otherwise"); - println!(" the program will open native save dialog to save the file."); + println!(" the program will open native save dialog (windows only) to save the file."); println!(" dlk, deeplink [url] Fires a deeplink with the \"url\"."); println!(); println!("Examples:"); From 23ffed309580ed7e441d9f2b03537b90c0aa4b67 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 13:37:18 +0530 Subject: [PATCH 07/13] [Fixing] Native dialog --- src/back/command.rs | 32 +++++++------------------------- src/back/dialog.rs | 30 ++++++++++++++++++++++++++++++ src/back/mod.rs | 3 ++- 3 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 src/back/dialog.rs diff --git a/src/back/command.rs b/src/back/command.rs index 007efce..14b27be 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -2,11 +2,7 @@ use crate::back::device::Device; use crate::back::connect::disconnect; use std::process::{Command, exit}; use std::path::Path; - -#[cfg(target_os = "windows")] -extern crate wfd; -#[cfg(target_os = "windows")] -use self::wfd::{DialogError, DialogParams}; +use crate::back::dialog::launch_windows_save_dialog; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -66,29 +62,15 @@ fn take_snap(file_path: &str) { } else { // show save dialog for windows only if cfg!(target_os="windows") { - let params = DialogParams { - file_name: "file.png", - file_types: vec![("png", "*.png")], - title: "Choose a path to save", - ..Default::default() - }; - let result = wfd::save_dialog(params); - let path: String = match result { - Ok(file) => { - String::from(file.selected_file_path.to_str().unwrap()) + let file = match launch_windows_save_dialog() { + Ok(file_path) => { + file_path } - Err(e) => { - match e { - DialogError::HResultFailed { hresult, error_method} => { - println!("- Error: HResult Failed - HRESULT: {:X}, Method: {}", hresult, error_method); - } - DialogError::UnsupportedFilepath => { println!("- Error: Unsupported file path"); } - DialogError::UserCancelled => { } - } - exit(1); + _ => { + exit(1) } }; - path + file } else { println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); exit(1); diff --git a/src/back/dialog.rs b/src/back/dialog.rs new file mode 100644 index 0000000..e26e12c --- /dev/null +++ b/src/back/dialog.rs @@ -0,0 +1,30 @@ +#[cfg(target_os = "windows")] +extern crate wfd; +#[cfg(target_os = "windows")] +use self::wfd::{DialogError, DialogParams}; + +#[cfg(target_os = "windows")] +pub fn launch_windows_save_dialog() -> Result { + let params = DialogParams { + file_name: "file.png", + file_types: vec![("png", "*.png")], + title: "Choose a path to save", + ..Default::default() + }; + let result = wfd::save_dialog(params); + match result { + Ok(file) => { + Ok(String::from(file.selected_file_path.to_str().unwrap())) + } + Err(e) => { + match e { + DialogError::HResultFailed { hresult, error_method} => { + println!("- Error: HResult Failed - HRESULT: {:X}, Method: {}", hresult, error_method); + } + DialogError::UnsupportedFilepath => { println!("- Error: Unsupported file path"); } + DialogError::UserCancelled => { } + } + Err(()) + } + } +} \ No newline at end of file diff --git a/src/back/mod.rs b/src/back/mod.rs index a98dc1c..b869ab5 100644 --- a/src/back/mod.rs +++ b/src/back/mod.rs @@ -2,4 +2,5 @@ pub mod device; pub mod connect; pub mod command; pub mod update; -mod config; \ No newline at end of file +pub mod dialog; +mod config; From 01763fd94bc5c5c789718a8b57e126a0540f5729 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 14:10:34 +0530 Subject: [PATCH 08/13] [Fixing] Native file dialog --- src/back/command.rs | 23 +++++++++-------------- src/back/dialog.rs | 6 ++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/back/command.rs b/src/back/command.rs index 14b27be..42b5fb7 100644 --- a/src/back/command.rs +++ b/src/back/command.rs @@ -61,20 +61,15 @@ fn take_snap(file_path: &str) { String::from(file_path) } else { // show save dialog for windows only - if cfg!(target_os="windows") { - let file = match launch_windows_save_dialog() { - Ok(file_path) => { - file_path - } - _ => { - exit(1) - } - }; - file - } else { - println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); - exit(1); - } + let file = match launch_windows_save_dialog() { + Ok(file_path) => { + file_path + } + _ => { + exit(1) + } + }; + file }; Command::new("adb").arg("-s").arg(device.device_id.as_str()).arg("pull").arg("/data/local/tmp/file.png").arg(save_path.as_str()).spawn().unwrap().wait().ok(); if Path::new(save_path.as_str()).exists() { diff --git a/src/back/dialog.rs b/src/back/dialog.rs index e26e12c..f40ee0e 100644 --- a/src/back/dialog.rs +++ b/src/back/dialog.rs @@ -3,6 +3,12 @@ extern crate wfd; #[cfg(target_os = "windows")] use self::wfd::{DialogError, DialogParams}; +#[cfg(any(target_os = "linux", target_os = "mac"))] +pub fn launch_windows_save_dialog() -> Result { + println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); + Err(()) +} + #[cfg(target_os = "windows")] pub fn launch_windows_save_dialog() -> Result { let params = DialogParams { From 8d68b90f9292265c8341271c70d9bae2e8fabca2 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 14:18:56 +0530 Subject: [PATCH 09/13] [Fixing] Native dialog for mac os --- src/back/dialog.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/back/dialog.rs b/src/back/dialog.rs index f40ee0e..cfc0625 100644 --- a/src/back/dialog.rs +++ b/src/back/dialog.rs @@ -3,7 +3,7 @@ extern crate wfd; #[cfg(target_os = "windows")] use self::wfd::{DialogError, DialogParams}; -#[cfg(any(target_os = "linux", target_os = "mac"))] +#[cfg(any(target_os = "linux", target_os = "macos"))] pub fn launch_windows_save_dialog() -> Result { println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); Err(()) From d88f5569d5f90c34948cb0a8c1dab38c2c89aa1a Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 14:33:16 +0530 Subject: [PATCH 10/13] Fixing: Chocolatey CI --- .github/workflows/cd.yml | 3 ++- .github/workflows/choco.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3e2bfc9..220a74b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,6 +1,7 @@ name: CI -on: [push] +#TODO: Change this later +on: [release] jobs: release: diff --git a/.github/workflows/choco.yml b/.github/workflows/choco.yml index 6f5e12a..82fe8bf 100644 --- a/.github/workflows/choco.yml +++ b/.github/workflows/choco.yml @@ -47,7 +47,7 @@ jobs: # Create the nupkg cd choco - cpack + cpack aow.nuspec move *.nupkg aow.nupkg dir choco push aow.nupkg --source https://push.chocolatey.org/ From 7f58dfbb7591af586b9fbb4d15e839f9457b3134 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 15:03:49 +0530 Subject: [PATCH 11/13] [Fixing] Chocolatey CI --- .github/workflows/choco.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/choco.yml b/.github/workflows/choco.yml index 82fe8bf..8d0ba05 100644 --- a/.github/workflows/choco.yml +++ b/.github/workflows/choco.yml @@ -47,7 +47,7 @@ jobs: # Create the nupkg cd choco - cpack aow.nuspec + choco pack aow.nuspec move *.nupkg aow.nupkg dir choco push aow.nupkg --source https://push.chocolatey.org/ From 57796bae57d96207c2d1b6e37a45481b895757a2 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 15:38:23 +0530 Subject: [PATCH 12/13] [Experimental] Native dialogs for linux & macos --- .github/workflows/cd.yml | 3 +- Cargo.lock | 314 ++++++++++++++++++++++++++++++++++++--- Cargo.toml | 3 + src/back/dialog.rs | 12 +- 4 files changed, 310 insertions(+), 22 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 220a74b..3e2bfc9 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,7 +1,6 @@ name: CI -#TODO: Change this later -on: [release] +on: [push] jobs: release: diff --git a/Cargo.lock b/Cargo.lock index fefef0c..b7792fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,7 @@ dependencies = [ "chrono", "regex", "reqwest", + "rfd", "serde", "serde_json", "tokio", @@ -23,6 +24,18 @@ dependencies = [ "wfd", ] +[[package]] +name = "atk-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f530e4af131d94cc4fa15c5c9d0348f0ef28bac64ba660b6b2a1cf2605dedfce" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -41,6 +54,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "bumpalo" version = "3.4.0" @@ -53,6 +72,16 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "cairo-sys-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ed2639b9ad5f1d6efa76de95558e11339e7318426d84ac4890b86c03e828ca7" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "cc" version = "1.0.62" @@ -84,6 +113,21 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", + "objc", +] + [[package]] name = "core-foundation" version = "0.9.1" @@ -100,6 +144,24 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation", + "foreign-types", + "libc", +] + +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + [[package]] name = "dtoa" version = "0.4.6" @@ -201,6 +263,36 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "gdk-pixbuf-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bfe468a7f43e97b8d193a762b6c5cf67a7d36cacbc0b9291dbcae24bfea1e8f" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a9653cfc500fd268015b1ac055ddbc3df7a5c9ea3f4ccef147b3957bd140d69" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -212,6 +304,58 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "gio-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e24fb752f8f5d2cf6bbc2c606fd2bc989c81c5e2fe321ab974d54f8b6344eac" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi 0.3.9", +] + +[[package]] +name = "glib-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e9b997a66e9a23d073f2b1abb4dbfc3925e0b8952f67efd8d9b6e168e4cdc1" +dependencies = [ + "libc", + "system-deps", +] + +[[package]] +name = "gobject-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gtk-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89acda6f084863307d948ba64a4b1ef674e8527dddab147ee4cdcc194c880457" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "system-deps", +] + [[package]] name = "h2" version = "0.2.7" @@ -238,6 +382,15 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +[[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.1.17" @@ -361,9 +514,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "js-sys" -version = "0.3.45" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" +checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" dependencies = [ "wasm-bindgen", ] @@ -399,6 +552,15 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "matches" version = "0.1.8" @@ -549,6 +711,15 @@ dependencies = [ "libc", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + [[package]] name = "openssl" version = "0.10.30" @@ -582,6 +753,18 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "pango-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d2650c8b62d116c020abd0cea26a4ed96526afda89b1c4ea567131fdefc890" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -780,6 +963,27 @@ dependencies = [ "winreg", ] +[[package]] +name = "rfd" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3de7c6d5eab0f6b212d1b5a376639d91061bbfbdc2d7c7c5214063bd6ce99581" +dependencies = [ + "block", + "cocoa-foundation", + "dispatch", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "lazy_static", + "objc", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winapi 0.3.9", +] + [[package]] name = "ryu" version = "1.0.5" @@ -889,6 +1093,24 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "strum" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" + +[[package]] +name = "strum_macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "syn" version = "1.0.48" @@ -900,6 +1122,21 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "system-deps" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b" +dependencies = [ + "heck", + "pkg-config", + "strum", + "strum_macros", + "thiserror", + "toml", + "version-compare", +] + [[package]] name = "tempfile" version = "3.1.0" @@ -914,6 +1151,26 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "thiserror" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.0.1" @@ -1008,6 +1265,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.0" @@ -1078,6 +1344,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -1102,6 +1374,12 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +[[package]] +name = "version-compare" +version = "0.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" + [[package]] name = "version_check" version = "0.9.2" @@ -1141,11 +1419,11 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" +checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "serde", "serde_json", "wasm-bindgen-macro", @@ -1153,9 +1431,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" +checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" dependencies = [ "bumpalo", "lazy_static", @@ -1168,11 +1446,11 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.18" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1180,9 +1458,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" +checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1190,9 +1468,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" +checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" dependencies = [ "proc-macro2", "quote", @@ -1203,15 +1481,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.68" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" +checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" [[package]] name = "web-sys" -version = "0.3.45" +version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" +checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 26c5fb4..d50318b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,9 @@ serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4.19" +[target.'cfg(any(target_os="linux", target_os="macos"))'.dependencies] +rfd = "0.2.1" + [target.'cfg(windows)'.dependencies] wfd = "0.1.7" diff --git a/src/back/dialog.rs b/src/back/dialog.rs index cfc0625..8951079 100644 --- a/src/back/dialog.rs +++ b/src/back/dialog.rs @@ -3,10 +3,18 @@ extern crate wfd; #[cfg(target_os = "windows")] use self::wfd::{DialogError, DialogParams}; +#[cfg(any(target_os = "linux", target_os = "macos"))] +use rfd::FileDialog; + #[cfg(any(target_os = "linux", target_os = "macos"))] pub fn launch_windows_save_dialog() -> Result { - println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); - Err(()) + let file = FileDialog::new().add_filter("png", &["png"]).save_file(); + match file { + Some(buff) => { + Ok(buff.as_path().to_str().unwrap().to_owned()) + } + None => { Err(()) } + } } #[cfg(target_os = "windows")] From 7112ff86baa708ecfd6359679473fcca4d0dc375 Mon Sep 17 00:00:00 2001 From: Kaustubh Patange Date: Tue, 16 Mar 2021 16:14:45 +0530 Subject: [PATCH 13/13] [Revert] --- Cargo.lock | 278 --------------------------------------------- Cargo.toml | 3 - src/back/dialog.rs | 12 +- 3 files changed, 2 insertions(+), 291 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7792fb..c63cf18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,6 @@ dependencies = [ "chrono", "regex", "reqwest", - "rfd", "serde", "serde_json", "tokio", @@ -24,18 +23,6 @@ dependencies = [ "wfd", ] -[[package]] -name = "atk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f530e4af131d94cc4fa15c5c9d0348f0ef28bac64ba660b6b2a1cf2605dedfce" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - [[package]] name = "autocfg" version = "1.0.1" @@ -54,12 +41,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" - [[package]] name = "bumpalo" version = "3.4.0" @@ -72,16 +53,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" -[[package]] -name = "cairo-sys-rs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed2639b9ad5f1d6efa76de95558e11339e7318426d84ac4890b86c03e828ca7" -dependencies = [ - "libc", - "system-deps", -] - [[package]] name = "cc" version = "1.0.62" @@ -113,21 +84,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "cocoa-foundation" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" -dependencies = [ - "bitflags", - "block", - "core-foundation", - "core-graphics-types", - "foreign-types", - "libc", - "objc", -] - [[package]] name = "core-foundation" version = "0.9.1" @@ -144,24 +100,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" -[[package]] -name = "core-graphics-types" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" -dependencies = [ - "bitflags", - "core-foundation", - "foreign-types", - "libc", -] - -[[package]] -name = "dispatch" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" - [[package]] name = "dtoa" version = "0.4.6" @@ -263,36 +201,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "gdk-pixbuf-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bfe468a7f43e97b8d193a762b6c5cf67a7d36cacbc0b9291dbcae24bfea1e8f" -dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gdk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a9653cfc500fd268015b1ac055ddbc3df7a5c9ea3f4ccef147b3957bd140d69" -dependencies = [ - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "pkg-config", - "system-deps", -] - [[package]] name = "getrandom" version = "0.1.15" @@ -304,58 +212,6 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1", ] -[[package]] -name = "gio-sys" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e24fb752f8f5d2cf6bbc2c606fd2bc989c81c5e2fe321ab974d54f8b6344eac" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", - "winapi 0.3.9", -] - -[[package]] -name = "glib-sys" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e9b997a66e9a23d073f2b1abb4dbfc3925e0b8952f67efd8d9b6e168e4cdc1" -dependencies = [ - "libc", - "system-deps", -] - -[[package]] -name = "gobject-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c" -dependencies = [ - "glib-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gtk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89acda6f084863307d948ba64a4b1ef674e8527dddab147ee4cdcc194c880457" -dependencies = [ - "atk-sys", - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "system-deps", -] - [[package]] name = "h2" version = "0.2.7" @@ -382,15 +238,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -[[package]] -name = "heck" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.17" @@ -552,15 +399,6 @@ dependencies = [ "cfg-if 0.1.10", ] -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - [[package]] name = "matches" version = "0.1.8" @@ -711,15 +549,6 @@ dependencies = [ "libc", ] -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - [[package]] name = "openssl" version = "0.10.30" @@ -753,18 +582,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "pango-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d2650c8b62d116c020abd0cea26a4ed96526afda89b1c4ea567131fdefc890" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -963,27 +780,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "rfd" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de7c6d5eab0f6b212d1b5a376639d91061bbfbdc2d7c7c5214063bd6ce99581" -dependencies = [ - "block", - "cocoa-foundation", - "dispatch", - "glib-sys", - "gobject-sys", - "gtk-sys", - "js-sys", - "lazy_static", - "objc", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winapi 0.3.9", -] - [[package]] name = "ryu" version = "1.0.5" @@ -1093,24 +889,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "strum" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" - -[[package]] -name = "strum_macros" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "syn" version = "1.0.48" @@ -1122,21 +900,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "system-deps" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b" -dependencies = [ - "heck", - "pkg-config", - "strum", - "strum_macros", - "thiserror", - "toml", - "version-compare", -] - [[package]] name = "tempfile" version = "3.1.0" @@ -1151,26 +914,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "thiserror" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "thread_local" version = "1.0.1" @@ -1265,15 +1008,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" -dependencies = [ - "serde", -] - [[package]] name = "tower-service" version = "0.3.0" @@ -1344,12 +1078,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - [[package]] name = "unicode-xid" version = "0.2.1" @@ -1374,12 +1102,6 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" -[[package]] -name = "version-compare" -version = "0.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" - [[package]] name = "version_check" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index d50318b..26c5fb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,6 @@ serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4.19" -[target.'cfg(any(target_os="linux", target_os="macos"))'.dependencies] -rfd = "0.2.1" - [target.'cfg(windows)'.dependencies] wfd = "0.1.7" diff --git a/src/back/dialog.rs b/src/back/dialog.rs index 8951079..cfc0625 100644 --- a/src/back/dialog.rs +++ b/src/back/dialog.rs @@ -3,18 +3,10 @@ extern crate wfd; #[cfg(target_os = "windows")] use self::wfd::{DialogError, DialogParams}; -#[cfg(any(target_os = "linux", target_os = "macos"))] -use rfd::FileDialog; - #[cfg(any(target_os = "linux", target_os = "macos"))] pub fn launch_windows_save_dialog() -> Result { - let file = FileDialog::new().add_filter("png", &["png"]).save_file(); - match file { - Some(buff) => { - Ok(buff.as_path().to_str().unwrap().to_owned()) - } - None => { Err(()) } - } + println!("- Error: Native dialogs are not supported on {}", std::env::consts::OS); + Err(()) } #[cfg(target_os = "windows")]