Skip to content

Commit

Permalink
fix: use tracing instead of systemd log and fix default theme path
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Jan 29, 2024
1 parent feb3249 commit 7fef4ce
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 41 deletions.
54 changes: 36 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ onagre-launcher-toolkit = { git = "https://github.com/onagre-launcher/launcher"
clap = { version = "^4", features = ["derive"] }
freedesktop-icons = "0.2.5"

log = { version = "^0.4" }
systemd-journal-logger = "2.1.1"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

once_cell = "^1"
anyhow = "^1"
Expand Down
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use iced::{
use iced_core::widget::operation::scrollable::RelativeOffset;
use iced_core::{Event, Font};
use iced_style::Theme;
use log::{debug, trace};
use onagre_launcher_toolkit::launcher::{Request, Response};
use once_cell::sync::Lazy;
use tracing::{debug, trace};

use crate::app::entries::pop_entry::PopSearchResult;
use crate::app::entries::AsEntry;
Expand Down
2 changes: 1 addition & 1 deletion src/app/state.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app::cache::Cache;
use crate::app::mode::ActiveMode;
use crate::app::plugin_matchers::{match_web_plugins, Plugin};
use log::debug;
use onagre_launcher_toolkit::launcher::SearchResult;
use tracing::debug;

use crate::app::{Message, INPUT_ID};
use crate::icons::IconPath;
Expand Down
15 changes: 6 additions & 9 deletions src/app/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use crate::app::style::search::input::SearchInputStyles;
use crate::app::style::search::SearchContainerStyles;
use crate::config::color::OnagreColor;
use crate::config::padding::OnagrePadding;
use crate::THEME_PATH;
use iced::widget::container::Appearance;
use iced::Background;
use iced_core::BorderRadius;
use tracing::{error, warn};

pub mod app;
pub mod rows;
Expand All @@ -16,16 +18,11 @@ pub mod search;

impl Theme {
pub fn load() -> Self {
let buf = dirs::config_dir()
.expect("Failed to open `$XDG_CONFIG_HOME`")
.join("onagre")
.join("theme.scss");

let theme = crate::config::parse_file(buf);
let buf = THEME_PATH.lock().unwrap().clone();
let theme = crate::config::parse_file(&buf);
if let Err(err) = &theme {
eprintln!("Failed to parse theme:");
eprintln!("{err}");
eprintln!("Failing back to default theme");
error!("Failed to parse theme {buf:?}: {err}");
warn!("Failing back to default theme");
};

theme.unwrap_or_default()
Expand Down
2 changes: 1 addition & 1 deletion src/app/subscriptions/pop_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use iced::Subscription;
use iced_core::event::Status;
use iced_runtime::futures::futures::stream;
use iced_runtime::futures::subscription::Recipe;
use log::debug;
use onagre_launcher_toolkit::launcher::{json_input_stream, Request, Response};
use std::hash::Hash;
use std::process::Stdio;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::{ChildStderr, ChildStdin, ChildStdout, Command};
use tracing::debug;

// Whenever a message is red from pop-launcher stdout, send it to the subscription receiver
async fn handle_stdout(stdout: ChildStdout, mut sender: Sender<Response>) {
Expand Down
2 changes: 1 addition & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use log::{debug, trace};
use once_cell::sync::Lazy;
use std::cmp::Reverse;
use std::fmt::Debug;
use tracing::{debug, trace};

use serde::de::DeserializeOwned;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/db/web.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::db::{Database, Entity};
use log::debug;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use tracing::debug;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct WebEntity<'a> {
Expand Down
21 changes: 14 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::path::PathBuf;
use std::sync::Mutex;

use anyhow::anyhow;
use app::style::Theme;
use clap::Parser;
use log::{debug, info, LevelFilter};
use once_cell::sync::Lazy;
use std::sync::Mutex;
use systemd_journal_logger::JournalLog;
use tracing::{debug, info};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

use app::style::Theme;

pub mod app;
pub mod config;
Expand All @@ -18,7 +20,7 @@ pub static THEME_PATH: Lazy<Mutex<PathBuf>> = Lazy::new(|| {
Mutex::new(
dirs::config_dir()
.ok_or_else(|| anyhow!("Theme config not found"))
.map(|path| path.join("onagre").join("theme.toml"))
.map(|path| path.join("onagre").join("theme.scss"))
.unwrap(),
)
});
Expand All @@ -40,8 +42,13 @@ struct Cli {
}

pub fn main() -> iced::Result {
JournalLog::new().unwrap().install().unwrap();
log::set_max_level(LevelFilter::Info);
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(
std::env::var("RUST_LOG").unwrap_or_else(|_| "onagre=info".into()),
))
.with(tracing_subscriber::fmt::layer())
.init();

info!("Starting onagre");
let cli = Cli::parse();
// User defined theme config, $XDG_CONFIG_DIR/onagre/theme.toml otherwise
Expand Down

0 comments on commit 7fef4ce

Please sign in to comment.