1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-20 11:54:23 +02:00
ironbar/src/ipc/server/bar.rs
Jake Stanger 9dd711235f
feat!: improve CLI structure, add new commands
This splits most CLI/IPC commands into two categories:

- `var` for ironvars
- `bar` for controlling individual bars.

It also introduces more commands for visibility, as well as breaking existing ones.

New commands:

- `show`
- `hide`
- `toggle_visible`
- `set_popup_visible`
- `get_popup_visible`

Lastly, the implementation of some existing commands has been improved.

BREAKING CHANGE: All IPC commands have changed. Namely, `type` has been changed to `command`, and bar/var related commands are now under a `subcommand`. The full spec can be found on the wiki.

BREAKING CHANGE: Several CLI commands are now located under the `var` and `bar` categories. Usage of any commands to get/set Ironvars or control bar visibility will need to be updated.

BREAKING CHANGE: The `open_popup` and `close_popup` IPC commands are now called `show_popup` and `hide_popup` respectively.

BREAKING CHANGE: The popup `name` argument has been renamed to `widget_name` on all IPC commands.

BREAKING CHANGE: The `set-visibility` CLI command now takes a `true`/`false` positional argument in place of the `-v` flag.

BREAKING CHANGE: `ok_value` responses will no longer print `ok` as the first line when using the CLI
2024-06-01 17:04:51 +01:00

84 lines
2.3 KiB
Rust

use super::Response;
use crate::bar::Bar;
use crate::ipc::{BarCommand, BarCommandType};
use crate::modules::PopupButton;
use crate::Ironbar;
use std::rc::Rc;
pub fn handle_command(command: BarCommand, ironbar: &Rc<Ironbar>) -> Response {
let bar = ironbar.bar_by_name(&command.name);
let Some(bar) = bar else {
return Response::error("Invalid bar name");
};
use BarCommandType::*;
match command.subcommand {
Show => set_visible(&bar, true),
Hide => set_visible(&bar, false),
SetVisible { visible } => set_visible(&bar, visible),
ToggleVisible => set_visible(&bar, !bar.visible()),
GetVisible => Response::OkValue {
value: bar.visible().to_string(),
},
ShowPopup { widget_name } => show_popup(&bar, widget_name),
HidePopup => hide_popup(&bar),
SetPopupVisible {
widget_name,
visible,
} => {
if visible {
show_popup(&bar, widget_name)
} else {
hide_popup(&bar)
}
}
TogglePopup { widget_name } => {
if bar.popup().visible() {
hide_popup(&bar)
} else {
show_popup(&bar, widget_name)
}
}
GetPopupVisible => Response::OkValue {
value: bar.popup().visible().to_string(),
},
}
}
fn set_visible(bar: &Bar, visible: bool) -> Response {
bar.set_visible(visible);
Response::Ok
}
fn show_popup(bar: &Bar, widget_name: String) -> Response {
let popup = bar.popup();
// only one popup per bar, so hide if open for another widget
popup.hide();
let data = popup
.container_cache
.borrow()
.iter()
.find(|(_, value)| value.name == widget_name)
.map(|(id, value)| (*id, value.content.buttons.first().cloned()));
match data {
Some((id, Some(button))) => {
let button_id = button.popup_id();
popup.show(id, button_id);
Response::Ok
}
Some((_, None)) => Response::error("Module has no popup functionality"),
None => Response::error("Invalid module name"),
}
}
fn hide_popup(bar: &Bar) -> Response {
let popup = bar.popup();
popup.hide();
Response::Ok
}