2023-09-10 20:39:49 -07:00
|
|
|
mod state;
|
|
|
|
|
|
|
|
use crate::state::State;
|
|
|
|
|
|
|
|
use calloop_wayland_source::WaylandSource;
|
|
|
|
use color_eyre::eyre::{self, Context};
|
|
|
|
use wayland_client::{globals as WG, Connection};
|
|
|
|
|
|
|
|
fn setup() -> eyre::Result<()>
|
2023-06-22 00:54:46 -07:00
|
|
|
{
|
2023-09-10 20:39:49 -07:00
|
|
|
use log4rs::{append, config, encode::pattern::PatternEncoder};
|
|
|
|
let stdout = append::console::ConsoleAppender::builder()
|
|
|
|
.encoder(Box::new(PatternEncoder::new(
|
|
|
|
"{d(%Y-%m-%d %H:%M:%S)} | {h({l}):5.5} | [{T}] {f}:{L} — {m}{n}",
|
|
|
|
)))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let file = append::file::FileAppender::builder()
|
|
|
|
.encoder(Box::new(PatternEncoder::new("{d} - {m}{n}")))
|
|
|
|
.build("requests.log")?;
|
|
|
|
|
|
|
|
let config = config::Config::builder()
|
|
|
|
.appender(config::Appender::builder().build("stdout", Box::new(stdout)))
|
|
|
|
.appender(config::Appender::builder().build("file", Box::new(file)))
|
|
|
|
.build(
|
|
|
|
config::Root::builder()
|
|
|
|
.appender("stdout")
|
|
|
|
.build(log::LevelFilter::Trace),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let _handle = log4rs::init_config(config)?;
|
|
|
|
Ok(())
|
2023-06-22 00:54:46 -07:00
|
|
|
}
|
|
|
|
|
2023-09-10 20:39:49 -07:00
|
|
|
fn main() -> eyre::Result<()>
|
2023-06-22 00:54:46 -07:00
|
|
|
{
|
2023-09-10 20:39:49 -07:00
|
|
|
// Initialise on I/O modules
|
|
|
|
color_eyre::install()?;
|
|
|
|
setup().wrap_err("Could not initialize logging")?;
|
|
|
|
|
|
|
|
// Create WL connection and get the display
|
|
|
|
let connection = Connection::connect_to_env()?;
|
|
|
|
let display = connection.display();
|
|
|
|
let (globals, event_queue) = WG::registry_queue_init::<State>(&connection)?;
|
|
|
|
let q_handle = event_queue.handle();
|
|
|
|
|
|
|
|
let registry = display.get_registry(&q_handle, ());
|
|
|
|
|
|
|
|
let mut state = State::new(globals.contents().clone_list(), ®istry, &q_handle)?;
|
|
|
|
|
|
|
|
// Main calloop event loop
|
|
|
|
let mut event_loop = calloop::EventLoop::<State>::try_new()?;
|
|
|
|
|
|
|
|
WaylandSource::new(event_queue)?.insert(event_loop.handle())?;
|
|
|
|
|
|
|
|
log::trace!("Main loop starting");
|
|
|
|
|
|
|
|
state.lock(&q_handle);
|
|
|
|
|
|
|
|
while let Ok(_) = event_loop.dispatch(None, &mut state) {
|
|
|
|
if state.stop {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log::trace!("Teardown");
|
|
|
|
|
|
|
|
Ok(())
|
2023-06-22 00:54:46 -07:00
|
|
|
}
|