From a20d8d1bc721024ad007ebd827e5126c06168db5 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:20:19 -0500 Subject: [PATCH] Rename --- .../src/{config.rs => app_settings.rs} | 28 ++++++++++++++++--- apps/desktop/src-tauri/src/commands.rs | 12 ++++---- apps/desktop/src-tauri/src/main.rs | 10 +++---- apps/desktop/src-tauri/src/tray.rs | 4 +-- 4 files changed, 37 insertions(+), 17 deletions(-) rename apps/desktop/src-tauri/src/{config.rs => app_settings.rs} (71%) diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/app_settings.rs similarity index 71% rename from apps/desktop/src-tauri/src/config.rs rename to apps/desktop/src-tauri/src/app_settings.rs index f1a2e0a9..0da4bf37 100644 --- a/apps/desktop/src-tauri/src/config.rs +++ b/apps/desktop/src-tauri/src/app_settings.rs @@ -20,7 +20,7 @@ pub struct FeatureFlags { #[derive(Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")] -pub struct Config { +pub struct Settings { pub pin: bool, pub placment: WindowLayout, pub telemetry: bool, @@ -29,10 +29,26 @@ pub struct Config { pub feature_flags: FeatureFlags, } -const CONFIG_FILE_NAME: &str = "expirmental_config_v2.json"; +// create a default config +impl Default for Settings { + fn default() -> Self { + Settings { + pin: false, + placment: WindowLayout::Center, + telemetry: true, + join_history_notifications: true, + show_only_talking_users: true, + feature_flags: FeatureFlags { + hide_overlay_on_mouseover: false, + }, + } + } +} + +const CONFIG_FILE_NAME: &str = "experimental_config.json"; // create a helper function to seed the config with values -pub fn create_or_get_config(app: &AppHandle) -> Store { - debug!("Creating or getting config..."); +pub fn get_app_settings(app: &AppHandle) -> Store { + debug!("Creating or getting app settings..."); // create the store let mut appdir = app .path() @@ -48,8 +64,12 @@ pub fn create_or_get_config(app: &AppHandle) -> Store { // if the file exists we don't want to overwrite it if config_exists { debug!("Config file already exists, loading from file"); + // NOTE: we can get the config from the filesystem store.load(); + + // add keys from the default confg } else { + // NOTE: we need to create the config for the first time store.insert("pin".to_string(), json!(false)); store.insert("placement".to_string(), json!(WindowLayout::Center)); store.insert("telemetry".to_string(), json!(true)); diff --git a/apps/desktop/src-tauri/src/commands.rs b/apps/desktop/src-tauri/src/commands.rs index a374a0be..86ec31b5 100644 --- a/apps/desktop/src-tauri/src/commands.rs +++ b/apps/desktop/src-tauri/src/commands.rs @@ -7,7 +7,7 @@ use serde_json::json; use tauri::{image::Image, menu::Menu, AppHandle, Emitter, Manager, State, WebviewWindow, Wry}; use tauri_plugin_store::Store; -use crate::{constants::*, Pinned, StoreWrapper, TrayMenu}; +use crate::{constants::*, Pinned, AppSettings, TrayMenu}; #[tauri::command] pub fn zoom_window(window: tauri::Window, scale_factor: f64) { @@ -75,7 +75,7 @@ pub fn toggle_pin( window: WebviewWindow, pin: State, menu: State, - config: State, + config: State, ) { let app = window.app_handle(); let value = !get_pin(app.state::()); @@ -89,9 +89,9 @@ pub fn set_pin( pin: State, menu: State, value: bool, - config: State, + settings: State, ) { - _set_pin(value, &window, pin, menu, config); + _set_pin(value, &window, pin, menu, settings); } impl Deref for Pinned { @@ -102,7 +102,7 @@ impl Deref for Pinned { } } -impl Deref for StoreWrapper { +impl Deref for AppSettings { type Target = Mutex>; fn deref(&self) -> &Self::Target { @@ -123,7 +123,7 @@ fn _set_pin( window: &WebviewWindow, pinned: State, menu: State, - config: State, + config: State, ) { // @d0nutptr cooked here pinned.store(value, std::sync::atomic::Ordering::Relaxed); diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 46ab8771..3cbaab5c 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -10,13 +10,13 @@ extern crate objc; mod app_handle; mod commands; -mod config; +mod app_settings; mod constants; mod tray; mod window_custom; use crate::commands::*; -use config::create_or_get_config; +use app_settings::get_app_settings; use constants::*; use log::{debug, info}; use std::{ @@ -43,7 +43,7 @@ use system_notification::WorkspaceListener; use tauri::WebviewWindow; pub struct Pinned(AtomicBool); -pub struct StoreWrapper(Mutex>); +pub struct AppSettings(Mutex>); pub struct TrayMenu(Mutex>); #[cfg(target_os = "macos")] @@ -137,8 +137,8 @@ fn main() { window.set_decorations(false); // we should call this to create the config file - let config = create_or_get_config(&app.app_handle()); - app.manage(StoreWrapper(Mutex::new(config))); + let app_settings = get_app_settings(&app.app_handle()); + app.manage(AppSettings(Mutex::new(app_settings))); // add mac things #[cfg(target_os = "macos")] diff --git a/apps/desktop/src-tauri/src/tray.rs b/apps/desktop/src-tauri/src/tray.rs index 666aa84e..6fa763d1 100644 --- a/apps/desktop/src-tauri/src/tray.rs +++ b/apps/desktop/src-tauri/src/tray.rs @@ -10,7 +10,7 @@ use anyhow::Result; use tauri_plugin_window_state::{AppHandleExt, StateFlags}; use crate::{ - commands, toggle_pin, Pinned, StoreWrapper, TrayMenu, MAIN_WINDOW_NAME, OVERLAYED, + commands, toggle_pin, Pinned, AppSettings, TrayMenu, MAIN_WINDOW_NAME, OVERLAYED, SETTINGS_WINDOW_NAME, TRAY_OPEN_DEVTOOLS_MAIN, TRAY_OPEN_DEVTOOLS_SETTINGS, TRAY_QUIT, TRAY_RELOAD, TRAY_SETTINGS, TRAY_SHOW_APP, TRAY_TOGGLE_PIN, }; @@ -56,7 +56,7 @@ impl Tray { window, app.state::(), app.state::(), - app.state::(), + app.state::(), ); } TRAY_SHOW_APP => {