Skip to content

Commit

Permalink
fix: macos sreenshot app tempfile + 2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
imyanice committed May 19, 2024
1 parent 13ce548 commit 41b0923
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
5 changes: 3 additions & 2 deletions src-tauri/src/listeners.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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])
{
Expand Down
8 changes: 3 additions & 5 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,7 +73,6 @@ fn main() {
..Default::default()
});
}

}
sentry::configure_scope(|scope| {
scope.set_user(user.clone());
Expand Down Expand Up @@ -113,7 +112,6 @@ fn main() {
}
}
});

}

fn get_system_tray() -> SystemTray {
Expand Down
88 changes: 45 additions & 43 deletions src-tauri/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 => {
Expand All @@ -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!")
Expand Down Expand Up @@ -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<UploadedFile> = 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<UploadedFile> = 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<UploadedFile> = 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<UploadedFile> = 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()
Expand All @@ -189,4 +191,4 @@ fn add_file_data(app_handle: &AppHandle, file_path: &Path, deletion_url: String,
sentry::capture_error(&err);
}
}
}
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "E-Z Uploader",
"version": "2.0.2"
"version": "2.0.4"
},
"tauri": {
"allowlist": {
Expand Down

0 comments on commit 41b0923

Please sign in to comment.