diff --git a/crates/lcode/src/app/impl_app/get_info.rs b/crates/lcode/src/app/impl_app/get_info.rs index 129b1f6..e2ad987 100644 --- a/crates/lcode/src/app/impl_app/get_info.rs +++ b/crates/lcode/src/app/impl_app/get_info.rs @@ -39,8 +39,12 @@ impl<'app> App<'app> { .await; let avatar_path = avatar_path - .as_os_str() - .to_str() + .as_ref() + .map(|v| { + v.as_os_str() + .to_str() + .unwrap_or_default() + }) .unwrap_or_default(); if res_cn.checkin_ok() { Notification::new() @@ -102,7 +106,7 @@ impl<'app> App<'app> { pub fn get_status_done( &mut self, - info: (UserStatus, TotalPoints, PassData, PathBuf), + info: (UserStatus, TotalPoints, PassData, Option), ) -> miette::Result<()> { ( self.info.user_status, @@ -111,7 +115,7 @@ impl<'app> App<'app> { self.info.avatar_path, ) = info; - if self.img_state.is_none() { + if self.img_state.is_none() && self.info.avatar_path.is_some() { #[cfg(not(target_os = "windows"))] let mut picker = Picker::from_termios().or(Err(miette::miette!("Image Picker error")))?; @@ -120,13 +124,18 @@ impl<'app> App<'app> { picker.guess_protocol(); picker.background_color = Some(Rgb::([255, 0, 255])); - let dyn_img = image::ImageReader::open(&self.info.avatar_path) - .into_diagnostic()? - .with_guessed_format() - .into_diagnostic()? - .decode() - .into_diagnostic()? - .resize_to_fill(150, 150, ratatui_image::FilterType::Triangle); + let dyn_img = image::ImageReader::open( + self.info + .avatar_path + .as_ref() + .expect("No avatar file"), + ) + .into_diagnostic()? + .with_guessed_format() + .into_diagnostic()? + .decode() + .into_diagnostic()? + .resize_to_fill(150, 150, ratatui_image::FilterType::Triangle); // Send a [ResizeProtocol] to resize and encode it in a separate thread. let (tx_worker, rec_worker) = diff --git a/crates/lcode/src/app/info/mod.rs b/crates/lcode/src/app/info/mod.rs index 37711c6..69453ef 100644 --- a/crates/lcode/src/app/info/mod.rs +++ b/crates/lcode/src/app/info/mod.rs @@ -17,7 +17,7 @@ pub struct Info<'tab3> { pub points: TotalPoints, pub pass_data: PassData, - pub avatar_path: PathBuf, + pub avatar_path: Option, } // keymaps diff --git a/crates/leetcode-api/src/leetcode/impl_lc/user_info.rs b/crates/leetcode-api/src/leetcode/impl_lc/user_info.rs index 3999eca..d61144f 100644 --- a/crates/leetcode-api/src/leetcode/impl_lc/user_info.rs +++ b/crates/leetcode-api/src/leetcode/impl_lc/user_info.rs @@ -26,11 +26,8 @@ use crate::{ // some info impl LeetCode { /// download user avatar image - pub async fn dow_user_avator(&self, status: &UserStatus) -> PathBuf { - let avatar_url = status - .avatar - .as_deref() - .unwrap_or_default(); + pub async fn dow_user_avator(&self, status: &UserStatus) -> Option { + let avatar_url = status.avatar.as_deref()?; let mut avatar_path = G_CACHE_DIR.clone(); if let Ok(url) = Url::parse(avatar_url) { if let Some(url_path) = url.path_segments() { @@ -58,7 +55,7 @@ impl LeetCode { } } } - avatar_path + Some(avatar_path) } pub async fn pass_qs_status(&self, user_slug: &str) -> Result { let json = GraphqlQuery::pass_status(user_slug);