mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-28 11:22:47 +01:00
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:
1 parent
a2fa30acdc
commit
1e902542c7
2 files changed
+61
-59
No files matched your search
Generated
+1
@@ -3344,6 +3344,7 @@ version = "0.1.42"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
|
"color-eyre",
|
||||||
"komorebi-layouts",
|
"komorebi-layouts",
|
||||||
"komorebi-protocol",
|
"komorebi-protocol",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ use komorebic_core::cli::Cmd;
|
|||||||
use komorebic_core::cli::Meta;
|
use komorebic_core::cli::Meta;
|
||||||
use komorebic_core::cli::command;
|
use komorebic_core::cli::command;
|
||||||
use komorebic_core::docgen::DocFormat;
|
use komorebic_core::docgen::DocFormat;
|
||||||
|
use komorebic_core::launcher;
|
||||||
|
use komorebic_core::launcher::Launcher;
|
||||||
use komorebic_core::messages::Messages;
|
use komorebic_core::messages::Messages;
|
||||||
use komorebic_core::pan;
|
use komorebic_core::pan;
|
||||||
use komorebic_core::platform::macos::*;
|
use komorebic_core::platform::macos::*;
|
||||||
@@ -28,7 +30,6 @@ use std::process::Command;
|
|||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::time::Duration;
|
|
||||||
use sysinfo::ProcessesToUpdate;
|
use sysinfo::ProcessesToUpdate;
|
||||||
|
|
||||||
lazy_static! {
|
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.
|
/// What the top of the help and `--version` say.
|
||||||
const META: Meta = Meta {
|
const META: Meta = Meta {
|
||||||
name: "komorebic",
|
name: "komorebic",
|
||||||
@@ -552,61 +606,12 @@ exit 1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MacosCommands::Start(args) => {
|
MacosCommands::Start(args) => {
|
||||||
let mut command = &mut Command::new("komorebi");
|
let mut launcher = MacosLauncher {
|
||||||
|
args: &args,
|
||||||
if let Some(config) = &args.config {
|
system: sysinfo::System::new_all(),
|
||||||
command =
|
|
||||||
command.args(["--config", &format!("'--config=\"{}\"'", config.display())])
|
|
||||||
};
|
};
|
||||||
|
|
||||||
command = command
|
if !launcher::start(&mut launcher)? {
|
||||||
.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)?);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,11 +667,7 @@ exit 1
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
MacosCommands::Stop(args) => {
|
MacosCommands::Stop(args) => {
|
||||||
if args.ignore_restore {
|
send_message(&launcher::stop_message(args.ignore_restore))?;
|
||||||
send_message(&SocketMessage::StopIgnoreRestore)?;
|
|
||||||
} else {
|
|
||||||
send_message(&SocketMessage::Stop)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if args.bar {
|
if args.bar {
|
||||||
Command::new("pkill").arg("komorebi-bar").spawn()?;
|
Command::new("pkill").arg("komorebi-bar").spawn()?;
|
||||||
|
|||||||
Reference in new issue
Block a user