diff --git a/Cargo.lock b/Cargo.lock index 09180303..fd0079f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2929,6 +2929,7 @@ dependencies = [ "os_info", "parking_lot", "paste", + "powershell_script", "regex", "reqwest", "schemars", diff --git a/komorebi-bar/src/widgets/komorebi.rs b/komorebi-bar/src/widgets/komorebi.rs index 7b99ba25..332c8bc7 100644 --- a/komorebi-bar/src/widgets/komorebi.rs +++ b/komorebi-bar/src/widgets/komorebi.rs @@ -472,55 +472,25 @@ impl BarWidget for Komorebi { for (name, location) in configuration_switcher.configurations.iter() { let path = PathBuf::from(location); if path.is_file() { - config.apply_on_widget(false, ui,|ui|{ - if SelectableFrame::new(false).show(ui, |ui|{ - ui.add(Label::new(name).selectable(false)) - }) - .clicked() - { - let canonicalized = dunce::canonicalize(path.clone()).unwrap_or(path); - let mut proceed = true; - if komorebi_client::send_message(&SocketMessage::ReplaceConfiguration( - canonicalized, - )) - .is_err() + config.apply_on_widget(false, ui, |ui| { + if SelectableFrame::new(false) + .show(ui, |ui| ui.add(Label::new(name).selectable(false))) + .clicked() { - tracing::error!( - "could not send message to komorebi: ReplaceConfiguration" - ); - proceed = false; - } + let canonicalized = + dunce::canonicalize(path.clone()).unwrap_or(path); - if let Some(rect) = komorebi_notification_state.work_area_offset { - if proceed { - match komorebi_client::send_query(&SocketMessage::Query( - komorebi_client::StateQuery::FocusedMonitorIndex, - )) { - Ok(idx) => { - if let Ok(monitor_idx) = idx.parse::() { - if komorebi_client::send_message( - &SocketMessage::MonitorWorkAreaOffset( - monitor_idx, - rect, - ), - ) - .is_err() - { - tracing::error!( - "could not send message to komorebi: MonitorWorkAreaOffset" - ); - } - } - } - Err(_) => { - tracing::error!( - "could not send message to komorebi: Query" - ); - } - } + if komorebi_client::send_message( + &SocketMessage::ReplaceConfiguration(canonicalized), + ) + .is_err() + { + tracing::error!( + "could not send message to komorebi: ReplaceConfiguration" + ); } } - }}); + }); } } } diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 79c2f078..f99cbbe8 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -27,6 +27,7 @@ net2 = "0.2" os_info = "3.10" parking_lot = "0.12" paste = { workspace = true } +powershell_script = "1.0" regex = "1" schemars = { workspace = true, optional = true } serde = { workspace = true } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 66be0861..8f5de4a5 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1682,6 +1682,65 @@ impl WindowManager { // Set self to the new wm instance *self = wm; + // check if there are any bars + let mut system = sysinfo::System::new_all(); + system.refresh_processes(sysinfo::ProcessesToUpdate::All, true); + + let has_bar = system + .processes_by_name("komorebi-bar.exe".as_ref()) + .next() + .is_some(); + + // stop bar(s) + if has_bar { + let script = r" +Stop-Process -Name:komorebi-bar -ErrorAction SilentlyContinue + "; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + + // start new bar(s) + let mut config = StaticConfig::read(config)?; + if let Some(display_bar_configurations) = + &mut config.bar_configurations + { + for config_file_path in &mut *display_bar_configurations { + let script = r#"Start-Process "komorebi-bar" '"--config" "CONFIGFILE"' -WindowStyle hidden"# + .replace("CONFIGFILE", &config_file_path.to_string_lossy()); + + match powershell_script::run(&script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + } else { + let script = r" +if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue)) +{ + Start-Process komorebi-bar -WindowStyle hidden +} + "; + match powershell_script::run(script) { + Ok(_) => { + println!("{script}"); + } + Err(error) => { + println!("Error: {error}"); + } + } + } + } + Err(error) => { + println!("Error: {error}"); + } + } + } + force_update_borders = true; } }