From 46cb6bcbe8ed6254aa06ff155828666d14ef7bed Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 14 Sep 2025 17:58:59 +0800 Subject: feat: network control --- src/client/connector.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/client/connector.rs') diff --git a/src/client/connector.rs b/src/client/connector.rs index 6b59f60..3396349 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -5,6 +5,7 @@ use std::{thread::sleep, time::Duration}; use crate::executor::{Executor, tasks::IntoTask}; +#[derive(Debug)] pub(crate) enum Result { Ok(T), Err(E), @@ -17,16 +18,26 @@ pub(crate) trait Connection { // should use channel to notify update fn update(&self) -> Result; // None if no update(content is same) + // TODO: queue failed ntfy fn ntfy(&self, data: String) -> Result; fn is_prev(&mut self, str: &Self::Ok) -> bool; + fn force_network(&mut self); + + fn reinit(&mut self) { + sleep(Duration::from_millis(500)); + _ = Executor::new("network", ["on".to_string()]); + self.force_network(); + } + fn r#loop(&mut self) -> ! { loop { // tradeoff: if I put this at the ened of the loop, then the continue would just skip it, and continue doing update() until with no waiting, this wastes lot of cpu/IO // however, of course we can add a manual sleep before it continue and put this in the end, but that's code duplication // the cons of the current approch is that the first time we've entered, it would start sleeping - sleep(Duration::from_millis(500)); + self.reinit(); + match self.update() { Result::Ok(s) => { if self.is_prev(&s) { -- cgit v1.2.3