panorama/src/main.rs

70 lines
2 KiB
Rust
Raw Normal View History

2021-02-14 13:20:35 +00:00
#[macro_use]
extern crate tracing;
2021-02-14 13:20:35 +00:00
use std::path::PathBuf;
2021-02-12 08:12:43 +00:00
use anyhow::Result;
2021-02-12 12:32:17 +00:00
use futures::future::TryFutureExt;
2021-02-16 10:45:41 +00:00
use panorama::{config::spawn_config_watcher_system, mail, report_err, ui};
use structopt::StructOpt;
2021-02-15 10:36:06 +00:00
use tokio::sync::mpsc;
use xdg::BaseDirectories;
2021-02-12 08:12:43 +00:00
#[derive(Debug, StructOpt)]
2021-02-12 13:52:46 +00:00
#[structopt(author, about)]
struct Opt {
/// The path to the log file. By default, does not log.
#[structopt(long = "log-file")]
log_file: Option<PathBuf>,
}
2021-02-16 10:45:41 +00:00
#[tokio::main(flavor = "multi_thread")]
2021-02-12 08:54:19 +00:00
async fn main() -> Result<()> {
// parse command line arguments into options struct
2021-02-20 01:44:04 +00:00
let _opt = Opt::from_args();
// print logs to file as directed by command line options
use tracing_subscriber::filter::LevelFilter;
let file = tracing_appender::rolling::daily("public", "lol");
let (non_blocking, _guard) = tracing_appender::non_blocking(file);
tracing_subscriber::fmt()
.with_max_level(LevelFilter::TRACE)
.with_writer(non_blocking)
.with_thread_ids(true)
.init();
debug!("shiet");
// TODO: debug
let x = span!(tracing::Level::WARN, "ouais");
let _y = x.enter();
2021-02-12 08:12:43 +00:00
2021-02-15 10:36:06 +00:00
let _xdg = BaseDirectories::new()?;
2021-02-15 11:07:48 +00:00
let (_config_thread, config_update) = spawn_config_watcher_system()?;
// used to notify the runtime that the process should exit
2021-02-14 13:20:35 +00:00
let (exit_tx, mut exit_rx) = mpsc::channel::<()>(1);
// used to send commands to the mail service
2021-02-15 10:36:06 +00:00
let (_mail_tx, mail_rx) = mpsc::unbounded_channel();
2021-02-12 08:12:43 +00:00
2021-02-16 10:45:41 +00:00
tokio::spawn(async move {
let config_update = config_update.clone();
mail::run_mail(config_update, mail_rx)
.unwrap_or_else(report_err)
.await;
});
2021-02-14 23:49:54 +00:00
let stdout = std::io::stdout();
2021-02-14 23:49:54 +00:00
tokio::spawn(ui::run_ui(stdout, exit_tx).unwrap_or_else(report_err));
2021-02-12 08:12:43 +00:00
2021-02-14 13:20:35 +00:00
exit_rx.recv().await;
// TODO: graceful shutdown
// yada yada create a background process and pass off the connections so they can be safely
// shutdown
std::process::exit(0);
// Ok(())
2021-02-12 08:12:43 +00:00
}