From cf14625ac5ffc369fd22de4b80db32046dd2dbe0 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Sat, 17 Aug 2024 13:33:07 -0600 Subject: [PATCH] fix release profile --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/engines/ultralight.rs | 8 ++++++-- src/lib.rs | 40 --------------------------------------- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eacf172..fca3e6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -703,6 +703,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_home" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" + [[package]] name = "equivalent" version = "1.0.1" @@ -1564,6 +1570,7 @@ name = "icy_browser" version = "0.1.0" dependencies = [ "cmake", + "env_home", "iced", "iced_aw", "iced_on_focus_widget", diff --git a/Cargo.toml b/Cargo.toml index 3ce9b2a..2c1c1d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ ultralight = ["ul-next"] # iced_core = { git = "https://github.com/iced-rs/iced", rev = "6734d183594ebf89b8e6c030ea69d53ecb6b72db" } [dependencies] +env_home = "0.1.0" iced = { version = "0.12.*", features = ["advanced", "image", "tokio", "lazy"]} iced_aw = { version = "0.9.3", features = ["tab_bar", "icons"] } iced_on_focus_widget = "0.1.0" diff --git a/src/engines/ultralight.rs b/src/engines/ultralight.rs index 861696c..2212f59 100644 --- a/src/engines/ultralight.rs +++ b/src/engines/ultralight.rs @@ -15,6 +15,9 @@ use ul_next::{ }; use url::Url; +#[cfg(not(debug_assertions))] +use env_home::env_home_dir; + use super::{BrowserEngine, PixelFormat}; struct UlLogger; @@ -56,8 +59,9 @@ impl Ultralight { platform::enable_platform_fontloader(); #[cfg(not(debug_assertions))] - let mut home_dir = home_dir().unwrap(); - + let mut home_dir = env_home_dir().unwrap(); + #[cfg(not(debug_assertions))] + home_dir.push(".icy_browser"); #[cfg(not(debug_assertions))] platform::enable_platform_filesystem(home_dir.as_path()).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 45496ef..d25df0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,4 @@ use iced::widget::image::{Handle, Image}; -use std::fs::{remove_file, File}; -use std::io::{self, copy, Write}; - -use std::path::PathBuf; -use tempfile::Builder; use url::{ParseError, Url}; mod engines; @@ -61,41 +56,6 @@ impl ImageInfo { } } -fn copy_bytes_to_file(name: &str, bytes: &[u8], mut path: PathBuf) -> Result<(), io::Error> { - path.push(name); - let _ = remove_file(path.clone()); // file already exists - let mut file = std::fs::File::create(&path)?; - file.write_all(&bytes[..])?; - Ok(()) -} - -// This function has to be called in a iced Command/Task future -// if path is false, its downloaded to a temp dir -async fn download_file(path: Option, url: &str) -> Option<()> { - let tmp_dir = Builder::new().prefix("Rust-Browser_Cache").tempdir().ok()?; - let response = reqwest::get(url).await.ok()?; - - let mut dest = { - let fname = response - .url() - .path_segments() - .and_then(|segments| segments.last()) - .and_then(|name| if name.is_empty() { None } else { Some(name) }) - .unwrap_or("tmp.bin"); - - let path = match path { - Some(path) => tmp_dir.path().join(path), - None => tmp_dir.path().join(fname), - }; - - File::create(path).ok()? - }; - - let content = response.text().await.ok()?; - copy(&mut content.as_bytes(), &mut dest).ok()?; - Some(()) -} - fn to_url(url: &str) -> Option { match Url::parse(url) { Ok(url) => Some(url),