refactor(komorebic): the macOS start and stop use the Launcher skeleton of komorebic-core

start becomes a MacosLauncher around komorebic_core::launcher::start; the companion bar and the licence text after it stay as they were, and stop sends launcher::stop_message. The odd '--config' arguments macOS passes are kept as they were. 'Waiting for komorebi to start... ' is now flushed as KDE's was (the text is the same).

Verified: macOS fake-CC cargo check --locked --workspace --all-targets: 0 errors. Not verified: running komorebic start on macOS.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent a2fa30acdc
commit 1e902542c7
2 files changed
+61 -59

No files matched your search

+1
View File
@@ -3344,6 +3344,7 @@ version = "0.1.42"
dependencies = [
"clap",
"clap_complete",
"color-eyre",
"komorebi-layouts",
"komorebi-protocol",
]
+60 -59
View File
@@ -13,6 +13,8 @@ use komorebic_core::cli::Cmd;
use komorebic_core::cli::Meta;
use komorebic_core::cli::command;
use komorebic_core::docgen::DocFormat;
use komorebic_core::launcher;
use komorebic_core::launcher::Launcher;
use komorebic_core::messages::Messages;
use komorebic_core::pan;
use komorebic_core::platform::macos::*;
@@ -28,7 +30,6 @@ use std::process::Command;
use std::process::Stdio;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
use sysinfo::ProcessesToUpdate;
lazy_static! {
@@ -61,6 +62,59 @@ fn print_query(message: &SocketMessage) {
}
}
/// Starting `komorebi` for `komorebic start`: a `Command` for the daemon, found among the
/// processes by its exact name.
struct MacosLauncher<'a> {
args: &'a Start,
system: sysinfo::System,
}
impl Launcher for MacosLauncher<'_> {
fn daemon_name(&self) -> &str {
"komorebi"
}
fn spawn(&mut self) -> eyre::Result<()> {
let mut command = Command::new("komorebi");
if let Some(config) = &self.args.config {
command.args(["--config", &format!("'--config=\"{}\"'", config.display())]);
}
command
.stdout(Stdio::null())
.stderr(Stdio::null())
.stdin(Stdio::null())
.spawn()?;
Ok(())
}
fn is_running(&mut self) -> eyre::Result<bool> {
self.system.refresh_processes(ProcessesToUpdate::All, true);
Ok(self
.system
.processes_by_exact_name("komorebi".as_ref())
.next()
.is_some())
}
fn diagnose(&mut self) -> eyre::Result<()> {
let mut command = Command::new("komorebi");
if let Some(config) = &self.args.config {
command.arg(format!("'--config=\"{}\"'", config.display()));
}
if let Ok(output) = command.output() {
println!("{}", String::from_utf8(output.stderr)?);
}
Ok(())
}
}
/// What the top of the help and `--version` say.
const META: Meta = Meta {
name: "komorebic",
@@ -552,61 +606,12 @@ exit 1
}
}
MacosCommands::Start(args) => {
let mut command = &mut Command::new("komorebi");
if let Some(config) = &args.config {
command =
command.args(["--config", &format!("'--config=\"{}\"'", config.display())])
let mut launcher = MacosLauncher {
args: &args,
system: sysinfo::System::new_all(),
};
command = command
.stdout(Stdio::null())
.stderr(Stdio::null())
.stdin(Stdio::null());
let mut system = sysinfo::System::new_all();
system.refresh_processes(ProcessesToUpdate::All, true);
let mut attempts = 0;
let mut running = system
.processes_by_exact_name("komorebi".as_ref())
.next()
.is_some();
while !running && attempts <= 2 {
command.spawn()?;
print!("Waiting for komorebi to start... ");
std::thread::sleep(Duration::from_secs(3));
system.refresh_processes(ProcessesToUpdate::All, true);
if system
.processes_by_exact_name("komorebi".as_ref())
.next()
.is_some()
{
println!("Started!");
running = true;
} else {
println!("komorebi did not start... Trying again");
attempts += 1;
}
}
if !running {
println!("\nRunning komorebi directly for detailed error output\n");
if let Some(config) = &args.config {
if let Ok(output) = Command::new("komorebi")
.arg(format!("'--config=\"{}\"'", config.display()))
.output()
{
println!("{}", String::from_utf8(output.stderr)?);
}
} else if let Ok(output) = Command::new("komorebi").output() {
println!("{}", String::from_utf8(output.stderr)?);
}
if !launcher::start(&mut launcher)? {
return Ok(());
}
@@ -662,11 +667,7 @@ exit 1
);
}
MacosCommands::Stop(args) => {
if args.ignore_restore {
send_message(&SocketMessage::StopIgnoreRestore)?;
} else {
send_message(&SocketMessage::Stop)?;
}
send_message(&launcher::stop_message(args.ignore_restore))?;
if args.bar {
Command::new("pkill").arg("komorebi-bar").spawn()?;