Add commandline option "theme" to switch to dark or light mode before starting gossip

This commit is contained in:
Bu5hm4nn 2024-08-07 14:35:47 +02:00
parent 9a3a3214b6
commit 8a157ce2e6

View File

@ -25,7 +25,7 @@ impl Command {
}
}
const COMMANDS: [Command; 38] = [
const COMMANDS: [Command; 39] = [
Command {
cmd: "oneshot",
usage_params: "{depends}",
@ -196,6 +196,11 @@ const COMMANDS: [Command; 38] = [
usage_params: "",
desc: "Reprocess relay lists (including kind 3 contents)",
},
Command {
cmd: "theme",
usage_params: "<dark | light>",
desc: "Start gossip with the selected theme",
},
Command {
cmd: "ungiftwrap",
usage_params: "<idhex>",
@ -274,6 +279,10 @@ pub fn handle_command(mut args: env::Args, runtime: &Runtime) -> Result<bool, Er
"rename_person_list" => rename_person_list(command, args)?,
"reprocess_recent" => reprocess_recent(command, runtime)?,
"reprocess_relay_lists" => reprocess_relay_lists()?,
"theme" => {
set_theme(command, args)?;
return Ok(false);
}
"ungiftwrap" => ungiftwrap(command, args)?,
"verify" => verify(command, args)?,
"verify_json" => verify_json(command, args)?,
@ -986,6 +995,27 @@ pub fn reprocess_relay_lists() -> Result<(), Error> {
Ok(())
}
pub fn set_theme(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let theme = match args.next() {
Some(s) => s,
None => return cmd.usage("Missing theme selection".to_string()),
};
match theme.as_str() {
"dark" => {
GLOBALS.storage.write_setting_dark_mode(&true, None)?;
println!("Setting 'dark' theme");
}
"light" => {
GLOBALS.storage.write_setting_dark_mode(&false, None)?;
println!("Setting 'light' theme");
}
_ => return cmd.usage("Invalid theme selection".to_string()),
};
Ok(())
}
pub fn verify(cmd: Command, mut args: env::Args) -> Result<(), Error> {
let idstr = match args.next() {
Some(id) => id,