Skip to content

Commit

Permalink
Merge pull request #22 from AaronErhardt/fix-missing-perf-prof
Browse files Browse the repository at this point in the history
tailord: Gracefully handle missing performance profiles
  • Loading branch information
AaronErhardt authored Aug 30, 2023
2 parents 30209f9 + 7a45ee7 commit a1338db
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 74 deletions.
5 changes: 2 additions & 3 deletions tailor_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use crate::cli::{Command, Opts};
#[tokio::main]
async fn main() -> Result<()> {
let args = Opts::parse();
match args.command {
Some(Command::Profile { profile_cmd }) => profile::handle(profile_cmd).await?,
None => {}
if let Some(Command::Profile { profile_cmd }) = args.command {
profile::handle(profile_cmd).await?;
}
Ok(())
}
2 changes: 1 addition & 1 deletion tailor_cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) async fn handle(cmd: ProfileCommand) -> Result<()> {
if let Some(next_profile_name) = next_profile_name {
let profile_updated_msg = format!("Current profile: {}", next_profile_name);
connection
.set_active_global_profile_name(&next_profile_name)
.set_active_global_profile_name(next_profile_name)
.await?;
if verbose {
println!("{}", profile_updated_msg)
Expand Down
4 changes: 2 additions & 2 deletions tailor_gui/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"mesonbuild.configureOnOpen": false,
"mesonbuild.buildFolder": "_build",
"mesonbuild.mesonPath": "/home/aaron/Nextcloud/dev/Projects/Active/tuxedo-rs/tailor_gui/.flatpak/meson.sh",
"rust-analyzer.server.path": "/home/aaron/Nextcloud/dev/Projects/Active/tuxedo-rs/tailor_gui/.flatpak/rust-analyzer.sh",
"rust-analyzer.runnables.command": "/home/aaron/Nextcloud/dev/Projects/Active/tuxedo-rs/tailor_gui/.flatpak/cargo.sh",
"rust-analyzer.server.path": "${workspaceFolder}/.flatpak/rust-analyzer.sh",
"rust-analyzer.runnables.command": "${workspaceFolder}/.flatpak/cargo.sh",
"rust-analyzer.files.excludeDirs": [
".flatpak"
]
Expand Down
111 changes: 82 additions & 29 deletions tailor_gui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tailor_gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ repository = "https://github.com/AaronErhardt/tuxedo-rs"
futures = "0.3.28"
gettext-rs = { version = "0.7", features = ["gettext-system"] }
once_cell = "1.17.1"
relm4-components = { version = "0.6.0-beta.1" }
relm4 = { version = "0.6.0-beta.1", features = ["libadwaita", "gnome_44"] }
relm4-components = { version = "0.6.0" }
relm4 = { version = "0.6.0", features = ["libadwaita", "gnome_44"] }
tailor_api = "0.2.1"
tailor_client = "0.2.1"
tokio = { version = "1.27", features = ["parking_lot"] }
tracing = "0.1"
tracing-subscriber = "0.3"
tracker = "0.2"
relm4-icons = { version = "0.6.0-beta.6", features = ["plus", "settings", "speedometer", "menu-large", "up", "down", "color", "cross-filled", "data-bar-vertical-ascending-filled"] }
relm4-icons = { version = "0.6.0", features = ["plus", "settings", "speedometer", "menu-large", "up", "down", "color", "cross-filled", "data-bar-vertical-ascending-filled"] }
40 changes: 21 additions & 19 deletions tailor_gui/src/components/factories/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Profile {
pub active: bool,
pub leds: FactoryVecDeque<ProfileItemLed>,
pub fans: FactoryVecDeque<ProfileItemFan>,
pub performance: Controller<SimpleComboBox<String>>,
pub performance: Option<Controller<SimpleComboBox<String>>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -96,6 +96,8 @@ impl FactoryComponent for Profile {

#[template]
add_row = &templates::ProfileListItem {
set_visible: self.performance.is_some(),

#[template_child]
image -> gtk::Image {
set_icon_name: Some(icon_name::SPEEDOMETER),
Expand All @@ -108,7 +110,7 @@ impl FactoryComponent for Profile {

#[template_child]
row -> gtk::Box {
append: self.performance.widget(),
append?: self.performance.as_ref().map(Controller::widget),
}
}
}
Expand Down Expand Up @@ -186,18 +188,21 @@ impl FactoryComponent for Profile {
}
}

let active_index = info.performance_profile.as_ref().and_then(|profile| {
capabilities
.performance_profiles
.iter()
.position(|name| name == profile)
});
let performance = SimpleComboBox::builder()
.launch(SimpleComboBox {
variants: capabilities.performance_profiles.clone(),
active_index,
})
.forward(sender.input_sender(), |_| ProfileInput::UpdateProfile);
let performance = capabilities
.performance_profiles
.as_ref()
.map(|cap_perf_prof| {
let active_index = info
.performance_profile
.as_ref()
.and_then(|profile| cap_perf_prof.iter().position(|name| name == profile));
SimpleComboBox::builder()
.launch(SimpleComboBox {
variants: cap_perf_prof.clone(),
active_index,
})
.forward(sender.input_sender(), |_| ProfileInput::UpdateProfile)
});

Self {
name,
Expand Down Expand Up @@ -227,11 +232,8 @@ impl FactoryComponent for Profile {

let performance_profile = self
.performance
.state()
.get()
.model
.get_active_elem()
.cloned();
.as_ref()
.and_then(|perf| perf.state().get().model.get_active_elem().cloned());

self.info = ProfileInfo {
leds,
Expand Down
Loading

0 comments on commit a1338db

Please sign in to comment.