From a394fa93c56a471639f4cd01963cd5790b2a6279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 9 Mar 2024 23:43:02 +0800 Subject: [PATCH 1/5] Remove update callback. --- tunet-cui/src/event.rs | 33 ++++---- tunet-flutter/native/src/api.rs | 131 ++++++++++++++++++-------------- tunet-gui/src/context.rs | 27 ++++--- tunet-model/src/lib.rs | 130 ++++++++++++++++--------------- 4 files changed, 178 insertions(+), 143 deletions(-) diff --git a/tunet-cui/src/event.rs b/tunet-cui/src/event.rs index a3e9f99e..76d412f1 100644 --- a/tunet-cui/src/event.rs +++ b/tunet-cui/src/event.rs @@ -27,14 +27,14 @@ impl Event { pub fn new() -> Result { let (tx, rx) = channel(32); let (mtx, mrx) = channel(32); - let mut e = Self { - model: Model::new(mtx)?, + let (utx, urx) = channel(32); + let e = Self { + model: Model::new(mtx, utx)?, tx, rx, }; - e.attach_callback(); e.spawn_terminal_event(); - e.spawn_model_action(mrx); + e.spawn_model_action(mrx, urx); Ok(e) } @@ -45,18 +45,6 @@ impl Event { self.spawn_details(); } - #[allow(clippy::single_match)] - fn attach_callback(&mut self) { - let tx = self.tx.clone(); - self.model.update = Some(Box::new(move |_model, msg| match msg { - UpdateMsg::State => { - let tx = tx.clone(); - tokio::spawn(async move { tx.send(Ok(EventType::UpdateState)).await.ok() }); - } - _ => {} - })); - } - fn spawn_terminal_event(&self) { let tx = self.tx.clone(); tokio::spawn(async move { @@ -70,7 +58,7 @@ impl Event { }); } - fn spawn_model_action(&self, mut mrx: Receiver) { + fn spawn_model_action(&self, mut mrx: Receiver, mut urx: Receiver) { let tx = self.tx.clone(); tokio::spawn(async move { while let Some(a) = mrx.recv().await { @@ -78,6 +66,17 @@ impl Event { } Ok::<_, anyhow::Error>(()) }); + let tx = self.tx.clone(); + tokio::spawn(async move { + while let Some(u) = urx.recv().await { + #[allow(clippy::single_match)] + match u { + UpdateMsg::State => tx.send(Ok(EventType::UpdateState)).await?, + _ => {} + } + } + Ok::<_, anyhow::Error>(()) + }); } fn spawn_watch_status(&self) { diff --git a/tunet-flutter/native/src/api.rs b/tunet-flutter/native/src/api.rs index 064157d4..01853670 100644 --- a/tunet-flutter/native/src/api.rs +++ b/tunet-flutter/native/src/api.rs @@ -122,7 +122,8 @@ pub struct RuntimeStartConfig { } pub struct Runtime { - pub rx: RustOpaque>>>, + pub arx: RustOpaque>>>, + pub urx: RustOpaque>>>, pub model: RustOpaque>, pub handle: RustOpaque>>, } @@ -144,10 +145,12 @@ impl Runtime { .level_filter(log::LevelFilter::Trace) .init()?; - let (tx, rx) = mpsc::channel(32); - let model = Model::new(tx)?; + let (atx, arx) = mpsc::channel(32); + let (utx, urx) = mpsc::channel(32); + let model = Model::new(atx, utx)?; Ok(Self { - rx: RustOpaque::new(Mutex::new(Some(rx))), + arx: RustOpaque::new(Mutex::new(Some(arx))), + urx: RustOpaque::new(Mutex::new(Some(urx))), model: RustOpaque::new(Mutex::new(model)), handle: RustOpaque::new(Mutex::new(None)), }) @@ -155,7 +158,8 @@ impl Runtime { pub fn start(&self, sink: StreamSink, config: RuntimeStartConfig) { let model = self.model.clone(); - let mut rx = self.rx.lock().unwrap().take().unwrap(); + let mut arx = self.arx.lock().unwrap().take().unwrap(); + let mut urx = self.urx.lock().unwrap().take().unwrap(); let runtime = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) .enable_all() @@ -166,66 +170,81 @@ impl Runtime { std::thread::spawn(move || { runtime.block_on(async { { - let mut model = model.lock().unwrap(); - model.update = Some(Box::new(move |model, msg| { - let msg = match msg { - UpdateMsg::Credential => { - UpdateMsgWrap::Credential(model.username.clone()) - } - UpdateMsg::State => UpdateMsgWrap::State(model.state), - UpdateMsg::Status => UpdateMsgWrap::Status(model.status.to_string()), - UpdateMsg::Log => UpdateMsgWrap::Log(model.log.to_string()), - UpdateMsg::Flux => UpdateMsgWrap::Flux(model.flux.clone()), - UpdateMsg::Online => UpdateMsgWrap::Online( - model - .users - .iter() - .map(|u| NetUserWrap { - address: u.address.into(), - address_v6: u.address_v6.into(), - login_time: u.login_time, - mac_address: u - .mac_address - .map(|addr| addr.to_string()) - .unwrap_or_default(), - flux: u.flux, - is_local: model - .mac_addrs + let model = model.clone(); + tokio::spawn(async move { + while let Some(msg) = urx.recv().await { + let msg = { + let model = model.lock().unwrap(); + match msg { + UpdateMsg::Credential => { + UpdateMsgWrap::Credential(model.username.clone()) + } + UpdateMsg::State => UpdateMsgWrap::State(model.state), + UpdateMsg::Status => { + UpdateMsgWrap::Status(model.status.to_string()) + } + UpdateMsg::Log => UpdateMsgWrap::Log(model.log.to_string()), + UpdateMsg::Flux => UpdateMsgWrap::Flux(model.flux.clone()), + UpdateMsg::Online => UpdateMsgWrap::Online( + model + .users .iter() - .any(|it| Some(it) == u.mac_address.as_ref()), - }) - .collect(), - ), - UpdateMsg::Details => UpdateMsgWrap::Details(model.details.clone(), { - let data = DetailDaily::new(&model.details); - DetailDailyWrap { - details: data - .details - .into_iter() - .map(|(date, flux)| DetailDailyPoint { - day: date.day(), - flux, + .map(|u| NetUserWrap { + address: u.address.into(), + address_v6: u.address_v6.into(), + login_time: u.login_time, + mac_address: u + .mac_address + .map(|addr| addr.to_string()) + .unwrap_or_default(), + flux: u.flux, + is_local: model + .mac_addrs + .iter() + .any(|it| Some(it) == u.mac_address.as_ref()), + }) + .collect(), + ), + UpdateMsg::Details => { + UpdateMsgWrap::Details(model.details.clone(), { + let data = DetailDaily::new(&model.details); + DetailDailyWrap { + details: data + .details + .into_iter() + .map(|(date, flux)| DetailDailyPoint { + day: date.day(), + flux, + }) + .collect(), + now_month: data.now.month(), + now_day: data.now.day(), + max_flux: data.max_flux, + } }) - .collect(), - now_month: data.now.month(), - now_day: data.now.day(), - max_flux: data.max_flux, + } + UpdateMsg::LogBusy => UpdateMsgWrap::LogBusy(model.log_busy()), + UpdateMsg::OnlineBusy => { + UpdateMsgWrap::OnlineBusy(model.online_busy()) + } + UpdateMsg::DetailBusy => { + UpdateMsgWrap::DetailBusy(model.detail_busy()) + } } - }), - UpdateMsg::LogBusy => UpdateMsgWrap::LogBusy(model.log_busy()), - UpdateMsg::OnlineBusy => UpdateMsgWrap::OnlineBusy(model.online_busy()), - UpdateMsg::DetailBusy => UpdateMsgWrap::DetailBusy(model.detail_busy()), - }; - sink.add(msg).unwrap(); - })); - + }; + sink.add(msg).unwrap(); + } + }); + } + { + let model = model.lock().unwrap(); if (!config.username.is_empty()) && (!config.password.is_empty()) { model.queue(Action::Credential(config.username, config.password)); } model.queue(Action::Status(Some(config.status))); model.queue(Action::Timer); } - while let Some(action) = rx.recv().await { + while let Some(action) = arx.recv().await { log::debug!("received action: {:?}", action); model.lock().unwrap().handle(action); } diff --git a/tunet-gui/src/context.rs b/tunet-gui/src/context.rs index c5122606..84652492 100644 --- a/tunet-gui/src/context.rs +++ b/tunet-gui/src/context.rs @@ -8,7 +8,10 @@ use plotters::{ }; use slint::{ComponentHandle, Image, ModelRc, SharedString, StandardListViewItem, VecModel}; use std::{cmp::Reverse, rc::Rc, sync::Arc, sync::Mutex as SyncMutex}; -use tokio::sync::{mpsc, Mutex}; +use tokio::sync::{ + mpsc::{self, channel}, + Mutex, +}; use tunet_helper::{ usereg::{NetDetail, NetUser}, Datelike, Flux, NetFlux, NetState, @@ -33,15 +36,21 @@ impl UpdateContext { &self.weak_app } - pub async fn create_model(&self, tx: mpsc::Sender) -> Result>> { - let model = Arc::new(Mutex::new(Model::new(tx)?)); - let context = self.clone(); - let update = move |model: &Model, msg| { - context.update(model, msg); - }; + pub async fn create_model( + &self, + action_sender: mpsc::Sender, + ) -> Result>> { + let (update_sender, mut update_receiver) = channel(32); + let model = Arc::new(Mutex::new(Model::new(action_sender, update_sender)?)); { - let mut model = model.lock().await; - model.update = Some(Box::new(update)); + let model = model.clone(); + let context = self.clone(); + tokio::spawn(async move { + while let Some(msg) = update_receiver.recv().await { + let model = model.lock().await; + context.update(&model, msg) + } + }); } Ok(model) } diff --git a/tunet-model/src/lib.rs b/tunet-model/src/lib.rs index 5a38b77f..41a4b125 100644 --- a/tunet-model/src/lib.rs +++ b/tunet-model/src/lib.rs @@ -49,11 +49,9 @@ impl DetailDaily { } } -pub type UpdateCallback = Box; - pub struct Model { - tx: Sender, - pub update: Option, + action_sender: Sender, + update_sender: Sender, pub username: String, password: String, pub http: HttpClient, @@ -70,7 +68,7 @@ pub struct Model { } impl Model { - pub fn new(tx: Sender) -> Result { + pub fn new(action_sender: Sender, update_sender: Sender) -> Result { let http = create_http_client()?; let mac_addrs = MacAddressIterator::new() @@ -78,17 +76,17 @@ impl Model { .unwrap_or_default(); Ok(Self { - update: None, + action_sender: action_sender.clone(), + update_sender, username: String::default(), password: String::default(), - tx: tx.clone(), http, state: NetState::Unknown, status: NetStatus::Unknown, log: Cow::default(), - log_busy: BusyBool::new(tx.clone(), UpdateMsg::LogBusy), - online_busy: BusyBool::new(tx.clone(), UpdateMsg::OnlineBusy), - detail_busy: BusyBool::new(tx, UpdateMsg::DetailBusy), + log_busy: BusyBool::new(action_sender.clone(), UpdateMsg::LogBusy), + online_busy: BusyBool::new(action_sender.clone(), UpdateMsg::OnlineBusy), + detail_busy: BusyBool::new(action_sender, UpdateMsg::DetailBusy), flux: NetFlux::default(), users: Vec::default(), details: Vec::default(), @@ -97,8 +95,8 @@ impl Model { } pub fn queue(&self, action: Action) { - let tx = self.tx.clone(); - tokio::spawn(async move { tx.send(action).await.ok() }); + let action_sender = self.action_sender.clone(); + tokio::spawn(async move { action_sender.send(action).await.ok() }); } pub fn handle(&mut self, action: Action) { @@ -111,12 +109,12 @@ impl Model { Action::State(s) => { match s { None => { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let http = self.http.clone(); let status = self.status.clone(); tokio::spawn(async move { let state = suggest::suggest_with_status(&http, &status).await; - tx.send(Action::State(Some(state))).await.ok() + action_sender.send(Action::State(Some(state))).await.ok() }); } Some(s) => { @@ -181,25 +179,25 @@ impl Model { self.update(UpdateMsg::Online); } Action::Connect(addr) => { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let usereg = self.usereg(); let (u, p) = (self.username.clone(), self.password.clone()); tokio::spawn(async move { usereg.login(&u, &p).await?; usereg.connect(addr).await?; - tx.send(Action::Online).await?; - Ok::<_, anyhow::Error>(()) + action_sender.send(Action::Online).await?; + anyhow::Ok(()) }); } Action::Drop(addr) => { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let usereg = self.usereg(); let (u, p) = (self.username.clone(), self.password.clone()); tokio::spawn(async move { usereg.login(&u, &p).await?; usereg.drop(addr).await?; - tx.send(Action::Online).await?; - Ok::<_, anyhow::Error>(()) + action_sender.send(Action::Online).await?; + anyhow::Ok(()) }); } Action::Details => { @@ -216,32 +214,31 @@ impl Model { } pub fn update(&self, msg: UpdateMsg) { - if let Some(f) = &self.update { - f(self, msg); - } + let update_sender = self.update_sender.clone(); + tokio::spawn(async move { update_sender.send(msg).await }); } fn spawn_watch_status(&self) { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); tokio::spawn(async move { let mut events = NetStatus::watch(); while let Some(()) = events.next().await { - tx.send(Action::Status(None)).await?; + action_sender.send(Action::Status(None)).await?; } - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } fn spawn_timer(&self) { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); tokio::spawn(async move { let mut interval = tokio::time::interval(std::time::Duration::from_secs(1)); loop { interval.tick().await; - tx.send(Action::Tick).await?; + action_sender.send(Action::Tick).await?; } #[allow(unreachable_code)] - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } @@ -255,20 +252,21 @@ impl Model { fn spawn_login(&self) { if let Some(lock) = self.log_busy.lock() { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let (u, p) = (self.username.clone(), self.password.clone()); if let Some(client) = self.client() { tokio::spawn(async move { let _lock = lock; let res = client.login(&u, &p).await; let ok = res.is_ok(); - tx.send(Action::LoginDone(res.unwrap_or_else(|e| e.to_string()))) + action_sender + .send(Action::LoginDone(res.unwrap_or_else(|e| e.to_string()))) .await?; if ok { sleep(std::time::Duration::from_secs(1)).await; - Self::flux_impl(client, tx, true).await?; + Self::flux_impl(client, action_sender, true).await?; } - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } } @@ -276,19 +274,20 @@ impl Model { fn spawn_logout(&self) { if let Some(lock) = self.log_busy.lock() { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let u = self.username.clone(); if let Some(client) = self.client() { tokio::spawn(async move { let _lock = lock; let res = client.logout(&u).await; let ok = res.is_ok(); - tx.send(Action::LoginDone(res.unwrap_or_else(|e| e.to_string()))) + action_sender + .send(Action::LoginDone(res.unwrap_or_else(|e| e.to_string()))) .await?; if ok { - Self::flux_impl(client, tx, true).await?; + Self::flux_impl(client, action_sender, true).await?; } - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } } @@ -296,29 +295,36 @@ impl Model { fn spawn_flux(&self) { if let Some(lock) = self.log_busy.lock() { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); if let Some(client) = self.client() { tokio::spawn(async move { let _lock = lock; - Self::flux_impl(client, tx, false).await + Self::flux_impl(client, action_sender, false).await }); } } } - async fn flux_impl(client: TUNetConnect, tx: Sender, keep_msg: bool) -> Result<()> { + async fn flux_impl( + client: TUNetConnect, + action_sender: Sender, + keep_msg: bool, + ) -> Result<()> { let flux = client.flux().await; match flux { Ok(flux) => { - tx.send(Action::FluxDone(flux, None, keep_msg)).await?; + action_sender + .send(Action::FluxDone(flux, None, keep_msg)) + .await?; } Err(err) => { - tx.send(Action::FluxDone( - NetFlux::default(), - Some(err.to_string()), - keep_msg, - )) - .await? + action_sender + .send(Action::FluxDone( + NetFlux::default(), + Some(err.to_string()), + keep_msg, + )) + .await? } } Ok(()) @@ -326,7 +332,7 @@ impl Model { fn spawn_online(&self) { if let Some(lock) = self.online_busy.lock() { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let usereg = self.usereg(); let (u, p) = (self.username.clone(), self.password.clone()); tokio::spawn(async move { @@ -334,16 +340,17 @@ impl Model { usereg.login(&u, &p).await?; let users = usereg.users(); pin_mut!(users); - tx.send(Action::OnlineDone(users.try_collect().await?)) + action_sender + .send(Action::OnlineDone(users.try_collect().await?)) .await?; - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } } fn spawn_details(&self) { if let Some(lock) = self.detail_busy.lock() { - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); let usereg = self.usereg(); let (u, p) = (self.username.clone(), self.password.clone()); tokio::spawn(async move { @@ -351,9 +358,10 @@ impl Model { usereg.login(&u, &p).await?; let details = usereg.details(NetDetailOrder::LogoutTime, false); pin_mut!(details); - tx.send(Action::DetailsDone(details.try_collect().await?)) + action_sender + .send(Action::DetailsDone(details.try_collect().await?)) .await?; - Ok::<_, anyhow::Error>(()) + anyhow::Ok(()) }); } } @@ -411,15 +419,15 @@ pub enum UpdateMsg { struct BusyBool { lock: Arc, - tx: Sender, + action_sender: Sender, msg: UpdateMsg, } impl BusyBool { - pub fn new(tx: Sender, msg: UpdateMsg) -> Self { + pub fn new(action_sender: Sender, msg: UpdateMsg) -> Self { Self { lock: Arc::new(AtomicBool::new(false)), - tx, + action_sender, msg, } } @@ -435,16 +443,16 @@ impl BusyBool { .is_ok() { let msg = self.msg; - let tx = self.tx.clone(); + let action_sender = self.action_sender.clone(); tokio::spawn(async move { - tx.send(Action::Update(msg)).await.ok(); + action_sender.send(Action::Update(msg)).await.ok(); }); Some(guard( - (self.lock.clone(), self.tx.clone(), self.msg), - |(lock, tx, msg)| { + (self.lock.clone(), self.action_sender.clone(), self.msg), + |(lock, action_sender, msg)| { lock.store(false, Ordering::Release); tokio::spawn(async move { - tx.send(Action::Update(msg)).await.ok(); + action_sender.send(Action::Update(msg)).await.ok(); }); }, )) From 631d21ae573c18f420b51b8338d059ca169be3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sat, 9 Mar 2024 23:56:44 +0800 Subject: [PATCH 2/5] Remove spawns in cui. --- tunet-cui/src/event.rs | 78 +++++++++++++----------------------------- tunet-cui/src/main.rs | 3 +- 2 files changed, 25 insertions(+), 56 deletions(-) diff --git a/tunet-cui/src/event.rs b/tunet-cui/src/event.rs index 76d412f1..74977ab6 100644 --- a/tunet-cui/src/event.rs +++ b/tunet-cui/src/event.rs @@ -1,12 +1,8 @@ use anyhow::Result; pub use crossterm::event::Event as TerminalEvent; -use crossterm::event::{KeyCode, MouseButton, MouseEventKind}; -use futures_util::{pin_mut, Stream, StreamExt}; +use crossterm::event::{EventStream, KeyCode, MouseButton, MouseEventKind}; +use futures_util::StreamExt; use ratatui::layout::Rect; -use std::{ - pin::Pin, - task::{Context, Poll}, -}; use tokio::sync::mpsc::*; use tunet_model::*; @@ -19,23 +15,21 @@ pub enum EventType { pub struct Event { pub model: Model, - tx: Sender>, - rx: Receiver>, + event: EventStream, + mrx: Receiver, + urx: Receiver, } impl Event { pub fn new() -> Result { - let (tx, rx) = channel(32); let (mtx, mrx) = channel(32); let (utx, urx) = channel(32); - let e = Self { + Ok(Self { model: Model::new(mtx, utx)?, - tx, - rx, - }; - e.spawn_terminal_event(); - e.spawn_model_action(mrx, urx); - Ok(e) + event: EventStream::new(), + mrx, + urx, + }) } pub fn start(&self) { @@ -45,38 +39,22 @@ impl Event { self.spawn_details(); } - fn spawn_terminal_event(&self) { - let tx = self.tx.clone(); - tokio::spawn(async move { - let stream = crossterm::event::EventStream::new(); - pin_mut!(stream); - while let Some(e) = stream.next().await { - tx.send(e.map(EventType::TerminalEvent).map_err(anyhow::Error::from)) - .await?; - } - Ok::<_, anyhow::Error>(()) - }); - } - - fn spawn_model_action(&self, mut mrx: Receiver, mut urx: Receiver) { - let tx = self.tx.clone(); - tokio::spawn(async move { - while let Some(a) = mrx.recv().await { - tx.send(Ok(EventType::ModelAction(a))).await?; - } - Ok::<_, anyhow::Error>(()) - }); - let tx = self.tx.clone(); - tokio::spawn(async move { - while let Some(u) = urx.recv().await { - #[allow(clippy::single_match)] - match u { - UpdateMsg::State => tx.send(Ok(EventType::UpdateState)).await?, + pub async fn next_event(&mut self) -> Result> { + loop { + tokio::select! { + e = self.event.next() => break if let Some(e) = e { + Ok(Some(EventType::TerminalEvent(e?))) + } else { + Ok(None) + }, + a = self.mrx.recv() => break Ok(a.map(EventType::ModelAction)), + u = self.urx.recv() => match u { + None => break Ok(None), + Some(UpdateMsg::State) => break Ok(Some(EventType::UpdateState)), _ => {} - } + }, } - Ok::<_, anyhow::Error>(()) - }); + } } fn spawn_watch_status(&self) { @@ -152,11 +130,3 @@ impl Event { true } } - -impl Stream for Event { - type Item = Result; - - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.rx.poll_recv(cx) - } -} diff --git a/tunet-cui/src/main.rs b/tunet-cui/src/main.rs index 1ecd9b67..44d608d2 100644 --- a/tunet-cui/src/main.rs +++ b/tunet-cui/src/main.rs @@ -7,7 +7,6 @@ use crossterm::{ execute, terminal::*, }; -use futures_util::TryStreamExt; use ratatui::{ backend::{Backend, CrosstermBackend}, layout::*, @@ -87,7 +86,7 @@ async fn main_loop( _ = interval.tick() => { terminal.draw(|f| view::draw(&event.model, f))?; } - e = event.try_next() => { + e = event.next_event() => { if let Some(e) = e? { if !event.handle(e, terminal.size()?) { break; From d422019f2b27b1d2197adaa0d71d46d6d0178fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sun, 10 Mar 2024 00:01:23 +0800 Subject: [PATCH 3/5] Update version. --- Cargo.lock | 99 +++++++++++++++----------------------- macbundle/Info.plist | 4 +- tunet-cui/Cargo.toml | 2 +- tunet-flutter/pubspec.yaml | 2 +- tunet-gui/Cargo.toml | 2 +- tunet-helper/Cargo.toml | 2 +- tunet-service/Cargo.toml | 2 +- tunet/Cargo.toml | 2 +- wix/main.wix | 2 +- 9 files changed, 48 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c373d1e..16dafa53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,9 +609,9 @@ checksum = "832133bbabbbaa9fbdba793456a2827627a7d2b8fb96032fa1e7666d7895832b" [[package]] name = "bumpalo" -version = "3.15.3" +version = "3.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" [[package]] name = "by_address" @@ -753,9 +753,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.89" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" dependencies = [ "jobserver", "libc", @@ -805,9 +805,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -835,14 +835,14 @@ checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" dependencies = [ "glob", "libc", - "libloading 0.8.2", + "libloading 0.8.3", ] [[package]] name = "clap" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -850,9 +850,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -1486,7 +1486,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.2", + "libloading 0.8.3", ] [[package]] @@ -1649,9 +1649,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" dependencies = [ "anstream", "anstyle", @@ -1894,9 +1894,9 @@ dependencies = [ [[package]] name = "flutter_rust_bridge_codegen" -version = "2.0.0-dev.26" +version = "2.0.0-dev.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88d27901244d5dc51cef7f98369f2219e3c8a9ff8d5b9c79fba6aef27fd973f" +checksum = "72a7f55174d9bd846b89231bcc4580adad9da0174808621c8da8e26e0dea5139" dependencies = [ "anyhow", "atty", @@ -2300,7 +2300,7 @@ dependencies = [ "glutin_glx_sys", "glutin_wgl_sys", "icrate", - "libloading 0.8.2", + "libloading 0.8.3", "objc2", "once_cell", "raw-window-handle", @@ -2630,7 +2630,7 @@ dependencies = [ "cfg-if", "derive_more", "fontdb", - "libloading 0.8.2", + "libloading 0.8.3", ] [[package]] @@ -3203,9 +3203,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", "windows-targets 0.52.4", @@ -3640,7 +3640,7 @@ dependencies = [ "netlink_wi", "objc", "pin-project", - "system-configuration 0.6.0", + "system-configuration", "tokio", "tokio-stream", "windows 0.53.0", @@ -4127,18 +4127,18 @@ checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", @@ -4519,9 +4519,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.24" +version = "0.11.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "0eea5a9eb898d3783f17c6407670e3592fd174cb81a10e51d4c37f49450b9946" dependencies = [ "base64", "bytes", @@ -4550,7 +4550,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration 0.5.1", + "system-configuration", "tokio", "tokio-native-tls", "tokio-rustls", @@ -5484,17 +5484,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys 0.5.0", -] - [[package]] name = "system-configuration" version = "0.6.0" @@ -5503,17 +5492,7 @@ checksum = "658bc6ee10a9b4fcf576e9b0819d95ec16f4d2c02d39fd83ac1c8789785c4a42" dependencies = [ "bitflags 2.4.2", "core-foundation", - "system-configuration-sys 0.6.0", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", + "system-configuration-sys", ] [[package]] @@ -5690,7 +5669,7 @@ checksum = "d4098d49269baa034a8d1eae9bd63e9fa532148d772121dace3bcd6a6c98eb6d" dependencies = [ "as-raw-xcb-connection", "ctor", - "libloading 0.8.2", + "libloading 0.8.3", "tracing", ] @@ -5920,7 +5899,7 @@ checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "tunet" -version = "0.9.2" +version = "0.9.3" dependencies = [ "anyhow", "clap", @@ -5937,7 +5916,7 @@ dependencies = [ [[package]] name = "tunet-cui" -version = "0.9.2" +version = "0.9.3" dependencies = [ "anyhow", "clap", @@ -5953,7 +5932,7 @@ dependencies = [ [[package]] name = "tunet-gui" -version = "0.9.2" +version = "0.9.3" dependencies = [ "anyhow", "color-theme", @@ -5973,7 +5952,7 @@ dependencies = [ [[package]] name = "tunet-helper" -version = "0.16.0" +version = "0.17.0" dependencies = [ "allo-isolate", "async-stream", @@ -6012,14 +5991,14 @@ dependencies = [ [[package]] name = "tunet-service" -version = "0.9.2" +version = "0.9.3" dependencies = [ "anyhow", "cfg-if", "clap", "dirs", "enum_dispatch", - "env_logger 0.11.2", + "env_logger 0.11.3", "futures-util", "humantime", "is_elevated", @@ -6857,9 +6836,9 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winit" -version = "0.29.13" +version = "0.29.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b9d7047a2a569d5a81e3be098dcd8153759909b127477f4397e03cf1006d90a" +checksum = "a7a3db69ffbe53a9babec7804da7a90f21020fcce1f2f5e5291e2311245b993d" dependencies = [ "ahash", "android-activity", @@ -7011,7 +6990,7 @@ dependencies = [ "as-raw-xcb-connection", "gethostname 0.4.3", "libc", - "libloading 0.8.2", + "libloading 0.8.3", "once_cell", "rustix 0.38.31", "x11rb-protocol 0.13.0", diff --git a/macbundle/Info.plist b/macbundle/Info.plist index 3d71674f..1cf2632f 100644 --- a/macbundle/Info.plist +++ b/macbundle/Info.plist @@ -17,9 +17,9 @@ tunet-gui CFBundleVersion - 0.9.2 + 0.9.3 CFBundleShortVersionString - 0.9.2 + 0.9.3 LSMinimumSystemVersion 11.7 diff --git a/tunet-cui/Cargo.toml b/tunet-cui/Cargo.toml index 91048c49..54dc169f 100644 --- a/tunet-cui/Cargo.toml +++ b/tunet-cui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tunet-cui" -version = "0.9.2" +version = "0.9.3" description = "Tsinghua University network CUI" edition.workspace = true authors.workspace = true diff --git a/tunet-flutter/pubspec.yaml b/tunet-flutter/pubspec.yaml index ef5c35a6..cbd014ec 100644 --- a/tunet-flutter/pubspec.yaml +++ b/tunet-flutter/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.9.2+1 +version: 0.9.3+1 environment: sdk: ">=3.0.0 <4.0.0" diff --git a/tunet-gui/Cargo.toml b/tunet-gui/Cargo.toml index 1ff33c69..f201a4e8 100644 --- a/tunet-gui/Cargo.toml +++ b/tunet-gui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tunet-gui" -version = "0.9.2" +version = "0.9.3" description = "Tsinghua University network GUI" edition.workspace = true authors.workspace = true diff --git a/tunet-helper/Cargo.toml b/tunet-helper/Cargo.toml index 14b739c6..0c0d0fa3 100644 --- a/tunet-helper/Cargo.toml +++ b/tunet-helper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tunet-helper" -version = "0.16.0" +version = "0.17.0" edition.workspace = true authors.workspace = true license.workspace = true diff --git a/tunet-service/Cargo.toml b/tunet-service/Cargo.toml index a5868845..86b866aa 100644 --- a/tunet-service/Cargo.toml +++ b/tunet-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tunet-service" -version = "0.9.2" +version = "0.9.3" description = "Tsinghua University network service daemon" edition.workspace = true authors.workspace = true diff --git a/tunet/Cargo.toml b/tunet/Cargo.toml index e57abd2b..99a37d9b 100644 --- a/tunet/Cargo.toml +++ b/tunet/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tunet" -version = "0.9.2" +version = "0.9.3" description = "Tsinghua University network CLI" edition.workspace = true authors.workspace = true diff --git a/wix/main.wix b/wix/main.wix index 751efc2b..14e1cee9 100644 --- a/wix/main.wix +++ b/wix/main.wix @@ -1,5 +1,5 @@ - + From 235e8b2dfcb24e102d0642994fce06c9d231e69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sun, 10 Mar 2024 00:12:42 +0800 Subject: [PATCH 4/5] Update packages. --- Cargo.lock | 42 +++++++++++++++++++-------------- Cargo.toml | 5 ++-- tunet-flutter/native/Cargo.toml | 2 +- tunet-flutter/pubspec.yaml | 2 +- tunet-helper/src/lib.rs | 13 ++++++---- tunet-model/src/lib.rs | 2 +- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16dafa53..aa184dfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -479,6 +479,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "bindgen" version = "0.69.4" @@ -947,7 +953,7 @@ dependencies = [ "cfg-if", "log", "objc", - "windows 0.53.0", + "windows 0.54.0", ] [[package]] @@ -1866,9 +1872,9 @@ dependencies = [ [[package]] name = "flutter_rust_bridge" -version = "2.0.0-dev.26" +version = "2.0.0-dev.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbff1c7e4ff043ba0e944a89728cd2356820740233a5081c440e78de937505d2" +checksum = "de520aa4b8fcb8e6cd67492a9de17e29e272daac98be05a97485d531a1d2dceb" dependencies = [ "allo-isolate", "android_logger", @@ -1938,9 +1944,9 @@ dependencies = [ [[package]] name = "flutter_rust_bridge_macros" -version = "2.0.0-dev.26" +version = "2.0.0-dev.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f28e5abab9b2c2f9b8e1b51e87fc6e03e7c8cc91309729397e3962b88369c4" +checksum = "e530c29aaf59c8ff9d3ba588956b4b29d93fcfdee213f422b0e6a76a1e632c6e" [[package]] name = "fnv" @@ -3643,7 +3649,7 @@ dependencies = [ "system-configuration", "tokio", "tokio-stream", - "windows 0.53.0", + "windows 0.54.0", ] [[package]] @@ -4186,7 +4192,7 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef" dependencies = [ - "base64", + "base64 0.21.7", "indexmap 2.2.5", "line-wrap", "quick-xml 0.31.0", @@ -4523,7 +4529,7 @@ version = "0.11.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eea5a9eb898d3783f17c6407670e3592fd174cb81a10e51d4c37f49450b9946" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "cookie", "cookie_store", @@ -4719,7 +4725,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", ] [[package]] @@ -4972,7 +4978,7 @@ version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15d167997bd841ec232f5b2b8e0e26606df2e7caa4c31b95ea9ca52b200bd270" dependencies = [ - "base64", + "base64 0.21.7", "chrono", "hex", "indexmap 1.9.3", @@ -5957,7 +5963,7 @@ dependencies = [ "allo-isolate", "async-stream", "authtea", - "base64", + "base64 0.22.0", "chrono", "data-encoding", "futures-core", @@ -6012,7 +6018,7 @@ dependencies = [ "tokio-stream", "tunet-helper", "tunet-settings", - "windows 0.53.0", + "windows 0.54.0", "windows-service", "winlog2", ] @@ -6151,7 +6157,7 @@ version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "377f62b4a3c173de8654c1aa80ab1dac1154e6f13a779a9943e53780120d1625" dependencies = [ - "base64", + "base64 0.21.7", "log", "pico-args", "usvg-parser", @@ -6580,11 +6586,11 @@ dependencies = [ [[package]] name = "windows" -version = "0.53.0" +version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efc5cf48f83140dcaab716eeaea345f9e93d0018fb81162753a3f76c3397b538" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" dependencies = [ - "windows-core 0.53.0", + "windows-core 0.54.0", "windows-targets 0.52.4", ] @@ -6608,9 +6614,9 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.53.0" +version = "0.54.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dcc5b895a6377f1ab9fa55acedab1fd5ac0db66ad1e6c7f47e28a22e446a5dd" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" dependencies = [ "windows-result", "windows-targets 0.52.4", diff --git a/Cargo.toml b/Cargo.toml index 7f3ebb7d..569c7f57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ chrono = { version = "0.4", default-features = false, features = [ clap = { version = "4", features = ["derive"] } dirs = "5" log = "0.4" -base64 = "0.21" +base64 = "0.22" futures-core = "0.3" futures-util = "0.3" @@ -70,6 +70,5 @@ objc = "0.2" core-foundation = "0.9" system-configuration = "0.6" -windows = "0.53" +windows = "0.54" winresource = "0.1" - diff --git a/tunet-flutter/native/Cargo.toml b/tunet-flutter/native/Cargo.toml index f5952734..cdab4868 100644 --- a/tunet-flutter/native/Cargo.toml +++ b/tunet-flutter/native/Cargo.toml @@ -17,7 +17,7 @@ anyhow = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"] } log = { workspace = true } chrono = { workspace = true } -flutter_rust_bridge = { version = "=2.0.0-dev.26", features = ["chrono"] } +flutter_rust_bridge = { version = "=2.0.0-dev.27", features = ["chrono"] } [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.13" diff --git a/tunet-flutter/pubspec.yaml b/tunet-flutter/pubspec.yaml index cbd014ec..9cdc3e74 100644 --- a/tunet-flutter/pubspec.yaml +++ b/tunet-flutter/pubspec.yaml @@ -31,7 +31,7 @@ dependencies: sdk: flutter ffi: ^2.1.0 - flutter_rust_bridge: 2.0.0-dev.26 + flutter_rust_bridge: 2.0.0-dev.27 meta: ^1.9.1 uuid: ^4.1.0 freezed_annotation: ^2.2.0 diff --git a/tunet-helper/src/lib.rs b/tunet-helper/src/lib.rs index c1039701..bc147807 100644 --- a/tunet-helper/src/lib.rs +++ b/tunet-helper/src/lib.rs @@ -141,11 +141,14 @@ impl std::str::FromStr for NetFlux { Ok(NetFlux { username: vec[0].to_string(), flux: Flux(vec[6].parse::().unwrap_or_default()), - online_time: Duration(NaiveDuration::seconds( - (vec[2].parse::().unwrap_or_default() - - vec[1].parse::().unwrap_or_default()) - .max(0), - )), + online_time: Duration( + NaiveDuration::try_seconds( + (vec[2].parse::().unwrap_or_default() + - vec[1].parse::().unwrap_or_default()) + .max(0), + ) + .unwrap_or_default(), + ), balance: Balance(vec[11].parse::().unwrap_or_default()), }) } else if s.is_empty() { diff --git a/tunet-model/src/lib.rs b/tunet-model/src/lib.rs index 41a4b125..2771c0bd 100644 --- a/tunet-model/src/lib.rs +++ b/tunet-model/src/lib.rs @@ -137,7 +137,7 @@ impl Model { Action::Tick => { if !self.flux.username.is_empty() { self.flux.online_time = - Duration(self.flux.online_time.0 + NaiveDuration::seconds(1)); + Duration(self.flux.online_time.0 + NaiveDuration::try_seconds(1).unwrap()); self.update(UpdateMsg::Flux); } } From 25467cc161ab215847092bbfa984433af8bbdd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sun, 10 Mar 2024 15:02:34 +0800 Subject: [PATCH 5/5] Fix runtime new in dart side --- tunet-flutter/lib/runtime.dart | 2 +- tunet-flutter/native/src/api.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tunet-flutter/lib/runtime.dart b/tunet-flutter/lib/runtime.dart index 2aacde03..01731eff 100644 --- a/tunet-flutter/lib/runtime.dart +++ b/tunet-flutter/lib/runtime.dart @@ -131,7 +131,7 @@ class ManagedRuntime extends NotifyPropertyChanged { } else { await RustLib.init(); } - final runtime = await Runtime.newRuntime(); + final runtime = Runtime(); return ManagedRuntime(runtime: runtime); } diff --git a/tunet-flutter/native/src/api.rs b/tunet-flutter/native/src/api.rs index 01853670..764d3615 100644 --- a/tunet-flutter/native/src/api.rs +++ b/tunet-flutter/native/src/api.rs @@ -129,6 +129,7 @@ pub struct Runtime { } impl Runtime { + #[frb(sync)] pub fn new() -> Result { #[cfg(target_os = "android")] android_logger::init_once(