2021-11-24 17:56:37 +01:00
|
|
|
// Copyright 2021 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2022-05-11 14:09:27 +02:00
|
|
|
use pop_launcher_toolkit::plugins;
|
|
|
|
|
use pop_launcher_toolkit::service;
|
2021-08-10 01:04:20 +02:00
|
|
|
|
2022-03-29 13:16:52 +02:00
|
|
|
use mimalloc::MiMalloc;
|
|
|
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
|
static GLOBAL: MiMalloc = MiMalloc;
|
|
|
|
|
|
2022-03-27 17:38:37 +02:00
|
|
|
#[tokio::main(flavor = "current_thread")]
|
|
|
|
|
async fn main() {
|
2021-08-10 01:04:20 +02:00
|
|
|
if let Some(plugin) = std::env::args().next() {
|
|
|
|
|
let start = plugin.rfind('/').map(|v| v + 1).unwrap_or(0);
|
2021-08-14 14:19:42 +02:00
|
|
|
let cmd = &plugin.as_str()[start..];
|
2022-03-28 00:54:26 +02:00
|
|
|
|
|
|
|
|
init_logging(cmd);
|
|
|
|
|
|
2021-08-14 14:19:42 +02:00
|
|
|
match cmd {
|
2022-03-27 17:38:37 +02:00
|
|
|
"calc" => plugins::calc::main().await,
|
|
|
|
|
"desktop-entries" => plugins::desktop_entries::main().await,
|
|
|
|
|
"find" => plugins::find::main().await,
|
|
|
|
|
"files" => plugins::files::main().await,
|
|
|
|
|
"pop-launcher" => service::main().await,
|
|
|
|
|
"pop-shell" => plugins::pop_shell::main().await,
|
|
|
|
|
"pulse" => plugins::pulse::main().await,
|
|
|
|
|
"recent" => plugins::recent::main().await,
|
|
|
|
|
"scripts" => plugins::scripts::main().await,
|
|
|
|
|
"terminal" => plugins::terminal::main().await,
|
|
|
|
|
"web" => plugins::web::main().await,
|
2023-02-03 12:35:13 -05:00
|
|
|
"cosmic-toplevel" => plugins::cosmic_toplevel::main().await,
|
2021-08-10 01:04:20 +02:00
|
|
|
unknown => {
|
|
|
|
|
eprintln!("unknown cmd: {}", unknown);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-28 00:54:26 +02:00
|
|
|
|
2024-07-13 01:13:17 +02:00
|
|
|
// todo: support journald once this issue is resolved: https://github.com/tokio-rs/tracing/issues/2348
|
2022-03-28 00:54:26 +02:00
|
|
|
fn init_logging(cmd: &str) {
|
2024-07-03 03:42:39 +02:00
|
|
|
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
2024-07-13 01:13:17 +02:00
|
|
|
|
2022-03-28 00:54:26 +02:00
|
|
|
let logdir = match dirs::state_dir() {
|
|
|
|
|
Some(dir) => dir.join("pop-launcher/"),
|
|
|
|
|
None => dirs::home_dir()
|
|
|
|
|
.expect("home directory required")
|
|
|
|
|
.join(".cache/pop-launcher"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let _ = std::fs::create_dir_all(&logdir);
|
|
|
|
|
|
|
|
|
|
let logfile = std::fs::OpenOptions::new()
|
|
|
|
|
.create(true)
|
2024-07-13 01:13:17 +02:00
|
|
|
.append(true)
|
2022-03-28 00:54:26 +02:00
|
|
|
.open(logdir.join([cmd, ".log"].concat().as_str()).as_path());
|
|
|
|
|
|
|
|
|
|
if let Ok(file) = logfile {
|
2024-07-13 01:13:17 +02:00
|
|
|
if let Ok(meta) = file.metadata() {
|
2024-07-03 03:42:39 +02:00
|
|
|
if meta.len() > 10000 {
|
2024-07-13 01:13:17 +02:00
|
|
|
let _ = file.set_len(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let filter_layer = EnvFilter::try_from_default_env()
|
|
|
|
|
.or_else(|_| EnvFilter::try_new("warn"))
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
2024-07-03 03:42:39 +02:00
|
|
|
let fmt_layer = fmt::layer().with_target(false).with_writer(file);
|
2024-07-13 01:13:17 +02:00
|
|
|
|
2024-07-03 03:42:39 +02:00
|
|
|
if let Ok(journal_layer) = tracing_journald::layer() {
|
|
|
|
|
tracing_subscriber::registry()
|
|
|
|
|
.with(journal_layer)
|
|
|
|
|
.with(filter_layer)
|
|
|
|
|
.init();
|
|
|
|
|
} else {
|
|
|
|
|
tracing_subscriber::registry()
|
|
|
|
|
.with(fmt_layer)
|
|
|
|
|
.with(filter_layer)
|
|
|
|
|
.init();
|
|
|
|
|
}
|
2022-03-28 00:54:26 +02:00
|
|
|
}
|
|
|
|
|
}
|