Skip to content

Commit

Permalink
Add ability to customize theming and colors with json config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jul 31, 2024
1 parent 89ccf62 commit 2110056
Show file tree
Hide file tree
Showing 13 changed files with 561 additions and 384 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

893 changes: 523 additions & 370 deletions rust/client/src/ui/theme/mod.rs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions rust/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ base64 = "0.22"
utils = { path = "../utils" }
bytes = "1.6.0"
thiserror = "1"
directories = "5.0"

[build-dependencies]
tonic-build = "0.11.0"

[features]
release = []
scenario_runner = []
22 changes: 21 additions & 1 deletion rust/server/src/dirs.rs → rust/common/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ use std::fs::File;
use std::path::{Path, PathBuf};
use anyhow::Context;

use directories::ProjectDirs;
use directories::{BaseDirs, ProjectDirs};

#[derive(Clone)]
pub struct Dirs {
inner: ProjectDirs
}

impl Dirs {

}

impl Dirs {
pub fn new() -> Self {
Self {
inner: ProjectDirs::from("dev", "project-gauntlet", "Gauntlet").unwrap()
}
}

pub fn home_dir(&self) -> Option<PathBuf> {
let path = BaseDirs::new()?
.home_dir()
.to_path_buf();

Some(path)
}

pub fn data_db_file(&self) -> anyhow::Result<PathBuf> {
let path = self.data_dir()?.join("data.db");
Ok(path)
Expand All @@ -38,6 +50,14 @@ impl Dirs {
self.config_dir().join("config.toml")
}

pub fn theme_file(&self) -> PathBuf {
self.config_dir().join("theme.json")
}

pub fn theme_color_file(&self) -> PathBuf {
self.config_dir().join("color_theme.json")
}

pub fn config_dir(&self) -> PathBuf {
let config_dir = if cfg!(feature = "release") || cfg!(feature = "scenario_runner") {
self.inner.config_dir().to_path_buf()
Expand Down
1 change: 1 addition & 0 deletions rust/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod model;
pub mod rpc;
pub mod scenario_convert;
pub mod scenario_model;
pub mod dirs;

#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "type")]
Expand Down
5 changes: 2 additions & 3 deletions rust/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ serde = { version = "1.0", features = ["derive"] }
deno_core = { version = "0.204.0" }
deno_runtime = { version = "0.126.0" }
tokio = "1.28.1"
directories = "5.0"
toml = "0.8.10"
tantivy = "0.20.2"
zstd-sys = "=2.0.9" # TODO REMOVE https://github.com/gyscos/zstd-rs/issues/270
Expand Down Expand Up @@ -51,5 +50,5 @@ plist = "1.6.1"
icns = "0.3.1"

[features]
release = []
scenario_runner = ["dep:scenario_runner"]
release = ["common/release"]
scenario_runner = ["dep:scenario_runner", "common/scenario_runner"]
1 change: 0 additions & 1 deletion rust/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub mod rpc;
pub(in crate) mod search;
pub(in crate) mod plugins;
pub(in crate) mod model;
mod dirs;

const SETTINGS_ENV: &'static str = "GAUNTLET_INTERNAL_SETTINGS";

Expand Down
6 changes: 3 additions & 3 deletions rust/server/src/plugins/applications/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::collections::HashMap;
use std::env;
use std::path::{PathBuf};

use directories::BaseDirs;
use freedesktop_entry_parser::parse_entry;
use freedesktop_icons::lookup;
use image::ImageFormat;
use image::imageops::FilterType;
use serde::Serialize;
use walkdir::WalkDir;
use common::dirs::Dirs;
use crate::plugins::applications::{DesktopEntry, resize_icon};

fn find_application_dirs() -> Option<Vec<PathBuf>> {
Expand All @@ -18,8 +18,8 @@ fn find_application_dirs() -> Option<Vec<PathBuf>> {
PathBuf::from(val)
},
None => {
let base_dirs = BaseDirs::new()?;
let home = base_dirs.home_dir();
let dirs = Dirs::new();
let home = dirs.home_dir()?;
home.join(".local/share")
}
};
Expand Down
2 changes: 1 addition & 1 deletion rust/server/src/plugins/config_reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;

use crate::dirs::Dirs;
use common::dirs::Dirs;
use crate::plugins::data_db_repository::{DataDbRepository, DbWritePendingPlugin};

pub struct ConfigReader {
Expand Down
2 changes: 1 addition & 1 deletion rust/server/src/plugins/data_db_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sqlx::sqlite::SqliteConnectOptions;
use sqlx::types::Json;
use uuid::Uuid;
use common::model::{PhysicalKey, PhysicalShortcut};
use crate::dirs::Dirs;
use common::dirs::Dirs;
use crate::model::ActionShortcutKey;
use crate::plugins::frecency::{FrecencyItemStats, FrecencyMetaParams};
use crate::plugins::loader::PluginManifestActionShortcutKey;
Expand Down
2 changes: 1 addition & 1 deletion rust/server/src/plugins/icon_cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::anyhow;
use crate::dirs::Dirs;
use common::dirs::Dirs;

#[derive(Clone)]
pub struct IconCache {
Expand Down
2 changes: 1 addition & 1 deletion rust/server/src/plugins/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use tokio::net::TcpStream;
use common::model::{EntrypointId, PluginId, UiRenderLocation, UiPropertyValue, UiWidget, UiWidgetId, SearchResultEntrypointType, PhysicalKey};
use common::rpc::frontend_api::FrontendApi;
use component_model::{Children, Component, create_component_model, Property, PropertyType, SharedType};
use crate::dirs::Dirs;
use common::dirs::Dirs;
use crate::model::{IntermediateUiEvent, JsUiPropertyValue, JsUiRenderLocation, JsUiEvent, JsUiRequestData, JsUiResponseData, JsUiWidget, PreferenceUserData};
use crate::plugins::applications::{DesktopEntry, get_apps};
use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_from_str, DbPluginEntrypointType, DbPluginPreference, DbPluginPreferenceUserData, DbReadPlugin, DbReadPluginEntrypoint};
Expand Down
2 changes: 1 addition & 1 deletion rust/server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use common::model::{DownloadStatus, EntrypointId, LocalSaveData, PhysicalKey, Ph
use common::rpc::frontend_api::FrontendApi;
use common::{settings_env_data_to_string, SettingsEnvData};
use utils::channel::RequestSender;
use crate::dirs::Dirs;
use common::dirs::Dirs;
use crate::model::ActionShortcutKey;
use crate::plugins::config_reader::ConfigReader;
use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_from_str, DbPluginActionShortcutKind, DbPluginEntrypointType, DbPluginPreference, DbPluginPreferenceUserData, DbReadPluginEntrypoint};
Expand Down

0 comments on commit 2110056

Please sign in to comment.