Skip to content

Commit

Permalink
Add new config
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Jul 16, 2024
1 parent 1fa791b commit 4a62d45
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/desktop/src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tauri = { version = "1.6.8", features = [
"http-all",
] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.120"
tokio = { version = "1.38.0", features = [
"full",
] } # Required for asynchronous operations
Expand Down
39 changes: 39 additions & 0 deletions apps/desktop/src-tauri/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use serde::{Deserialize, Serialize};
use serde_json::json;
use tauri::{AppHandle, Manager};
use tauri_plugin_store::StoreBuilder;

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum WindowLayout {
Left,
Right,
Center,
}

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Config {
pub pin: bool,
pub placment: WindowLayout,
pub telemetry: bool,
pub join_history_notifications: bool,
pub show_only_talking_users: bool,
}

// create a helper function to seed the config with values
pub fn create_config(app: &AppHandle) {
// create the store
let mut appdir = app.path_resolver().app_data_dir().unwrap();
appdir.push("config_v2.json");

let mut store = StoreBuilder::new(app.app_handle(), appdir).build();
store.insert("pin".to_string(), json!(false));
store.insert("placement".to_string(), json!(WindowLayout::Center));
store.insert("telemetry".to_string(), json!(true));
store.insert("join_history_notifications".to_string(), json!(true));
store.insert("show_only_talking_users".to_string(), json!(true));

store.save();
println!("ayo");
}
6 changes: 6 additions & 0 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
extern crate objc;

mod commands;
mod config;
mod constants;
mod tray;
mod window_custom;

use crate::commands::*;
use config::create_config;
use constants::*;
use log::LevelFilter;
use log::{debug, info};
Expand Down Expand Up @@ -108,6 +110,10 @@ fn main() {

// update the system tray
Tray::update_tray(&app.app_handle());
debug!("Updated the tray/taskbar menu");

// we should call this to create the config file
create_config(&app.app_handle());

info!("Started app");
Ok(())
Expand Down

0 comments on commit 4a62d45

Please sign in to comment.