定时任务,暂时屏蔽了所有警告,提交一次
This commit is contained in:
parent
06549c35ab
commit
3a7b0f22a8
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
@ -92,9 +92,6 @@ impl TabContent for HomePage {
|
||||
HomePageMsg::CheckUpdate => {
|
||||
info!("To check update.");
|
||||
}
|
||||
_ => {
|
||||
info!("Is the message you should process ? =====>> {msg:?}");
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
@ -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<JlcSearchResultItem>,
|
||||
search_error: String,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum JlcDownloaderMsg {
|
||||
Nothing,
|
||||
KeywordChanged(String),
|
||||
KeywordSearchResult(Vec<KeywordSearchItem>),
|
||||
KeywordSearchResult(Vec<JlcSearchResultItem>),
|
||||
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<Vec<KeywordSearchItem>> {
|
||||
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<Vec<KeywordSearchItem>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
pub async fn fetch_item_images(
|
||||
item: &KeywordSearchItem,
|
||||
) -> Result<Vec<iced::widget::image::Handle>> {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
|
||||
Ok(Vec::new())
|
||||
return c.into();
|
||||
}
|
||||
}
|
||||
|
@ -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<MainWindowMsg> {
|
||||
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<MainWindowMsg> {
|
||||
@ -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> {
|
||||
|
@ -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<UiCmd> = {
|
||||
let (tx, _) = broadcast::channel(10);
|
||||
tx
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_ui_broadcast_sender() -> broadcast::Sender<UiCmd> {
|
||||
UiBroadcast.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn get_ui_broadcast_receiver() -> broadcast::Receiver<UiCmd> {
|
||||
UiBroadcast.subscribe()
|
||||
}
|
||||
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[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<Never, StepDownloaderEvent> {
|
||||
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<Vec<JlcSearchResultItem>>{
|
||||
if keyword.is_empty(){
|
||||
return Err(anyhow::anyhow!("No keyword found"));
|
||||
}
|
||||
}
|
||||
Err(anyhow::Error::msg("Search error"))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user