定时任务,暂时屏蔽了所有警告,提交一次
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
|
# 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
|
# 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.
|
# 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"
|
utfx = "0.1.0"
|
||||||
registry = "1.3.0"
|
registry = "1.3.0"
|
||||||
anyhow = { version = "1.0.98", features = ["backtrace"] }
|
anyhow = { version = "1.0.98", features = ["backtrace"] }
|
||||||
log = "0.4.27"
|
|
||||||
env_logger = "0.11.8"
|
|
||||||
iced_fonts = { version = "0.2.1", features = ["full"] }
|
iced_fonts = { version = "0.2.1", features = ["full"] }
|
||||||
image = "0.25.6"
|
image = "0.25.6"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
@ -50,6 +48,7 @@ iced_futures = { version = "0.13.2", features = [
|
|||||||
num_enum = "0.7.4"
|
num_enum = "0.7.4"
|
||||||
trace = "0.1.7"
|
trace = "0.1.7"
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
|
log = "0.4.27"
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -92,9 +92,6 @@ impl TabContent for HomePage {
|
|||||||
HomePageMsg::CheckUpdate => {
|
HomePageMsg::CheckUpdate => {
|
||||||
info!("To check update.");
|
info!("To check update.");
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
info!("Is the message you should process ? =====>> {msg:?}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::ui::main_window::{MainWindowMsg, TabContent};
|
use crate::ui::main_window::{MainWindowMsg, TabContent};
|
||||||
|
use crate::utils::step_downloader::{self as downloader, JlcSearchResultItem};
|
||||||
|
#[allow(unused_imports)]
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use iced::{Length, Task, alignment::Horizontal, widget::Column};
|
use iced::{Length, Task, alignment::Horizontal, widget::Column};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
@ -6,12 +8,15 @@ use tracing::info;
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct JlcDownloader {
|
pub struct JlcDownloader {
|
||||||
search_word: String,
|
search_word: String,
|
||||||
|
search_results: Vec<JlcSearchResultItem>,
|
||||||
|
search_error: String,
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum JlcDownloaderMsg {
|
pub enum JlcDownloaderMsg {
|
||||||
Nothing,
|
Nothing,
|
||||||
KeywordChanged(String),
|
KeywordChanged(String),
|
||||||
KeywordSearchResult(Vec<KeywordSearchItem>),
|
KeywordSearchResult(Vec<JlcSearchResultItem>),
|
||||||
KeywordSearchError(String),
|
KeywordSearchError(String),
|
||||||
SearchPart,
|
SearchPart,
|
||||||
}
|
}
|
||||||
@ -28,10 +33,25 @@ impl TabContent for JlcDownloader {
|
|||||||
self.search_word = k;
|
self.search_word = k;
|
||||||
}
|
}
|
||||||
JlcDownloaderMsg::SearchPart => {
|
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) => {
|
||||||
info!("Whach out the msg: {msg:?}");
|
let e = format!("{e:?}");
|
||||||
|
MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchError(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
JlcDownloaderMsg::KeywordSearchResult(rest) => {
|
||||||
|
info!("JlcDownloaderMsg::KeywordSearchResult");
|
||||||
|
self.search_error.clear();
|
||||||
|
self.search_results = rest;
|
||||||
|
}
|
||||||
|
JlcDownloaderMsg::KeywordSearchError(e) => {
|
||||||
|
self.search_error = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
@ -46,43 +66,13 @@ impl TabContent for JlcDownloader {
|
|||||||
.on_press(MainWindowMsg::JlcDownloader(JlcDownloaderMsg::SearchPart)),
|
.on_press(MainWindowMsg::JlcDownloader(JlcDownloaderMsg::SearchPart)),
|
||||||
]
|
]
|
||||||
.height(Length::Shrink)
|
.height(Length::Shrink)
|
||||||
.spacing(20);
|
.spacing(40);
|
||||||
Column::new()
|
let c = Column::new()
|
||||||
.align_x(Horizontal::Left)
|
.align_x(Horizontal::Left)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.push(h)
|
.push(h);
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
return c.into();
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use crate::ui::db_browser::DbBrowserMsg;
|
use crate::ui::db_browser::DbBrowserMsg;
|
||||||
use crate::ui::home_page::HomePage;
|
use crate::ui::home_page::HomePage;
|
||||||
use crate::ui::home_page::HomePageMsg;
|
use crate::ui::home_page::HomePageMsg;
|
||||||
use crate::ui::jlc_downloader::JlcDownloader;
|
|
||||||
use crate::ui::jlc_downloader::JlcDownloaderMsg;
|
use crate::ui::jlc_downloader::JlcDownloaderMsg;
|
||||||
use crate::ui::part_viewer::PartViewerMsg;
|
use crate::ui::part_viewer::PartViewerMsg;
|
||||||
use crate::utils::step_downloader;
|
|
||||||
use iced::Subscription;
|
use iced::Subscription;
|
||||||
use iced::Task;
|
use iced::Task;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
@ -65,12 +63,6 @@ impl MainWindow {
|
|||||||
(
|
(
|
||||||
Self::default(),
|
Self::default(),
|
||||||
Task::batch([
|
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(),
|
iced::widget::focus_next(),
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
@ -98,7 +90,6 @@ pub enum MainWindowMsg {
|
|||||||
DbBrowser(DbBrowserMsg),
|
DbBrowser(DbBrowserMsg),
|
||||||
PartViewer(PartViewerMsg),
|
PartViewer(PartViewerMsg),
|
||||||
Nothing,
|
Nothing,
|
||||||
StepDownloader(step_downloader::StepDownloaderEvent),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@ -173,23 +164,21 @@ impl MainWindow {
|
|||||||
|
|
||||||
fn subscription(&self) -> Subscription<MainWindowMsg> {
|
fn subscription(&self) -> Subscription<MainWindowMsg> {
|
||||||
info!("subscription run once.");
|
info!("subscription run once.");
|
||||||
Subscription::run(step_downloader::StepDownloader::create_process)
|
iced::keyboard::on_key_press(|key, modifiers| {
|
||||||
.map(MainWindowMsg::StepDownloader)
|
info!("Press the key: {key:?}");
|
||||||
// iced::keyboard::on_key_press(|key, modifiers| {
|
info!("The modifiers: {modifiers:?}");
|
||||||
// info!("Press the key: {key:?}");
|
Some(MainWindowMsg::Nothing)
|
||||||
// info!("The modifiers: {modifiers:?}");
|
})
|
||||||
// Some(MainWindowMsg::Nothing)
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
fn create_tab_btn(&self, tab: TabId) -> Element<'_, MainWindowMsg> {
|
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
|
button::danger
|
||||||
} else {
|
} else {
|
||||||
button::primary
|
button::primary
|
||||||
};
|
};
|
||||||
let txt = format!("{tab}");
|
let txt = format!("{tab}");
|
||||||
let txt = iced::widget::text(txt);
|
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()
|
btn.on_press(MainWindowMsg::TabSelected(tab)).into()
|
||||||
}
|
}
|
||||||
fn update(&mut self, msg: MainWindowMsg) -> Task<MainWindowMsg> {
|
fn update(&mut self, msg: MainWindowMsg) -> Task<MainWindowMsg> {
|
||||||
@ -226,10 +215,6 @@ impl MainWindow {
|
|||||||
MainWindowMsg::SearchKeywordChanged(k) => self
|
MainWindowMsg::SearchKeywordChanged(k) => self
|
||||||
.jlc_downloader
|
.jlc_downloader
|
||||||
.update(JlcDownloaderMsg::KeywordChanged(k)),
|
.update(JlcDownloaderMsg::KeywordChanged(k)),
|
||||||
MainWindowMsg::StepDownloader(msg) => {
|
|
||||||
info!("StepDownloaderEvent: {msg:?}");
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn view(&self) -> Element<'_, MainWindowMsg> {
|
fn view(&self) -> Element<'_, MainWindowMsg> {
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UiCmd {
|
pub enum UiCmd {
|
||||||
Repaint,
|
Repaint,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
#[allow(dead_code)]
|
||||||
static ref UiBroadcast: broadcast::Sender<UiCmd> = {
|
static ref UiBroadcast: broadcast::Sender<UiCmd> = {
|
||||||
let (tx, _) = broadcast::channel(10);
|
let (tx, _) = broadcast::channel(10);
|
||||||
tx
|
tx
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_ui_broadcast_sender() -> broadcast::Sender<UiCmd> {
|
pub fn get_ui_broadcast_sender() -> broadcast::Sender<UiCmd> {
|
||||||
UiBroadcast.clone()
|
UiBroadcast.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_ui_broadcast_receiver() -> broadcast::Receiver<UiCmd> {
|
pub fn get_ui_broadcast_receiver() -> broadcast::Receiver<UiCmd> {
|
||||||
UiBroadcast.subscribe()
|
UiBroadcast.subscribe()
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,16 @@
|
|||||||
use log::info;
|
#[allow(unused_imports)]
|
||||||
use std::time::Duration;
|
use tracing::{error, info, warn};
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
use iced::task::{Never, Sipper, sipper};
|
#[derive(Debug,Clone,Eq,PartialEq)]
|
||||||
pub struct StepDownloader {
|
pub struct JlcSearchResultItem{
|
||||||
nothing: String,
|
pub chip_name:String,
|
||||||
|
pub imgs_url:Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
pub async fn search_keyword(keyword:String)->Result<Vec<JlcSearchResultItem>>{
|
||||||
pub enum StepDownloaderMsg {
|
if keyword.is_empty(){
|
||||||
Nothing,
|
return Err(anyhow::anyhow!("No keyword found"));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
Err(anyhow::Error::msg("Search error"))
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user