man
This commit is contained in:
parent
706d397ad5
commit
49367abb58
6 changed files with 37 additions and 21 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -649,11 +649,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "6.1.0"
|
version = "6.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab6f70b46d6325aa300f1c7bb3d470127dfc27806d8ea6bf294ee0ce643ce2b1"
|
checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
|
"funty",
|
||||||
"memchr",
|
"memchr",
|
||||||
"version_check 0.9.2",
|
"version_check 0.9.2",
|
||||||
]
|
]
|
||||||
|
@ -786,8 +787,7 @@ name = "panorama-imap"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_matches",
|
"assert_matches",
|
||||||
"funty",
|
"nom 6.1.2",
|
||||||
"nom 6.1.0",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -961,9 +961,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570"
|
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
|
@ -12,8 +12,7 @@ edition = "2018"
|
||||||
maintenance = { status = "passively-maintained" }
|
maintenance = { status = "passively-maintained" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
funty = "=1.1.0"
|
nom = { version = "6.1.2", default-features = false, features = ["std"] }
|
||||||
nom = { version = "6", default-features = false, features = ["std"] }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = "1.3"
|
assert_matches = "1.3"
|
||||||
|
|
|
@ -106,6 +106,7 @@ async fn watcher_loop(
|
||||||
// first try opening the config file directly when the program is opened
|
// 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)
|
// (so the config isn't blank until the user touches the config file)
|
||||||
let xdg = BaseDirectories::new()?;
|
let xdg = BaseDirectories::new()?;
|
||||||
|
|
||||||
if let Some(config_path) = xdg.find_config_file("panorama/panorama.toml") {
|
if let Some(config_path) = xdg.find_config_file("panorama/panorama.toml") {
|
||||||
debug!("found config at {:?}", config_path);
|
debug!("found config at {:?}", config_path);
|
||||||
let config = read_config(config_path).await?;
|
let config = read_config(config_path).await?;
|
||||||
|
@ -118,10 +119,15 @@ async fn watcher_loop(
|
||||||
debug!("new event: {:?}", event);
|
debug!("new event: {:?}", event);
|
||||||
use notify::DebouncedEvent::*;
|
use notify::DebouncedEvent::*;
|
||||||
match event {
|
match event {
|
||||||
NoticeWrite(path) | Write(path) => {
|
NoticeWrite(path) | Write(path) => match read_config(path).await {
|
||||||
let config = read_config(path).await?;
|
Ok(config) => {
|
||||||
|
debug!("read new config: {:?}", config);
|
||||||
config_tx.send(Some(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],
|
/// Start the entire config watcher system, and return a [ConfigWatcher][self::ConfigWatcher],
|
||||||
/// which is a cloneable receiver of config update events.
|
/// 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 (watcher, config_rx) = start_watcher()?;
|
||||||
let (config_tx, config_update) = watch::channel(None);
|
let (config_tx, config_update) = watch::channel(None);
|
||||||
|
|
||||||
|
|
9
src/mail/imap2.rs
Normal file
9
src/mail/imap2.rs
Normal file
|
@ -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(())
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
//! Mail
|
//! Mail
|
||||||
|
|
||||||
mod imap;
|
mod imap;
|
||||||
|
mod imap2;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
@ -23,18 +24,19 @@ pub enum MailCommand {
|
||||||
|
|
||||||
/// Main entrypoint for the mail listener.
|
/// Main entrypoint for the mail listener.
|
||||||
pub async fn run_mail(
|
pub async fn run_mail(
|
||||||
config_watcher: ConfigWatcher,
|
mut config_watcher: ConfigWatcher,
|
||||||
_cmd_in: UnboundedReceiver<MailCommand>,
|
_cmd_in: UnboundedReceiver<MailCommand>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut curr_conn: Option<JoinHandle<_>> = None;
|
let mut curr_conn: Option<JoinHandle<_>> = None;
|
||||||
|
|
||||||
let mut config_watcher = WatchStream::new(config_watcher);
|
// let mut config_watcher = WatchStream::new(config_watcher);
|
||||||
loop {
|
loop {
|
||||||
debug!("listening for configs");
|
debug!("listening for configs");
|
||||||
let a = config_watcher.next().await;
|
let config: Config = match config_watcher.changed().await {
|
||||||
debug!("got config {:?}", a);
|
Ok(_) => match *config_watcher.borrow() {
|
||||||
let config: Config = match a {
|
Some(ref v) => v.clone(),
|
||||||
Some(Some(v)) => v,
|
_ => break,
|
||||||
|
},
|
||||||
_ => break,
|
_ => break,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use futures::future::TryFutureExt;
|
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 structopt::StructOpt;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
|
@ -31,7 +31,7 @@ async fn main() -> Result<()> {
|
||||||
setup_logger(&opt)?;
|
setup_logger(&opt)?;
|
||||||
|
|
||||||
let _xdg = BaseDirectories::new()?;
|
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
|
// used to notify the runtime that the process should exit
|
||||||
let (exit_tx, mut exit_rx) = mpsc::channel::<()>(1);
|
let (exit_tx, mut exit_rx) = mpsc::channel::<()>(1);
|
||||||
|
|
Loading…
Reference in a new issue