From 3a7b0f22a881c9279a7c021c7d137fcb1d00cfdc Mon Sep 17 00:00:00 2001 From: z_lenovo Date: Sat, 28 Jun 2025 23:53:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=B1=8F=E8=94=BD=E4=BA=86=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=EF=BC=8C=E6=8F=90=E4=BA=A4=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- Cargo.toml | 3 +- src/ui/home_page.rs | 3 -- src/ui/jlc_downloader.rs | 66 +++++++++++++++--------------------- src/ui/main_window.rs | 29 ++++------------ src/utils/lazy.rs | 4 +++ src/utils/step_downloader.rs | 45 +++++++----------------- 7 files changed, 54 insertions(+), 99 deletions(-) diff --git a/.gitignore b/.gitignore index 025ba1e..66aef7b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ Cargo.lock # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea + diff --git a/Cargo.toml b/Cargo.toml index 05cede9..47d408f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,6 @@ tracing-subscriber = { version = "0.3.19", features = [ utfx = "0.1.0" registry = "1.3.0" anyhow = { version = "1.0.98", features = ["backtrace"] } -log = "0.4.27" -env_logger = "0.11.8" iced_fonts = { version = "0.2.1", features = ["full"] } image = "0.25.6" lazy_static = "1.5.0" @@ -50,6 +48,7 @@ iced_futures = { version = "0.13.2", features = [ num_enum = "0.7.4" trace = "0.1.7" tracing = "0.1.41" +log = "0.4.27" [build-dependencies] diff --git a/src/ui/home_page.rs b/src/ui/home_page.rs index ffe560b..2705442 100644 --- a/src/ui/home_page.rs +++ b/src/ui/home_page.rs @@ -92,9 +92,6 @@ impl TabContent for HomePage { HomePageMsg::CheckUpdate => { info!("To check update."); } - _ => { - info!("Is the message you should process ? =====>> {msg:?}"); - } } Task::none() } diff --git a/src/ui/jlc_downloader.rs b/src/ui/jlc_downloader.rs index 90071fe..4f81a75 100644 --- a/src/ui/jlc_downloader.rs +++ b/src/ui/jlc_downloader.rs @@ -1,4 +1,6 @@ use crate::ui::main_window::{MainWindowMsg, TabContent}; +use crate::utils::step_downloader::{self as downloader, JlcSearchResultItem}; +#[allow(unused_imports)] use anyhow::Result; use iced::{Length, Task, alignment::Horizontal, widget::Column}; use tracing::info; @@ -6,12 +8,15 @@ use tracing::info; #[derive(Default)] pub struct JlcDownloader { search_word: String, + search_results: Vec, + search_error: String, } +#[allow(dead_code)] #[derive(Debug, Clone, Eq, PartialEq)] pub enum JlcDownloaderMsg { Nothing, KeywordChanged(String), - KeywordSearchResult(Vec), + KeywordSearchResult(Vec), KeywordSearchError(String), SearchPart, } @@ -28,10 +33,25 @@ impl TabContent for JlcDownloader { self.search_word = k; } JlcDownloaderMsg::SearchPart => { - info!("Clicked Search"); + return Task::perform(downloader::search_keyword(self.search_word.clone()), |x| { + match x { + Ok(v) => { + MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchResult(v)) + } + Err(e) => { + let e = format!("{e:?}"); + MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchError(e)) + } + } + }); } - _ => { - info!("Whach out the msg: {msg:?}"); + JlcDownloaderMsg::KeywordSearchResult(rest) => { + info!("JlcDownloaderMsg::KeywordSearchResult"); + self.search_error.clear(); + self.search_results = rest; + } + JlcDownloaderMsg::KeywordSearchError(e) => { + self.search_error = e; } } Task::none() @@ -46,43 +66,13 @@ impl TabContent for JlcDownloader { .on_press(MainWindowMsg::JlcDownloader(JlcDownloaderMsg::SearchPart)), ] .height(Length::Shrink) - .spacing(20); - Column::new() + .spacing(40); + let c = Column::new() .align_x(Horizontal::Left) .width(Length::Fill) .height(Length::Fill) - .push(h) - .into() - } -} + .push(h); -#[derive(Clone, PartialEq, Eq, Debug)] -pub struct KeywordSearchItem { - name: String, -} -impl JlcDownloader { - pub async fn search_keyword(keyword: &str) -> Result> { - if keyword.is_empty() { - tokio::time::sleep(tokio::time::Duration::from_secs(1)); - info!("The keyword is empty."); - return Err(anyhow::Error::msg( - "Please insert the keyword before search", - )); - } - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; - for i in 0..10 { - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; - info!("In async search_keyword print tick {i}"); - } - Ok(Vec::new()) - } - pub async fn keyword_search_task() -> Result> { - Ok(Vec::new()) - } - pub async fn fetch_item_images( - item: &KeywordSearchItem, - ) -> Result> { - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; - Ok(Vec::new()) + return c.into(); } } diff --git a/src/ui/main_window.rs b/src/ui/main_window.rs index fc27702..15957ea 100644 --- a/src/ui/main_window.rs +++ b/src/ui/main_window.rs @@ -1,10 +1,8 @@ use crate::ui::db_browser::DbBrowserMsg; use crate::ui::home_page::HomePage; use crate::ui::home_page::HomePageMsg; -use crate::ui::jlc_downloader::JlcDownloader; use crate::ui::jlc_downloader::JlcDownloaderMsg; use crate::ui::part_viewer::PartViewerMsg; -use crate::utils::step_downloader; use iced::Subscription; use iced::Task; use tracing::info; @@ -65,12 +63,6 @@ impl MainWindow { ( Self::default(), Task::batch([ - Task::perform(JlcDownloader::search_keyword(""), |x| match x { - Ok(v) => MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchResult(v)), - Err(e) => MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchError( - format!("{e:?}"), - )), - }), iced::widget::focus_next(), ]), ) @@ -98,7 +90,6 @@ pub enum MainWindowMsg { DbBrowser(DbBrowserMsg), PartViewer(PartViewerMsg), Nothing, - StepDownloader(step_downloader::StepDownloaderEvent), } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -173,23 +164,21 @@ impl MainWindow { fn subscription(&self) -> Subscription { info!("subscription run once."); - Subscription::run(step_downloader::StepDownloader::create_process) - .map(MainWindowMsg::StepDownloader) - // iced::keyboard::on_key_press(|key, modifiers| { - // info!("Press the key: {key:?}"); - // info!("The modifiers: {modifiers:?}"); - // Some(MainWindowMsg::Nothing) - // }) + iced::keyboard::on_key_press(|key, modifiers| { + info!("Press the key: {key:?}"); + info!("The modifiers: {modifiers:?}"); + Some(MainWindowMsg::Nothing) + }) } fn create_tab_btn(&self, tab: TabId) -> Element<'_, MainWindowMsg> { - let bstyle = if self.curr_tab == tab { + let btn_style = if self.curr_tab == tab { button::danger } else { button::primary }; let txt = format!("{tab}"); let txt = iced::widget::text(txt); - let btn = button(txt).style(bstyle); + let btn = button(txt).style(btn_style); btn.on_press(MainWindowMsg::TabSelected(tab)).into() } fn update(&mut self, msg: MainWindowMsg) -> Task { @@ -226,10 +215,6 @@ impl MainWindow { MainWindowMsg::SearchKeywordChanged(k) => self .jlc_downloader .update(JlcDownloaderMsg::KeywordChanged(k)), - MainWindowMsg::StepDownloader(msg) => { - info!("StepDownloaderEvent: {msg:?}"); - Task::none() - } } } fn view(&self) -> Element<'_, MainWindowMsg> { diff --git a/src/utils/lazy.rs b/src/utils/lazy.rs index a9b7827..55599b2 100644 --- a/src/utils/lazy.rs +++ b/src/utils/lazy.rs @@ -1,22 +1,26 @@ use lazy_static::lazy_static; use tokio::sync::broadcast; +#[allow(dead_code)] #[derive(Debug, Clone)] pub enum UiCmd { Repaint, } lazy_static! { +#[allow(dead_code)] static ref UiBroadcast: broadcast::Sender = { let (tx, _) = broadcast::channel(10); tx }; } +#[allow(dead_code)] pub fn get_ui_broadcast_sender() -> broadcast::Sender { UiBroadcast.clone() } +#[allow(dead_code)] pub fn get_ui_broadcast_receiver() -> broadcast::Receiver { UiBroadcast.subscribe() } diff --git a/src/utils/step_downloader.rs b/src/utils/step_downloader.rs index 4fdb8e0..5061a5e 100644 --- a/src/utils/step_downloader.rs +++ b/src/utils/step_downloader.rs @@ -1,37 +1,16 @@ -use log::info; -use std::time::Duration; +#[allow(unused_imports)] +use tracing::{error, info, warn}; +use anyhow::Result; -use iced::task::{Never, Sipper, sipper}; -pub struct StepDownloader { - nothing: String, +#[derive(Debug,Clone,Eq,PartialEq)] +pub struct JlcSearchResultItem{ + pub chip_name:String, + pub imgs_url:Vec, } -#[derive(Debug, PartialEq, Eq, Clone)] -pub enum StepDownloaderMsg { - Nothing, - SearchKeyword(String), -} -#[derive(Debug, Clone)] -pub enum StepDownloaderEvent { - Nothing, -} - -impl StepDownloader { - pub fn create_process() -> impl Sipper { - info!("Start create the process."); - sipper(async |mut output| { - loop { - output.send(StepDownloaderEvent::Nothing).await; - info!("In process print once."); - - loop { - info!("In process print tick A."); - tokio::time::sleep(Duration::from_millis(1000)).await; - // output.send(StepDownloaderEvent::Nothing).await; - info!("In process print tick A."); - tokio::time::sleep(Duration::from_millis(1000)).await; - } - } - }) +pub async fn search_keyword(keyword:String)->Result>{ + if keyword.is_empty(){ + return Err(anyhow::anyhow!("No keyword found")); } -} + Err(anyhow::Error::msg("Search error")) +} \ No newline at end of file