Parse window title and theme better

This commit is contained in:
Gregory Schier
2024-06-12 10:14:53 -07:00
parent 0674bae787
commit f9cd2fa7fa
3 changed files with 28 additions and 7 deletions

2
src-tauri/Cargo.lock generated
View File

@@ -8136,7 +8136,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "yaak" name = "yaak-app"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",

View File

@@ -1,4 +1,5 @@
use hex_color::HexColor; use hex_color::HexColor;
use log::warn;
use objc::{msg_send, sel, sel_impl}; use objc::{msg_send, sel, sel_impl};
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
use tauri::{ use tauri::{
@@ -25,15 +26,35 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
let window_for_theme = window.clone(); let window_for_theme = window.clone();
let id1 = h.listen("yaak_bg_changed", move |ev| { let id1 = h.listen("yaak_bg_changed", move |ev| {
let payload = serde_json::from_str::<&str>(ev.payload()).unwrap().trim(); let color_str: String = match serde_json::from_str(ev.payload()) {
let color = HexColor::parse_rgb(payload).unwrap(); Ok(color) => color,
update_window_theme(window_for_theme.clone(), color); Err(err) => {
warn!("Failed to JSON parse color '{}': {}", ev.payload(), err);
return;
}
};
match HexColor::parse_rgb(color_str.trim()) {
Ok(color) => {
update_window_theme(window_for_theme.clone(), color);
}
Err(err) => {
warn!("Failed to parse background color '{}': {}", color_str, err)
}
}
}); });
let window_for_title = window.clone(); let window_for_title = window.clone();
let id2 = h.listen("yaak_title_changed", move |ev| { let id2 = h.listen("yaak_title_changed", move |ev| {
let payload = serde_json::from_str::<&str>(ev.payload()).unwrap().trim(); let title: String = match serde_json::from_str(ev.payload()) {
update_window_title(window_for_title.clone(), payload.to_string()); Ok(title) => title,
Err(err) => {
warn!("Failed to parse window title \"{}\": {}", ev.payload(), err);
return;
}
};
update_window_title(window_for_title.clone(), title);
}); });
let h = h.clone(); let h = h.clone();

View File

@@ -1,6 +1,6 @@
{ {
"productName": "yaak", "productName": "yaak",
"version": "2024.6.2", "version": "2024.6.3",
"identifier": "app.yaak.desktop", "identifier": "app.yaak.desktop",
"build": { "build": {
"beforeBuildCommand": "npm run build", "beforeBuildCommand": "npm run build",