添加测试结束后颜色显示, 方便判断, 修复部分Bug
This commit is contained in:
parent
85939e7fc4
commit
410a2ad5e1
@ -204,7 +204,7 @@ impl DownloadWrapper {
|
||||
}
|
||||
|
||||
fn save_log(& self, label: String, log: String) -> Result<bool, DownloadError> {
|
||||
if !fs::exists("./log") {
|
||||
if !fs::exists("./log").unwrap() {
|
||||
fs::create_dir("./log").expect("Cant Create Log Folder");
|
||||
}
|
||||
let mut file = fs::OpenOptions::new()
|
||||
|
66
src/main.rs
66
src/main.rs
@ -6,15 +6,18 @@ use crossbeam::channel;
|
||||
use crossbeam::channel::Sender;
|
||||
use download_wrapper::DownloadType;
|
||||
use iced::application::Title;
|
||||
use iced::widget::progress_bar::Style;
|
||||
use iced::widget::text_editor::Action::Scroll;
|
||||
use iced::widget::text_editor::Edit;
|
||||
use iced::widget::{button, checkbox, column, container, radio, row, text_editor, text_input};
|
||||
use iced::{event, time, window, Element, Event, Length, Subscription, Task};
|
||||
use iced::widget::{
|
||||
button, checkbox, column, container, progress_bar, radio, row, text_editor, text_input,
|
||||
};
|
||||
use iced::{event, time, window, Background, Border, Color, Element, Event, Length, Subscription, Task};
|
||||
use serde_json::Map;
|
||||
use std::any::Any;
|
||||
use std::fs;
|
||||
use std::sync::{Arc, LazyLock, Mutex};
|
||||
use std::io::Write;
|
||||
use std::sync::{Arc, LazyLock, Mutex};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application("WisunDownload V0.1", MainWindow::update, MainWindow::view)
|
||||
@ -24,7 +27,7 @@ pub fn main() -> iced::Result {
|
||||
.run()
|
||||
}
|
||||
|
||||
static logs: LazyLock<Arc<Mutex<Vec<String>>>> = LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
static LOGS: LazyLock<Arc<Mutex<Vec<String>>>> = LazyLock::new(|| Arc::new(Mutex::new(Vec::new())));
|
||||
|
||||
struct MainWindow {
|
||||
is_online: bool,
|
||||
@ -34,6 +37,7 @@ struct MainWindow {
|
||||
log_content: text_editor::Content,
|
||||
sender: Sender<Message>,
|
||||
receiver: channel::Receiver<Message>,
|
||||
result_background: Color
|
||||
}
|
||||
|
||||
impl Default for MainWindow {
|
||||
@ -45,6 +49,7 @@ impl Default for MainWindow {
|
||||
selection: None,
|
||||
label: String::new(),
|
||||
log_content: text_editor::Content::default(),
|
||||
result_background: Color::from_rgb8(255,255,255),
|
||||
sender,
|
||||
receiver,
|
||||
}
|
||||
@ -75,7 +80,7 @@ enum Message {
|
||||
AddLog(String),
|
||||
LogContentChanged(text_editor::Action),
|
||||
SaveConfig,
|
||||
DownloadEnd((String,bool)),
|
||||
DownloadEnd((String, bool)),
|
||||
WindowEvent(Event),
|
||||
ClearLog,
|
||||
Tick,
|
||||
@ -84,13 +89,14 @@ enum Message {
|
||||
pub fn add_log<'a>(msg: String) {
|
||||
let time_now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||
let really_msg = format!("{time_now} [Info]: {msg}");
|
||||
logs.lock().unwrap().push(really_msg);
|
||||
LOGS.lock().unwrap().push(really_msg);
|
||||
}
|
||||
|
||||
impl MainWindow {
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Start() => {
|
||||
self.result_background = Color::from_rgb8(255,255,255);
|
||||
self.start(self.sender.clone());
|
||||
Task::none()
|
||||
}
|
||||
@ -130,9 +136,10 @@ impl MainWindow {
|
||||
self.is_online = is_online;
|
||||
Task::none()
|
||||
}
|
||||
Message::ClearLog =>{
|
||||
Message::ClearLog => {
|
||||
self.log_content.perform(text_editor::Action::SelectAll);
|
||||
self.log_content.perform(text_editor::Action::Edit(Edit::Delete));
|
||||
self.log_content
|
||||
.perform(text_editor::Action::Edit(Edit::Backspace));
|
||||
Task::none()
|
||||
}
|
||||
Message::AddLog(log) => {
|
||||
@ -149,7 +156,7 @@ impl MainWindow {
|
||||
Task::none()
|
||||
}
|
||||
Message::Tick => {
|
||||
for log in logs.lock().unwrap().iter() {
|
||||
for log in LOGS.lock().unwrap().iter() {
|
||||
for c in log.chars() {
|
||||
self.log_content
|
||||
.perform(text_editor::Action::Edit(Edit::Insert(c)))
|
||||
@ -161,7 +168,7 @@ impl MainWindow {
|
||||
lines: line_size as i32,
|
||||
});
|
||||
}
|
||||
logs.lock().unwrap().clear();
|
||||
LOGS.lock().unwrap().clear();
|
||||
|
||||
match self.receiver.try_recv() {
|
||||
Ok(event) => match event {
|
||||
@ -184,12 +191,21 @@ impl MainWindow {
|
||||
}
|
||||
_ => Task::none(),
|
||||
},
|
||||
Message::DownloadEnd((label,res)) => {
|
||||
if !fs::exists("./uilog"){
|
||||
Message::DownloadEnd((label, res)) => {
|
||||
if !fs::exists("./uilog").unwrap() {
|
||||
fs::create_dir("./uilog").expect("Cant Create UiLog Folder");
|
||||
}
|
||||
let mut file = fs::OpenOptions::new().create(true).append(true).open(format!("./uilog/{label}.txt")).unwrap();
|
||||
writeln!(file, "{:?}",self.log_content.text().clone()).unwrap();
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(format!("./uilog/{label}.txt"))
|
||||
.unwrap();
|
||||
writeln!(file, "{:?}", self.log_content.text().clone()).unwrap();
|
||||
if res{
|
||||
self.result_background = Color::from_rgb8(0, 255,0);
|
||||
}else{
|
||||
self.result_background = Color::from_rgb8(255, 0,0);
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::WindowEvent(event) => {
|
||||
@ -242,17 +258,23 @@ impl MainWindow {
|
||||
self.selection,
|
||||
Message::TypeSelected
|
||||
),
|
||||
checkbox("online", self.is_online).on_toggle(Message::OnlineChecked)
|
||||
checkbox("online", self.is_online).on_toggle(Message::OnlineChecked),
|
||||
]
|
||||
.spacing(10),
|
||||
row![label_input, button("Start").on_press(Message::Start())].spacing(10),
|
||||
text_editor(&self.log_content)
|
||||
.on_action(Message::LogContentChanged)
|
||||
.height(Length::Fill)
|
||||
.height(Length::Fill),
|
||||
progress_bar(0.0..=100.0, 0.0).style(|_|{
|
||||
Style {
|
||||
background: self.result_background.into(),
|
||||
bar: self.result_background.into(),
|
||||
border: Border::default(),
|
||||
}
|
||||
}),
|
||||
]
|
||||
.spacing(10)
|
||||
.padding(5);
|
||||
|
||||
let container = container(content).padding(20);
|
||||
container.into()
|
||||
}
|
||||
@ -338,7 +360,9 @@ impl MainWindow {
|
||||
}
|
||||
add_log("擦除成功".to_string());
|
||||
add_log("正在下载BootLoader".to_string());
|
||||
if let Err(e) = download_wrapper.download(DownloadType::Bootloader,Some(label.clone())) {
|
||||
if let Err(e) =
|
||||
download_wrapper.download(DownloadType::Bootloader, Some(label.clone()))
|
||||
{
|
||||
add_log("下载BootLoader失败".to_string());
|
||||
sender.send(Message::DownloadEnd((label, false))).unwrap();
|
||||
return;
|
||||
@ -386,11 +410,11 @@ impl MainWindow {
|
||||
sender.send(Message::DownloadEnd((label, false))).unwrap();
|
||||
return;
|
||||
}
|
||||
sender.send(Message::DownloadEnd((label, false))).unwrap();
|
||||
sender.send(Message::DownloadEnd((label, true))).unwrap();
|
||||
return;
|
||||
} else {
|
||||
add_log("当前为离线模式".to_string());
|
||||
sender.send(Message::DownloadEnd((label, false))).unwrap();
|
||||
sender.send(Message::DownloadEnd((label, true))).unwrap();
|
||||
return;
|
||||
};
|
||||
});
|
||||
@ -425,7 +449,7 @@ impl MainWindow {
|
||||
fs::write("./config.json", config_str).unwrap();
|
||||
}
|
||||
fn read_config(&mut self) {
|
||||
if !fs::exists("./config.json"){
|
||||
if !fs::exists("./config.json").unwrap() {
|
||||
return;
|
||||
}
|
||||
let config_str = fs::read_to_string("./config.json").unwrap();
|
||||
|
@ -36,9 +36,7 @@ impl MesService {
|
||||
download_type: DownloadType,
|
||||
) -> Result<bool, Error> {
|
||||
match download_type {
|
||||
DownloadType::App=> {
|
||||
Ok(true)
|
||||
}
|
||||
DownloadType::App => Ok(true),
|
||||
DownloadType::Rail => {
|
||||
let mut conn = self.pool.get_conn()?;
|
||||
let check_result: Vec<String> = conn.query(format!(
|
||||
@ -49,7 +47,7 @@ impl MesService {
|
||||
}
|
||||
Ok(check_result[0] == "1")
|
||||
}
|
||||
DownloadType::Bootloader => Err(Error::msg("Not implemented yet"))
|
||||
DownloadType::Bootloader => Err(Error::msg("Not implemented yet")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,16 +58,20 @@ impl MesService {
|
||||
download_type: DownloadType,
|
||||
) -> Result<(), Error> {
|
||||
match download_type {
|
||||
DownloadType::Bootloader => {
|
||||
|
||||
}
|
||||
DownloadType::Bootloader => {}
|
||||
DownloadType::App => {
|
||||
let mut conn = self.pool.get_conn()?;
|
||||
let work_order_id: Vec<u32> = conn.query(format!(
|
||||
"SELECT `id` FROM wisun_ordertables WHERE `OrderId` = '{work_order}'"
|
||||
))?;
|
||||
if let Some(work_order_id) = work_order_id.first() {
|
||||
let _: Vec<String> = conn.exec(format!("INSERT OR UPDATE INTO {work_order} (`ID`,`Barcode`,`IMEI_1`, `Station1`) VALUES ({work_order_id},{label},{label}, '1')").to_string(), ())?;
|
||||
let _: Vec<String> = conn.exec(
|
||||
format!(
|
||||
"INSERT INTO {work_order} (`ID`, `Barcode`, `IMEI_1`, `Station1`) VALUES ({work_order_id}, {label}, {label}, '1') \
|
||||
ON DUPLICATE KEY UPDATE `Barcode` = VALUES(`Barcode`), `IMEI_1` = VALUES(`IMEI_1`), `Station1` = VALUES(`Station1`)"
|
||||
),
|
||||
()
|
||||
)?;
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user