diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 1c27a02..2a62ca0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1088,7 +1088,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "e-z-uploader" -version = "2.0.2" +version = "2.0.4" dependencies = [ "arboard", "confy", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 79bda72..2574143 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "e-z-uploader" -version = "2.0.2" +version = "2.0.4" description = "E-Z screenshot uploader" authors = ["imyanice"] license = "GPL-v3" @@ -43,4 +43,4 @@ codegen-units = 1 # Compile crates one after another so the compiler can optimiz lto = true # Enables link to optimizations opt-level = "s" # Optimize for binary size strip = true # Strip unneeded stuff - +debug = "full" diff --git a/src-tauri/src/listeners.rs b/src-tauri/src/listeners.rs index b6d15c7..e096644 100755 --- a/src-tauri/src/listeners.rs +++ b/src-tauri/src/listeners.rs @@ -1,4 +1,4 @@ -use notify::event::{CreateKind}; +use notify::event::{ModifyKind, RenameMode}; use notify::{Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher}; use std::sync::mpsc::channel; @@ -22,7 +22,8 @@ pub fn watch_file_system(app: tauri::AppHandle) { for res in &rx { match res { Ok(event) => { - if event.kind == EventKind::Create(CreateKind::File) + println!("{:?}", event); + if (event.kind != EventKind::Modify(ModifyKind::Name(RenameMode::Any))) && last_image != event.paths[0].to_str().unwrap() && files::is_image(&event.paths[0]) { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7d8dfdc..3c5ce14 100755 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -10,12 +10,12 @@ mod listeners; mod upload; mod utils; -use std::thread; +use crate::utils::get_screenshot_dir; use sentry::User; -use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; +use std::thread; use tauri::regex::Regex; +use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; use tauri_plugin_autostart::MacosLauncher; -use crate::utils::get_screenshot_dir; fn main() { let _guard = sentry::init(("", sentry::ClientOptions { @@ -73,7 +73,6 @@ fn main() { ..Default::default() }); } - } sentry::configure_scope(|scope| { scope.set_user(user.clone()); @@ -113,7 +112,6 @@ fn main() { } } }); - } fn get_system_tray() -> SystemTray { diff --git a/src-tauri/src/upload.rs b/src-tauri/src/upload.rs index 08e9ff4..dc7cf48 100755 --- a/src-tauri/src/upload.rs +++ b/src-tauri/src/upload.rs @@ -52,6 +52,8 @@ pub fn upload_file_to_host(file: &Path, app_handle: &tauri::AppHandle) { ); return; } + // sentry::capture_message(file.to_str().unwrap(), Level::Info); + match Part::file(file) { Ok(part_file) => { let client = Client::builder() @@ -63,9 +65,12 @@ pub fn upload_file_to_host(file: &Path, app_handle: &tauri::AppHandle) { .header("key", config.api_key) .multipart(Form::new().part("file", part_file)) .send(); + // sentry::capture_message("Request has been sent", Level::Info); match request { Ok(data) => { + // sentry::capture_message("The data is ok", Level::Info); + match data.status() { reqwest::StatusCode::OK => { let response = data @@ -74,18 +79,17 @@ pub fn upload_file_to_host(file: &Path, app_handle: &tauri::AppHandle) { let mut clipboard = Clipboard::new().unwrap(); let url = response.imageUrl.clone(); match clipboard.set_text(response.imageUrl) { - Ok {..} => { + Ok { .. } => { if !config.auto_wipe { add_file_data(app_handle, file, response.deletionUrl, url) }; utils::add_int_to_uploaded_files(app_handle); display_successful_notification(app_handle); - }, - Err (err) => { + } + Err(err) => { display_error_message(app_handle); sentry::capture_error(&err); } - }; } reqwest::StatusCode::UNAUTHORIZED => { @@ -103,18 +107,18 @@ pub fn upload_file_to_host(file: &Path, app_handle: &tauri::AppHandle) { display_no_internet_notification(app_handle); } } - }, - Err(_) => println!("file doesnt exist") + } + Err(_) => { + // sentry::capture_message("A file did not exist", Level::Info); + println!("file doesnt exist") + } } - if config.auto_wipe { delete_file(file); } - } - fn display_successful_notification(app_handle: &tauri::AppHandle) { Notification::new(app_handle.config().tauri.bundle.identifier.clone()) .title("File Uploaded!") @@ -145,40 +149,38 @@ fn add_file_data(app_handle: &AppHandle, file_path: &Path, deletion_url: String, .unwrap() .join("uploaded_files.json"); match fs::read_to_string(&path) { - Ok(cfg) => { - match file_path.symlink_metadata() { - Ok(file_meta) => { - let mut json: Vec = serde_json::from_str(cfg.as_str()).unwrap(); - json.push(UploadedFile { - path: file_path.as_os_str().to_str().unwrap().to_string(), - deletion_url, - name: file_path.file_name().unwrap().to_str().unwrap().to_string(), - size: file_meta.len() as i64, - url, - }); - let s = serde_json::to_string(&json).unwrap().to_string(); - File::create(&path) - .unwrap() - .write_all(s.as_ref()) - .expect("TODO: panic message");} - Err(_) => { - let mut json: Vec = serde_json::from_str(cfg.as_str()).unwrap(); - json.push(UploadedFile { - path: file_path.as_os_str().to_str().unwrap().to_string(), - deletion_url, - name: file_path.file_name().unwrap().to_str().unwrap().to_string(), - size: 0i64, - url, - }); - let s = serde_json::to_string(&json).unwrap().to_string(); - File::create(&path) - .unwrap() - .write_all(s.as_ref()) - .expect("TODO: panic message"); - } + Ok(cfg) => match file_path.symlink_metadata() { + Ok(file_meta) => { + let mut json: Vec = serde_json::from_str(cfg.as_str()).unwrap(); + json.push(UploadedFile { + path: file_path.as_os_str().to_str().unwrap().to_string(), + deletion_url, + name: file_path.file_name().unwrap().to_str().unwrap().to_string(), + size: file_meta.len() as i64, + url, + }); + let s = serde_json::to_string(&json).unwrap().to_string(); + File::create(&path) + .unwrap() + .write_all(s.as_ref()) + .expect("TODO: panic message"); } - - } + Err(_) => { + let mut json: Vec = serde_json::from_str(cfg.as_str()).unwrap(); + json.push(UploadedFile { + path: file_path.as_os_str().to_str().unwrap().to_string(), + deletion_url, + name: file_path.file_name().unwrap().to_str().unwrap().to_string(), + size: 0i64, + url, + }); + let s = serde_json::to_string(&json).unwrap().to_string(); + File::create(&path) + .unwrap() + .write_all(s.as_ref()) + .expect("TODO: panic message"); + } + }, Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => { File::create(&path) .unwrap() @@ -189,4 +191,4 @@ fn add_file_data(app_handle: &AppHandle, file_path: &Path, deletion_url: String, sentry::capture_error(&err); } } -} \ No newline at end of file +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index fa7de25..cec34ad 100755 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "E-Z Uploader", - "version": "2.0.2" + "version": "2.0.4" }, "tauri": { "allowlist": {