From 49367abb58f6c1b35278f3dcadc56318bfb8373a Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 15 Feb 2021 05:07:48 -0600 Subject: [PATCH] man --- Cargo.lock | 12 ++++++------ imap/Cargo.toml | 3 +-- src/config.rs | 16 +++++++++++----- src/mail/imap2.rs | 9 +++++++++ src/mail/mod.rs | 14 ++++++++------ src/main.rs | 4 ++-- 6 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 src/mail/imap2.rs diff --git a/Cargo.lock b/Cargo.lock index 66a9c5f..598c276 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -649,11 +649,12 @@ dependencies = [ [[package]] name = "nom" -version = "6.1.0" +version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6f70b46d6325aa300f1c7bb3d470127dfc27806d8ea6bf294ee0ce643ce2b1" +checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" dependencies = [ "bitvec", + "funty", "memchr", "version_check 0.9.2", ] @@ -786,8 +787,7 @@ name = "panorama-imap" version = "0.0.1" dependencies = [ "assert_matches", - "funty", - "nom 6.1.0", + "nom 6.1.2", ] [[package]] @@ -961,9 +961,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ "bitflags", ] diff --git a/imap/Cargo.toml b/imap/Cargo.toml index 7ed6b12..38bb6a3 100644 --- a/imap/Cargo.toml +++ b/imap/Cargo.toml @@ -12,8 +12,7 @@ edition = "2018" maintenance = { status = "passively-maintained" } [dependencies] -funty = "=1.1.0" -nom = { version = "6", default-features = false, features = ["std"] } +nom = { version = "6.1.2", default-features = false, features = ["std"] } [dev-dependencies] assert_matches = "1.3" diff --git a/src/config.rs b/src/config.rs index 6ea14b6..496fb51 100644 --- a/src/config.rs +++ b/src/config.rs @@ -106,6 +106,7 @@ async fn watcher_loop( // first try opening the config file directly when the program is opened // (so the config isn't blank until the user touches the config file) let xdg = BaseDirectories::new()?; + if let Some(config_path) = xdg.find_config_file("panorama/panorama.toml") { debug!("found config at {:?}", config_path); let config = read_config(config_path).await?; @@ -118,10 +119,15 @@ async fn watcher_loop( debug!("new event: {:?}", event); use notify::DebouncedEvent::*; match event { - NoticeWrite(path) | Write(path) => { - let config = read_config(path).await?; - config_tx.send(Some(config))?; - } + NoticeWrite(path) | Write(path) => match read_config(path).await { + Ok(config) => { + debug!("read new config: {:?}", config); + config_tx.send(Some(config))?; + } + Err(err) => { + debug!("error reading new config: {:?}", err); + } + }, _ => {} } } @@ -131,7 +137,7 @@ async fn watcher_loop( /// Start the entire config watcher system, and return a [ConfigWatcher][self::ConfigWatcher], /// which is a cloneable receiver of config update events. -pub fn spawn_config_watcher() -> Result<(JoinHandle<()>, ConfigWatcher)> { +pub fn spawn_config_watcher_system() -> Result<(JoinHandle<()>, ConfigWatcher)> { let (watcher, config_rx) = start_watcher()?; let (config_tx, config_update) = watch::channel(None); diff --git a/src/mail/imap2.rs b/src/mail/imap2.rs new file mode 100644 index 0000000..11f882a --- /dev/null +++ b/src/mail/imap2.rs @@ -0,0 +1,9 @@ +// let's try this again + +use anyhow::Result; + +use crate::config::ImapConfig; + +pub async fn open_imap_connection(config: ImapConfig) -> Result<()> { + Ok(()) +} diff --git a/src/mail/mod.rs b/src/mail/mod.rs index 6256134..e313a30 100644 --- a/src/mail/mod.rs +++ b/src/mail/mod.rs @@ -1,6 +1,7 @@ //! Mail mod imap; +mod imap2; use anyhow::Result; use futures::stream::StreamExt; @@ -23,18 +24,19 @@ pub enum MailCommand { /// Main entrypoint for the mail listener. pub async fn run_mail( - config_watcher: ConfigWatcher, + mut config_watcher: ConfigWatcher, _cmd_in: UnboundedReceiver, ) -> Result<()> { let mut curr_conn: Option> = None; - let mut config_watcher = WatchStream::new(config_watcher); + // let mut config_watcher = WatchStream::new(config_watcher); loop { debug!("listening for configs"); - let a = config_watcher.next().await; - debug!("got config {:?}", a); - let config: Config = match a { - Some(Some(v)) => v, + let config: Config = match config_watcher.changed().await { + Ok(_) => match *config_watcher.borrow() { + Some(ref v) => v.clone(), + _ => break, + }, _ => break, }; diff --git a/src/main.rs b/src/main.rs index 2148236..7043e35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use anyhow::Result; use futures::future::TryFutureExt; -use panorama::{config::spawn_config_watcher, mail, ui}; +use panorama::{config::spawn_config_watcher_system, mail, ui}; use structopt::StructOpt; use tokio::sync::mpsc; use xdg::BaseDirectories; @@ -31,7 +31,7 @@ async fn main() -> Result<()> { setup_logger(&opt)?; let _xdg = BaseDirectories::new()?; - let (_config_thread, config_update) = spawn_config_watcher()?; + let (_config_thread, config_update) = spawn_config_watcher_system()?; // used to notify the runtime that the process should exit let (exit_tx, mut exit_rx) = mpsc::channel::<()>(1);