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
|
|
|
|
|
|
|
|
fn init_logging(cmd: &str) {
|
|
|
|
|
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)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.write(true)
|
|
|
|
|
.open(logdir.join([cmd, ".log"].concat().as_str()).as_path());
|
|
|
|
|
|
|
|
|
|
if let Ok(file) = logfile {
|
|
|
|
|
use tracing_subscriber::{fmt, EnvFilter};
|
|
|
|
|
fmt()
|
|
|
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
|
|
|
.with_writer(file)
|
|
|
|
|
.init();
|
|
|
|
|
}
|
|
|
|
|
}
|