diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 24d7cc6..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] -} diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d9c6f6e..76f6312 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3348,7 +3348,7 @@ dependencies = [ [[package]] name = "rufeed" -version = "0.3.0" +version = "0.4.0" dependencies = [ "cached", "feed-rs", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c7bea8d..87222da 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rufeed" -version = "0.3.0" -description = "A Tauri App" +version = "0.4.0" +description = "A feed reader" authors = ["Ahmed Nagi"] edition = "2021" diff --git a/src-tauri/feeds.json b/src-tauri/feeds.json deleted file mode 100644 index 3b2b617..0000000 --- a/src-tauri/feeds.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "id": "17a52b7a-cb76-4d84-bc37-110537c2f7ca", - "title": "Rust Blog", - "url": "https://blog.rust-lang.org/", - "feed_url": "https://blog.rust-lang.org/feed.xml", - "icon": "https://blog.rust-lang.org/images/apple-touch-icon.png" - }, - { - "id": "c414b24b-c429-4d56-9be5-aa2e0c042fc0", - "title": "RSS feed for os.phil-opp.com", - "url": "https://os.phil-opp.com/", - "feed_url": "https://os.phil-opp.com/rss.xml", - "icon": "https://os.phil-opp.com/favicon.ico" - }, - { - "id": "e4a39047-3c64-4beb-9622-9fd02062cff5", - "title": "عالم الكمبيوتر- RSS", - "url": "https://www.computer-wd.com/", - "feed_url": "https://www.computer-wd.com/rss.xml", - "icon": "https://www.computer-wd.com/favicon.ico" - } -] \ No newline at end of file diff --git a/src-tauri/src/client.rs b/src-tauri/src/client.rs index 5df27f2..4a04196 100644 --- a/src-tauri/src/client.rs +++ b/src-tauri/src/client.rs @@ -1,6 +1,6 @@ -use once_cell::sync::Lazy; +use std::sync::LazyLock; -pub static CLIENT: Lazy = Lazy::new(|| { +pub static CLIENT: LazyLock = LazyLock::new(|| { reqwest::Client::builder() .timeout(std::time::Duration::from_secs(20)) .connect_timeout(std::time::Duration::from_secs(10)) diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 55ba267..e51649f 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -1,21 +1,32 @@ use std::fs; use std::path::PathBuf; +use std::sync::OnceLock; use serde::{Deserialize, Serialize}; use tauri::Manager; + use crate::Error; +static CONFIG_PATH: OnceLock = OnceLock::new(); + +pub fn init_config_path(app: &tauri::AppHandle) -> Result<(), String> { + let config_dir = app.path().app_config_dir().map_err(|e| e.to_string())?; -fn get_config_path(app: &tauri::AppHandle) -> Result { - let config_dir = app.path().app_config_dir() - .map_err(|e| e.to_string())?; - - // Create dir if not exist fs::create_dir_all(&config_dir).map_err(|e| e.to_string())?; - - Ok(config_dir.join("config.json")) + + let path = config_dir.join("feeds.json"); + CONFIG_PATH + .set(path) + .map_err(|_| "Config path already initialized".to_string())?; + + Ok(()) } +fn get_feeds_path() -> Result<&'static PathBuf, Error> { + CONFIG_PATH + .get() + .ok_or_else(|| Error::MissingField("Config path not initialized".to_string())) +} pub mod feed_config { use super::*; @@ -56,7 +67,7 @@ pub mod feed_config { }; feeds.push(new_feed); let json = serde_json::to_string_pretty(&feeds)?; - fs::write("feeds.json", json)?; + fs::write(get_feeds_path()?, json)?; Ok(feeds.pop().unwrap()) } @@ -70,13 +81,13 @@ pub mod feed_config { let removed = feeds.remove(index); let json = serde_json::to_string_pretty(&feeds)?; - fs::write("feeds.json", json)?; + fs::write(get_feeds_path()?, json)?; Ok(removed) } fn get_content() -> Result, Error> { - let path = std::path::Path::new("feeds.json"); + let path = std::path::Path::new(get_feeds_path()?); if !path.exists() { fs::write(path, "[]")?; } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1d9cf76..11f5ecf 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -5,18 +5,13 @@ pub mod parser; use commands::feed::{add_feed, get_entry, get_feed_item, get_feeds, remove_feed}; -pub async fn test_thing() -> Result<(), Error> { - // match get_entry("https://blog.rust-lang.org/", "https://blog.rust-lang.org/2026/03/20/rust-challenges/").await { - // Ok(feed) => println!("{:?}", feed), - // Err(e) => eprintln!("add_feed failed: {}", e), - // } - - Ok(()) -} - #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .setup(|app| { + config::init_config_path(&app.handle())?; + Ok(()) + }) .plugin(tauri_plugin_opener::init()) .invoke_handler(tauri::generate_handler![ add_feed, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index dc01711..97cfac3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,6 +3,5 @@ #[tokio::main] async fn main() { - // rufeed_lib::test_thing().await; rufeed_lib::run() } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c32a7d6..1d46936 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,8 +1,8 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "rufeed", - "version": "0.1.0", - "identifier": "com.army.rufeed", + "version": "0.4.0", + "identifier": "com.mindfeq.rufeed", "build": { "beforeDevCommand": "pnpm dev", "devUrl": "http://localhost:1420", diff --git a/target/flycheck0/stderr b/target/flycheck0/stderr deleted file mode 100644 index c0acfbf..0000000 --- a/target/flycheck0/stderr +++ /dev/null @@ -1 +0,0 @@ -error: manifest path `/home/army/Desktop/proj/rufeed/Cargo.toml` does not exist diff --git a/target/flycheck0/stdout b/target/flycheck0/stdout deleted file mode 100644 index e69de29..0000000