Skip to content

Commit

Permalink
Moar debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Jul 28, 2024
1 parent ff5de17 commit 07bbcf9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 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.

17 changes: 15 additions & 2 deletions apps/desktop/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{ops::Deref, sync::atomic::AtomicBool};

use log::debug;
use tauri::{Manager, State, SystemTrayHandle, Window};

use crate::{constants::*, Pinned};
Expand All @@ -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]
Expand All @@ -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<Pinned>) -> 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]
Expand All @@ -43,13 +52,16 @@ pub fn toggle_pin(window: Window, pin: State<Pinned>) {
let value = !get_pin(app.state::<Pinned>());

_set_pin(value, &window, pin);
debug!("Ran toggle_pin command");
}

#[tauri::command]
pub fn set_pin(window: Window, pin: State<Pinned>, 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;

Expand All @@ -59,7 +71,6 @@ impl Deref for Pinned {
}

fn _set_pin(value: bool, window: &Window, pinned: State<Pinned>) {
// @d0nutptr cooked here
pinned.store(value, std::sync::atomic::Ordering::Relaxed);

// let the client know
Expand Down Expand Up @@ -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);
}
11 changes: 9 additions & 2 deletions apps/desktop/src-tauri/src/config.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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));
Expand All @@ -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");
}
11 changes: 7 additions & 4 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -133,16 +135,17 @@ 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());

info!("Started app");
info!("App setup completed successfully!");
Ok(())
})
// Add the system tray
Expand Down

0 comments on commit 07bbcf9

Please sign in to comment.