1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-03 03:31:03 +02:00

feat: support for 'ironvar' dynamic variables

This commit is contained in:
Jake Stanger 2023-06-22 23:07:40 +01:00
parent f5bdc5a027
commit ded50cca6f
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
17 changed files with 613 additions and 195 deletions

View file

@ -10,5 +10,21 @@ pub enum Command {
/// Open the GTK inspector
Inspect,
}
/// Set an `ironvar` value.
/// This creates it if it does not already exist, and updates it if it does.
/// Any references to this variable are automatically and immediately updated.
/// Keys and values can be any valid UTF-8 string.
Set {
/// Variable key. Can be any valid UTF-8 string.
key: Box<str>,
/// Variable value. Can be any valid UTF-8 string.
value: String,
},
/// Get the current value of an `ironvar`.
Get {
/// Variable key.
key: Box<str>,
},
}

View file

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "type")]
pub enum Response {
Ok,
OkValue { value: String },
Err { message: Option<String> },
}

View file

@ -106,6 +106,22 @@ impl Ipc {
Command::Inspect => {
gtk::Window::set_interactive_debugging(true);
Response::Ok
},
Command::Set { key, value } => {
let variable_manager = get_variable_manager();
let mut variable_manager = write_lock!(variable_manager);
match variable_manager.set(key, value) {
Ok(_) => Response::Ok,
Err(err) => Response::error(&format!("{err}")),
}
}
Command::Get { key } => {
let variable_manager = get_variable_manager();
let value = read_lock!(variable_manager).get(&key);
match value {
Some(value) => Response::OkValue { value },
None => Response::error("Variable not found"),
}
}
Command::Ping => Response::Ok,
}