From fe315941df74d3a85e6e0eee5a2960a739138cb6 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:17:20 -0500 Subject: [PATCH 01/17] Add logger & new config --- apps/desktop/src-tauri/Cargo.lock | 291 ++++++++++++++++++++++++++++- apps/desktop/src-tauri/Cargo.toml | 3 + apps/desktop/src-tauri/src/main.rs | 19 ++ 3 files changed, 310 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index c535778c..864dd44f 100644 --- a/apps/desktop/src-tauri/Cargo.lock +++ b/apps/desktop/src-tauri/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom 0.2.15", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -62,6 +73,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-broadcast" version = "0.5.1" @@ -364,6 +381,18 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block" version = "0.1.6" @@ -392,6 +421,30 @@ dependencies = [ "piper", ] +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "borsh-derive", + "cfg_aliases 0.2.1", +] + +[[package]] +name = "borsh-derive" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +dependencies = [ + "once_cell", + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.68", + "syn_derive", +] + [[package]] name = "brotli" version = "3.5.0" @@ -429,6 +482,39 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byte-unit" +version = "5.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ac19bdf0b2665407c39d82dbc937e951e7e2001609f0fb32edd0af45a2d63e" +dependencies = [ + "rust_decimal", + "serde", + "utf8-width", +] + +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "bytemuck" version = "1.16.1" @@ -538,6 +624,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.38" @@ -1047,6 +1139,15 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "fern" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee" +dependencies = [ + "log", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -1136,6 +1237,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futf" version = "0.1.5" @@ -1576,6 +1683,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "hashbrown" @@ -2054,6 +2164,9 @@ name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +dependencies = [ + "value-bag", +] [[package]] name = "loom" @@ -2255,7 +2368,7 @@ checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags 2.6.0", "cfg-if", - "cfg_aliases", + "cfg_aliases 0.1.1", "libc", "memoffset 0.9.1", ] @@ -2335,6 +2448,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -2470,13 +2592,16 @@ version = "0.0.0" dependencies = [ "anyhow", "cocoa 0.25.0", + "log", "objc", "serde", "system-notification", "tauri", "tauri-build", "tauri-nspanel", + "tauri-plugin-log", "tauri-plugin-single-instance", + "tauri-plugin-store", "tauri-plugin-websocket", "tauri-plugin-window-state", "tokio", @@ -2851,6 +2976,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quick-xml" version = "0.31.0" @@ -2869,6 +3014,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.7.3" @@ -3029,6 +3180,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "reqwest" version = "0.11.27" @@ -3095,6 +3255,51 @@ dependencies = [ "windows 0.37.0", ] +[[package]] +name = "rkyv" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rust_decimal" +version = "1.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "rand 0.8.5", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -3188,6 +3393,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "security-framework" version = "2.11.0" @@ -3412,6 +3623,12 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simdutf8" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" + [[package]] name = "siphasher" version = "0.3.11" @@ -3556,6 +3773,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -3693,6 +3922,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tar" version = "0.4.41" @@ -3849,10 +4084,25 @@ dependencies = [ "tauri", ] +[[package]] +name = "tauri-plugin-log" +version = "0.0.0" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#a3fe84296a9a51fed960ab99ee7cebebb7df5390" +dependencies = [ + "byte-unit", + "fern", + "log", + "serde", + "serde_json", + "serde_repr", + "tauri", + "time", +] + [[package]] name = "tauri-plugin-single-instance" version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#81676da7ab0155c630dc56cd704cfa985867ab51" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#a3fe84296a9a51fed960ab99ee7cebebb7df5390" dependencies = [ "log", "serde", @@ -3863,10 +4113,22 @@ dependencies = [ "zbus 3.15.2", ] +[[package]] +name = "tauri-plugin-store" +version = "0.0.0" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#a3fe84296a9a51fed960ab99ee7cebebb7df5390" +dependencies = [ + "log", + "serde", + "serde_json", + "tauri", + "thiserror", +] + [[package]] name = "tauri-plugin-websocket" version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#81676da7ab0155c630dc56cd704cfa985867ab51" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#a3fe84296a9a51fed960ab99ee7cebebb7df5390" dependencies = [ "futures-util", "http 1.1.0", @@ -4053,7 +4315,9 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa 1.0.11", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -4391,6 +4655,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "uuid" version = "1.9.1" @@ -4406,6 +4676,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" @@ -5187,6 +5463,15 @@ dependencies = [ "windows-implement 0.39.0", ] +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "x11" version = "2.21.0" diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index a3eeb064..7bbea9a1 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -44,7 +44,10 @@ tokio = { version = "1.38.0", features = [ tauri-plugin-websocket = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-window-state = { git = "https://github.com/Hacksore/plugins-workspace", branch = "v1" } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } +tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } +tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } anyhow = "1.0.86" +log = "0.4.22" # macos dependencies [target.'cfg(target_os = "macos")'.dependencies] diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 444fc9e8..393e435e 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -16,8 +16,12 @@ mod window_custom; use crate::commands::*; use constants::*; +use log::LevelFilter; +use log::{debug, info}; +use std::str::FromStr; use std::sync::atomic::AtomicBool; use tauri::{generate_handler, LogicalSize, Manager, SystemTray}; +use tauri_plugin_log::LogTarget; use tauri_plugin_window_state::StateFlags; use tray::Tray; use window_custom::WindowExt; @@ -42,6 +46,7 @@ fn apply_macos_specifics(window: &Window) { use tauri_nspanel::ManagerExt; window.remove_shadow(); + debug!("Removed window shadow"); window.set_float_panel(constants::OVERLAYED_NORMAL_LEVEL); @@ -71,9 +76,21 @@ fn main() { let flags = StateFlags::POSITION | StateFlags::SIZE; let window_state_plugin = tauri_plugin_window_state::Builder::default().with_state_flags(flags); + let log_level = std::env::var("LOG_LEVEL") + .ok() + .and_then(|thing| LevelFilter::from_str(thing.as_str()).ok()) + .unwrap_or(LevelFilter::Info); + let mut app = tauri::Builder::default() .plugin(window_state_plugin.build()) .plugin(tauri_plugin_websocket::init()) + .plugin( + tauri_plugin_log::Builder::default() + .targets([LogTarget::LogDir]) + .level(log_level) + .build(), + ) + .plugin(tauri_plugin_store::Builder::default().build()) .plugin(tauri_plugin_single_instance::init(|app, argv, cwd| { println!("{}, {argv:?}, {cwd}", app.package_info().name); })); @@ -86,6 +103,7 @@ fn main() { app = app .manage(Pinned(AtomicBool::new(false))) .setup(|app| { + debug!("Starting the setup hook"); let window = app.get_window(MAIN_WINDOW_NAME).unwrap(); let settings = app.get_window(SETTINGS_WINDOW_NAME).unwrap(); @@ -124,6 +142,7 @@ fn main() { height: SETTINGS_WINDOW_HEIGHT, }); + info!("Started app"); Ok(()) }) // Add the system tray From 35b40702ab74ca23a2ee201f6bad9ea53ec9af54 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Mon, 15 Jul 2024 21:07:12 -0500 Subject: [PATCH 02/17] Add new config --- apps/desktop/src-tauri/Cargo.toml | 1 + apps/desktop/src-tauri/src/config.rs | 39 ++++++++++++++++++++++++++++ apps/desktop/src-tauri/src/main.rs | 6 +++++ 3 files changed, 46 insertions(+) create mode 100644 apps/desktop/src-tauri/src/config.rs diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 7bbea9a1..de6f774d 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -38,6 +38,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 diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/config.rs new file mode 100644 index 00000000..b4565e16 --- /dev/null +++ b/apps/desktop/src-tauri/src/config.rs @@ -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"); +} diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 393e435e..c70dccfa 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -10,11 +10,13 @@ extern crate objc; mod app_handle; 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}; @@ -135,6 +137,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()); // NOTE: always force settings window to be a certain size settings.set_size(LogicalSize { From c99e971c8b1b09fc1672bd151c075179691f7b1e Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:28:54 -0500 Subject: [PATCH 03/17] Moar debug --- apps/desktop/src-tauri/Cargo.lock | 5 +++-- apps/desktop/src-tauri/src/commands.rs | 17 +++++++++++++++-- apps/desktop/src-tauri/src/config.rs | 11 +++++++++-- apps/desktop/src-tauri/src/main.rs | 11 +++++++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index 864dd44f..ec6646da 100644 --- a/apps/desktop/src-tauri/Cargo.lock +++ b/apps/desktop/src-tauri/Cargo.lock @@ -2595,6 +2595,7 @@ dependencies = [ "log", "objc", "serde", + "serde_json", "system-notification", "tauri", "tauri-build", @@ -3473,9 +3474,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.118" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "indexmap 2.2.6", "itoa 1.0.11", diff --git a/apps/desktop/src-tauri/src/commands.rs b/apps/desktop/src-tauri/src/commands.rs index eb192565..9b6c4b43 100644 --- a/apps/desktop/src-tauri/src/commands.rs +++ b/apps/desktop/src-tauri/src/commands.rs @@ -1,5 +1,6 @@ use std::{ops::Deref, sync::atomic::AtomicBool}; +use log::debug; use tauri::{Manager, State, SystemTrayHandle, Window}; use crate::{constants::*, Pinned}; @@ -16,6 +17,8 @@ pub fn open_settings(window: Window, update: bool) { settings_windows.emit(SHOW_UPDATE_MODAL, ()).unwrap(); } } + + debug!("Ran open settings command"); } #[tauri::command] @@ -25,16 +28,22 @@ pub fn close_settings(window: Window) { if let Some(settings_windows) = settings_windows { settings_windows.hide(); } + + debug!("Ran close settings command"); } #[tauri::command] pub fn get_pin(storage: State) -> bool { - storage.0.load(std::sync::atomic::Ordering::Relaxed) + let pinned = storage.0.load(std::sync::atomic::Ordering::Relaxed); + debug!("Ran get_pinned command"); + + return pinned; } #[tauri::command] pub fn open_devtools(window: Window) { window.open_devtools(); + debug!("Ran open_devtools command"); } #[tauri::command] @@ -43,13 +52,16 @@ pub fn toggle_pin(window: Window, pin: State) { let value = !get_pin(app.state::()); _set_pin(value, &window, pin); + debug!("Ran toggle_pin command"); } #[tauri::command] pub fn set_pin(window: Window, pin: State, value: bool) { _set_pin(value, &window, pin); + debug!("Ran set_pin command"); } +// @d0nutptr cooked here to make it more concise to access the AtomicBool impl Deref for Pinned { type Target = AtomicBool; @@ -59,7 +71,6 @@ impl Deref for Pinned { } fn _set_pin(value: bool, window: &Window, pinned: State) { - // @d0nutptr cooked here pinned.store(value, std::sync::atomic::Ordering::Relaxed); // let the client know @@ -94,5 +105,7 @@ fn update_tray_icon(tray: SystemTrayHandle, pinned: bool) { icon = tauri::Icon::Raw(include_bytes!("../icons/tray/icon.ico").to_vec()); } + let icon_state = if pinned { "pinned" } else { "unpinned" }; tray.set_icon(icon); + debug!("Updated the tray icon state to {}", icon_state); } diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/config.rs index b4565e16..169c11de 100644 --- a/apps/desktop/src-tauri/src/config.rs +++ b/apps/desktop/src-tauri/src/config.rs @@ -1,9 +1,10 @@ +use log::debug; use serde::{Deserialize, Serialize}; use serde_json::json; use tauri::{AppHandle, Manager}; use tauri_plugin_store::StoreBuilder; -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize, Serialize, Debug, Copy, Clone)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum WindowLayout { Left, @@ -27,6 +28,12 @@ pub fn create_config(app: &AppHandle) { let mut appdir = app.path_resolver().app_data_dir().unwrap(); appdir.push("config_v2.json"); + // if the file exists we don't want to overwrite it + if appdir.exists() { + debug!("Config file already exists, skipping creation"); + return; + } + 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)); @@ -35,5 +42,5 @@ pub fn create_config(app: &AppHandle) { store.insert("show_only_talking_users".to_string(), json!(true)); store.save(); - println!("ayo"); + debug!("Config file created successfully"); } diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index c70dccfa..a69d545d 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -48,7 +48,7 @@ fn apply_macos_specifics(window: &Window) { use tauri_nspanel::ManagerExt; window.remove_shadow(); - debug!("Removed window shadow"); + debug!("macOS - Removed window shadow"); window.set_float_panel(constants::OVERLAYED_NORMAL_LEVEL); @@ -83,12 +83,14 @@ fn main() { .and_then(|thing| LevelFilter::from_str(thing.as_str()).ok()) .unwrap_or(LevelFilter::Info); + info!("Log level set to: {:?}", log_level); + let mut app = tauri::Builder::default() .plugin(window_state_plugin.build()) .plugin(tauri_plugin_websocket::init()) .plugin( tauri_plugin_log::Builder::default() - .targets([LogTarget::LogDir]) + .targets([LogTarget::LogDir, LogTarget::Stdout, LogTarget::Stdout]) .level(log_level) .build(), ) @@ -133,11 +135,12 @@ fn main() { { window.open_devtools(); settings.open_devtools(); + debug!("Opening devtools"); } // update the system tray Tray::update_tray(&app.app_handle()); - debug!("Updated the tray/taskbar menu"); + debug!("Updated the tray/taskbar"); // we should call this to create the config file create_config(&app.app_handle()); @@ -148,7 +151,7 @@ fn main() { height: SETTINGS_WINDOW_HEIGHT, }); - info!("Started app"); + info!("App setup completed successfully!"); Ok(()) }) // Add the system tray From ecec368ca2fe2d288489ce827a14edb56b8304ac Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:31:48 -0500 Subject: [PATCH 04/17] Add notes --- apps/desktop/src-tauri/src/config.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/config.rs index 169c11de..4841d686 100644 --- a/apps/desktop/src-tauri/src/config.rs +++ b/apps/desktop/src-tauri/src/config.rs @@ -44,3 +44,7 @@ pub fn create_config(app: &AppHandle) { store.save(); debug!("Config file created successfully"); } + +// TODO: what i reallly want is a util method to allow me to do like +// config.set(ConfigKey::Pin, json!(false)) +// config.get(ConfigKey::Pin) From eb1cda3f3182e8e1a963dc3a483a729a4f76eb40 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:23:57 -0500 Subject: [PATCH 05/17] Add moar logging --- apps/desktop/package.json | 1 + apps/desktop/src/rpc/event.ts | 1 + apps/desktop/src/rpc/manager.ts | 42 +++++++++++++++++++++++---------- pnpm-lock.yaml | 11 +++++++++ 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/apps/desktop/package.json b/apps/desktop/package.json index c1465116..4b2a0293 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -46,6 +46,7 @@ "tailwindcss-animate": "^1.0.7", "tauri-plugin-websocket-api": "github:tauri-apps/tauri-plugin-websocket#v1", "tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1", + "tauri-plugin-log": "github:tauri-apps/tauri-plugin-log#v1", "uuid": "^9.0.1", "zustand": "^4.5.2" }, diff --git a/apps/desktop/src/rpc/event.ts b/apps/desktop/src/rpc/event.ts index f8bcb9fa..261c7699 100644 --- a/apps/desktop/src/rpc/event.ts +++ b/apps/desktop/src/rpc/event.ts @@ -2,6 +2,7 @@ export enum RPCEvent { /** non-subscription event sent immediately after connecting, contains server information */ READY = "READY", /** non-subscription event sent when there is an error, including command responses */ + ERROR = "ERROR", /** sent when a user in a subscribed voice channel speaks */ SPEAKING_START = "SPEAKING_START", diff --git a/apps/desktop/src/rpc/manager.ts b/apps/desktop/src/rpc/manager.ts index a042e2fc..08899f16 100644 --- a/apps/desktop/src/rpc/manager.ts +++ b/apps/desktop/src/rpc/manager.ts @@ -17,6 +17,7 @@ import type { VoiceUser } from "@/types"; import { getVersion } from "@tauri-apps/api/app"; import { hash } from "@/utils/crypto"; import { invoke } from "@tauri-apps/api"; +import { error, info, debug } from "tauri-plugin-log"; interface TokenResponse { access_token: string; @@ -101,7 +102,7 @@ class SocketManager { * Setup the websocket connection and listen for messages */ async init(navigate: NavigateFunction) { - console.log("Init web socket manager"); + info("[WEBSOCKET] Init manager"); this.disconnect(); this._navigate = navigate; @@ -135,6 +136,7 @@ class SocketManager { } public disconnect() { + debug("[WEBSOCKET] Disconnecting socket"); this.socket?.disconnect(); this.isConnected = false; } @@ -180,6 +182,7 @@ class SocketManager { // TODO: this has to be a bug in the upstream lib, we should get a proper code // and not have to check the raw dawg string to see if something is wrong if (typeof event === "string" && (event as string).includes("Connection reset without closing handshake")) { + error("[WEBSOCKET] Connection reset without closing handshake"); this.navigate("/error"); await this.unpin(); @@ -199,8 +202,10 @@ class SocketManager { const acessToken = this.userdataStore.accessToken; if (acessToken) { + debug("[WEBSOCKET] Found access token and attempting to login with it"); this.login(acessToken); } else { + debug("[WEBSOCKET] No access token found attempting to login"); this.authenticate(); } } @@ -274,17 +279,26 @@ class SocketManager { // we got a token back from discord let's fetch an access token if (payload.cmd === RPCCommand.AUTHORIZE) { + debug("[WEBSOCKET] Got valid code back from discord, fetching access token..."); const { code } = payload.data; - const res = await fetch(`${API_URL}/token`, { - method: "POST", - body: Body.json({ code }), - }); - // we need send the token to discord - this.userdataStore.setAccessToken(res.data.access_token); + try { + const res = await fetch(`${API_URL}/token`, { + method: "POST", + body: Body.json({ code }), + }); + + debug("[WEBSOCKET] Obtained access token api, attempting to login with it..."); - // login with the token - this.login(res.data.access_token); + // we need send the token to discord + this.userdataStore.setAccessToken(res.data.access_token); + + // login with the token + this.login(res.data.access_token); + } catch (e) { + error(`[WEBSOCKET] Error fetching token: ${JSON.stringify(e)}`); + this.navigate("/error"); + } } // GET_SELECTED_VOICE_CHANNEL used to get the current voice channel the client is in @@ -300,9 +314,9 @@ class SocketManager { } } - // console.log(payload); - // we are ready to do things cause we are fully authed + // we hit an auth error with discord if (payload.cmd === RPCCommand.AUTHENTICATE && payload.evt === RPCEvent.ERROR) { + error(`[WEBSOCKET] Error authenticating with discord: ${JSON.stringify(payload.data)}`); // they have a token from the old client id if (payload.data.code === RPCErrors.INVALID_CLIENTID) { this.userdataStore.removeAccessToken(); @@ -321,6 +335,7 @@ class SocketManager { // track error metric track(Metric.DiscordAuthed, 0); } else if (payload?.cmd === RPCCommand.AUTHENTICATE) { + info("[WEBSOCKET] Logged into discord successfully"); // track success metric track(Metric.DiscordAuthed, 1); @@ -360,6 +375,7 @@ class SocketManager { // when we move channels we get a new list of users if (payload.cmd === RPCCommand.GET_CHANNEL) { + debug("[WEBSOCKET] Requesting channel for user"); this.requestUserChannel(); } } @@ -417,12 +433,12 @@ export const useSocket = () => { return; } + // if the socket is already initialized return if (socketRef.current) { - console.log("Socket already initialized"); return; } - console.log("Initializing websocket..."); + info("[WEBSOCKET] Initializing websocket..."); const socketManager = new SocketManager(); socketManager.init(navigate); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 908a3371..1d04320d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -187,6 +187,9 @@ importers: tailwindcss-animate: specifier: ^1.0.7 version: 1.0.7(tailwindcss@3.4.4) + tauri-plugin-log: + specifier: github:tauri-apps/tauri-plugin-log#v1 + version: tauri-plugin-log-api@https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/2bb26e22f7f7b4f164bad02f0ae4085796f77fff tauri-plugin-websocket-api: specifier: github:tauri-apps/tauri-plugin-websocket#v1 version: https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/c23ba8b03953e459fd9a56ea6113b12461b78026 @@ -5205,6 +5208,10 @@ packages: resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==} engines: {node: '>=10'} + tauri-plugin-log-api@https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/2bb26e22f7f7b4f164bad02f0ae4085796f77fff: + resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/2bb26e22f7f7b4f164bad02f0ae4085796f77fff} + version: 0.0.0 + tauri-plugin-websocket-api@https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/c23ba8b03953e459fd9a56ea6113b12461b78026: resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/c23ba8b03953e459fd9a56ea6113b12461b78026} version: 0.0.0 @@ -11681,6 +11688,10 @@ snapshots: mkdirp: 1.0.4 yallist: 4.0.0 + tauri-plugin-log-api@https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/2bb26e22f7f7b4f164bad02f0ae4085796f77fff: + dependencies: + '@tauri-apps/api': 1.6.0 + tauri-plugin-websocket-api@https://codeload.github.com/tauri-apps/tauri-plugin-websocket/tar.gz/c23ba8b03953e459fd9a56ea6113b12461b78026: dependencies: '@tauri-apps/api': 1.6.0 From 6dd16e340078ddd33cffa132b24a778cf11f1b34 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Sun, 28 Jul 2024 09:34:48 -0500 Subject: [PATCH 06/17] Add nested key for feature flags --- apps/desktop/src-tauri/src/config.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src-tauri/src/config.rs b/apps/desktop/src-tauri/src/config.rs index 4841d686..2702884d 100644 --- a/apps/desktop/src-tauri/src/config.rs +++ b/apps/desktop/src-tauri/src/config.rs @@ -12,6 +12,12 @@ pub enum WindowLayout { Center, } +#[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct FeatureFlags { + hide_overlay_on_mouseover: bool, +} + #[derive(Deserialize, Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Config { @@ -20,6 +26,7 @@ pub struct Config { pub telemetry: bool, pub join_history_notifications: bool, pub show_only_talking_users: bool, + pub feature_flags: FeatureFlags, } // create a helper function to seed the config with values @@ -38,8 +45,9 @@ pub fn create_config(app: &AppHandle) { 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.insert("joinHistoryNotifications".to_string(), json!(true)); + store.insert("showOnlyTalkingUsers".to_string(), json!(true)); + store.insert("featureFlags".to_string(), json!({})); store.save(); debug!("Config file created successfully"); From 156adeb0eddb8a125a23b82f66b62746235044da Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:38:26 -0500 Subject: [PATCH 07/17] It's broken --- apps/desktop/package.json | 3 +- apps/desktop/src/config.ts | 98 ------------------- apps/desktop/src/hooks/use-config-value.ts | 16 +-- apps/desktop/src/metrics.ts | 10 +- apps/desktop/src/utils/migration.ts | 25 ----- apps/desktop/src/views/settings/account.tsx | 7 +- .../src/views/settings/join-history.tsx | 7 +- pnpm-lock.yaml | 11 +++ 8 files changed, 36 insertions(+), 141 deletions(-) delete mode 100644 apps/desktop/src/utils/migration.ts diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 4b2a0293..9f05ec42 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -44,9 +44,10 @@ "react-router-dom": "^6.22.3", "tailwind-merge": "^2.2.1", "tailwindcss-animate": "^1.0.7", + "tauri-plugin-log": "github:tauri-apps/tauri-plugin-log#v1", + "tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1", "tauri-plugin-websocket-api": "github:tauri-apps/tauri-plugin-websocket#v1", "tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1", - "tauri-plugin-log": "github:tauri-apps/tauri-plugin-log#v1", "uuid": "^9.0.1", "zustand": "^4.5.2" }, diff --git a/apps/desktop/src/config.ts b/apps/desktop/src/config.ts index 2cfde317..4f9240b8 100644 --- a/apps/desktop/src/config.ts +++ b/apps/desktop/src/config.ts @@ -1,13 +1,6 @@ -import { writeFile, readTextFile, createDir } from "@tauri-apps/api/fs"; -import { appConfigDir } from "@tauri-apps/api/path"; -import * as Sentry from "@sentry/react"; - export type DirectionLR = "left" | "right" | "center"; export type DirectionTB = "top" | "bottom"; -// TODO: this is hard to use we zzz -// NOTE: how can i handle versions updates where i add new keys -// NOTE: this looks cool https://github.com/harshkhandeparkar/tauri-settings/issues export interface OverlayedConfig { pin: boolean; horizontal: DirectionLR; @@ -30,94 +23,3 @@ export const DEFAULT_OVERLAYED_CONFIG: OverlayedConfig = { showOnlyTalkingUsers: false, showOwnUser: true, }; - -const CONFIG_FILE_NAME = "config.json"; - -export class Config { - private config: OverlayedConfig = DEFAULT_OVERLAYED_CONFIG; - private configPath: string = ""; - private loaded = false; - constructor() { - this.load(); - } - - load = async () => { - if (this.loaded) return; - - this.configPath = await appConfigDir(); - try { - const config = await readTextFile(this.configPath + "/" + CONFIG_FILE_NAME); - this.config = JSON.parse(config); - - // get the new keys that don't exist in the config and merge them in - const newKeys = Object.keys(DEFAULT_OVERLAYED_CONFIG).filter(key => !Object.keys(this.config).includes(key)); - - this.config = { - ...DEFAULT_OVERLAYED_CONFIG, - ...this.config, - // NOTE: set new keys added to the default value - ...newKeys.reduce((acc, key) => { - // @ts-expect-error not sure why this errors but need to fix it - acc[key] = DEFAULT_OVERLAYED_CONFIG[key as OverlayedConfigKey]; - return acc; - }, {} as OverlayedConfig), - }; - - // make sure to disable sentry if they have disabled telemetry - if (!this.config.telemetry) { - console.warn("[TELEMETRY] Disabling sentry.io telemetry because the user has disabled it"); - Sentry.close(); - } else { - console.log("[TELEMETRY] sentry.io telemetry is enabled!"); - } - - // fuck it persist it - this.save(); - } catch (e: unknown) { - this.config = DEFAULT_OVERLAYED_CONFIG; - this.save(); - - // we don't need to raise an error cause it's the first time they have used overlayed probably? - } - - this.loaded = true; - }; - - async getConfig(): Promise { - await this.load(); - return this.config; - } - - async get(key: K): Promise { - await this.load(); - - return this.config[key]; - } - - async set(key: K, value: OverlayedConfig[K]): Promise { - await this.load(); - - this.config[key] = value; - this.save(); - } - - async save() { - // create the config dir if it's not there - try { - await createDir(this.configPath, { - recursive: true, - }); - } catch (err: unknown) { - // noop - } - - await writeFile({ - path: this.configPath + CONFIG_FILE_NAME, - contents: JSON.stringify(this.config, null, 2), - }); - } -} - -const config = new Config(); - -export default config; diff --git a/apps/desktop/src/hooks/use-config-value.ts b/apps/desktop/src/hooks/use-config-value.ts index 54bdfb68..17ab307e 100644 --- a/apps/desktop/src/hooks/use-config-value.ts +++ b/apps/desktop/src/hooks/use-config-value.ts @@ -1,25 +1,27 @@ -import Config, { DEFAULT_OVERLAYED_CONFIG, type OverlayedConfig, type OverlayedConfigKey } from "@/config"; +import { Store } from "tauri-plugin-store-api"; import { listen } from "@tauri-apps/api/event"; import { useEffect, useState } from "react"; +import { DEFAULT_OVERLAYED_CONFIG } from "@/config"; +const store = new Store("config.json"); /** * i want a single key from the config */ -export const useConfigValue = ( - key: T +export const useConfigValue = ( + key: any ): { - value: OverlayedConfig[T]; + value: any; } => { - const [value, setValue] = useState(DEFAULT_OVERLAYED_CONFIG[key]); + const [value, setValue] = useState(DEFAULT_OVERLAYED_CONFIG[key]); useEffect(() => { const init = () => { - Config.get(key).then(setValue); + store.get(key).then(setValue); }; init(); - const listenFn = listen("config_update", event => { + const listenFn = listen("config_update", event => { const { payload } = event; // update the latest value diff --git a/apps/desktop/src/metrics.ts b/apps/desktop/src/metrics.ts index c5affe53..e4c7d180 100644 --- a/apps/desktop/src/metrics.ts +++ b/apps/desktop/src/metrics.ts @@ -1,5 +1,7 @@ import { axiom } from "@/axiom"; -import Config from "@/config"; +import { Store } from "tauri-plugin-store-api"; + +const store = new Store("config.json"); export const OVERLAYED_DATASET = "overlayed-prod"; @@ -18,12 +20,12 @@ export const Metric = { type MetricNamesValues = (typeof Metric)[keyof typeof Metric]; // NOTE: allow opt-out of tracking from the settings UI -const isTelemetryEnabled = () => { - return import.meta.env.VITE_AXIOM_TOKEN && Config.get("telemetry"); +const isTelemetryEnabled = async () => { + return import.meta.env.VITE_AXIOM_TOKEN && (await store.get<{ value: boolean }>("telemetry"))?.value; }; // tell the user if they have telemetry disabled -if (!(await Config.get("telemetry"))) { +if (!(await store.get<{ value: boolean }>("telemetry"))?.value) { console.warn("[TELEMETRY] Disabling axiom telemetry because the user has disabled it"); } else { console.log("[TELEMETRY] Axiom telemetry is enabled!"); diff --git a/apps/desktop/src/utils/migration.ts b/apps/desktop/src/utils/migration.ts deleted file mode 100644 index 02fc5b1d..00000000 --- a/apps/desktop/src/utils/migration.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BaseDirectory, createDir, exists, readTextFile, writeFile } from "@tauri-apps/api/fs"; - -export async function completeMigration(name: string) { - try { - if (!(await exists("migrations", { dir: BaseDirectory.AppConfig }))) { - await createDir("migrations", { dir: BaseDirectory.AppConfig }); - } - - await writeFile(`migrations/${name}.json`, JSON.stringify({ completed: true }), { dir: BaseDirectory.AppConfig }); - } catch (e) { - console.error(e); - } -} - -export async function isMigrationComplete(name: string): Promise { - try { - const contents = await readTextFile(`migrations/${name}.json`, { - dir: BaseDirectory.AppConfig, - }); - - return JSON.parse(contents).completed; - } catch (e) { - return false; - } -} diff --git a/apps/desktop/src/views/settings/account.tsx b/apps/desktop/src/views/settings/account.tsx index 9f2a4443..7ae80f1e 100644 --- a/apps/desktop/src/views/settings/account.tsx +++ b/apps/desktop/src/views/settings/account.tsx @@ -6,7 +6,7 @@ import { saveWindowState, StateFlags } from "tauri-plugin-window-state-api"; import { shell } from "@tauri-apps/api"; import { invoke } from "@tauri-apps/api"; import { usePlatformInfo } from "@/hooks/use-platform-info"; -import Config from "@/config"; +import { Store } from "tauri-plugin-store-api" import { Dialog, @@ -25,6 +25,7 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import type { VoiceUser } from "@/types"; import { useConfigValue } from "@/hooks/use-config-value"; +const store = new Store("config.json"); export const Developer = () => { const platformInfo = usePlatformInfo(); return ( @@ -82,9 +83,9 @@ export const AppInfo = () => { checked={showOnlyTalkingUsers} onCheckedChange={async () => { const newBool = !showOnlyTalkingUsers; - await Config.set("showOnlyTalkingUsers", newBool); + await store.set("showOnlyTalkingUsers", newBool); - await emit("config_update", await Config.getConfig()); + await emit("config_update", await store.values()); }} />