Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Sep 4, 2024
1 parent 561fc6c commit a20d8d1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Wry> {
debug!("Creating or getting config...");
pub fn get_app_settings(app: &AppHandle) -> Store<Wry> {
debug!("Creating or getting app settings...");
// create the store
let mut appdir = app
.path()
Expand All @@ -48,8 +64,12 @@ pub fn create_or_get_config(app: &AppHandle) -> Store<Wry> {
// 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));
Expand Down
12 changes: 6 additions & 6 deletions apps/desktop/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn toggle_pin(
window: WebviewWindow,
pin: State<Pinned>,
menu: State<TrayMenu>,
config: State<StoreWrapper>,
config: State<AppSettings>,
) {
let app = window.app_handle();
let value = !get_pin(app.state::<Pinned>());
Expand All @@ -89,9 +89,9 @@ pub fn set_pin(
pin: State<Pinned>,
menu: State<TrayMenu>,
value: bool,
config: State<StoreWrapper>,
settings: State<AppSettings>,
) {
_set_pin(value, &window, pin, menu, config);
_set_pin(value, &window, pin, menu, settings);
}

impl Deref for Pinned {
Expand All @@ -102,7 +102,7 @@ impl Deref for Pinned {
}
}

impl Deref for StoreWrapper {
impl Deref for AppSettings {
type Target = Mutex<Store<Wry>>;

fn deref(&self) -> &Self::Target {
Expand All @@ -123,7 +123,7 @@ fn _set_pin(
window: &WebviewWindow,
pinned: State<Pinned>,
menu: State<TrayMenu>,
config: State<StoreWrapper>,
config: State<AppSettings>,
) {
// @d0nutptr cooked here
pinned.store(value, std::sync::atomic::Ordering::Relaxed);
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -43,7 +43,7 @@ use system_notification::WorkspaceListener;
use tauri::WebviewWindow;

pub struct Pinned(AtomicBool);
pub struct StoreWrapper(Mutex<Store<Wry>>);
pub struct AppSettings(Mutex<Store<Wry>>);
pub struct TrayMenu(Mutex<Menu<Wry>>);

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Tray {
window,
app.state::<Pinned>(),
app.state::<TrayMenu>(),
app.state::<StoreWrapper>(),
app.state::<AppSettings>(),
);
}
TRAY_SHOW_APP => {
Expand Down

0 comments on commit a20d8d1

Please sign in to comment.