|
|
@@ -300,72 +300,9 @@ impl WindowManager { |
| 300 |
300 |
} |
| 301 |
301 |
|
| 302 |
302 |
fn handle_restart(&self) -> Result<bool> { |
| 303 |
|
- let user_binary = get_config_path().join("oxwm-user"); |
| 304 |
|
- |
| 305 |
|
- if user_binary.exists() && self.needs_recompile()? { |
| 306 |
|
- println!("Config changed, recompiling..."); |
| 307 |
|
- self.recompile()?; |
| 308 |
|
- } |
| 309 |
|
- |
| 310 |
303 |
Ok(true) |
| 311 |
304 |
} |
| 312 |
305 |
|
| 313 |
|
- fn needs_recompile(&self) -> Result<bool> { |
| 314 |
|
- let config_dir = get_config_path(); |
| 315 |
|
- let binary_path = get_user_binary_path(); |
| 316 |
|
- |
| 317 |
|
- if !binary_path.exists() { |
| 318 |
|
- return Ok(true); |
| 319 |
|
- } |
| 320 |
|
- |
| 321 |
|
- let binary_time = std::fs::metadata(&binary_path)?.modified()?; |
| 322 |
|
- |
| 323 |
|
- let watch_files = ["config.rs", "main.rs", "Cargo.toml"]; |
| 324 |
|
- |
| 325 |
|
- for filename in &watch_files { |
| 326 |
|
- let path = config_dir.join(filename); |
| 327 |
|
- if !path.exists() { |
| 328 |
|
- continue; |
| 329 |
|
- } |
| 330 |
|
- |
| 331 |
|
- let file_time = std::fs::metadata(&path)?.modified()?; |
| 332 |
|
- if file_time > binary_time { |
| 333 |
|
- println!("✓ Change detected: {}", filename); |
| 334 |
|
- return Ok(true); |
| 335 |
|
- } |
| 336 |
|
- } |
| 337 |
|
- |
| 338 |
|
- Ok(false) |
| 339 |
|
- } |
| 340 |
|
- |
| 341 |
|
- fn recompile(&self) -> Result<()> { |
| 342 |
|
- let config_dir = get_config_path(); |
| 343 |
|
- |
| 344 |
|
- notify("OXWM", "Recompiling configuration..."); |
| 345 |
|
- |
| 346 |
|
- let output = std::process::Command::new("cargo") |
| 347 |
|
- .args(&["build", "--release"]) |
| 348 |
|
- .current_dir(&config_dir) |
| 349 |
|
- .output()?; |
| 350 |
|
- |
| 351 |
|
- if !output.status.success() { |
| 352 |
|
- let stderr = String::from_utf8_lossy(&output.stderr); |
| 353 |
|
- notify_error("OXWM Compile Error", &stderr); |
| 354 |
|
- eprintln!("Compilation failed:\n{}", stderr); |
| 355 |
|
- anyhow::bail!("Failed to compile configuration"); |
| 356 |
|
- } |
| 357 |
|
- |
| 358 |
|
- let source = config_dir.join("target/release/oxwm-user"); |
| 359 |
|
- let dest = get_user_binary_path(); |
| 360 |
|
- |
| 361 |
|
- std::fs::create_dir_all(dest.parent().unwrap())?; |
| 362 |
|
- std::fs::copy(&source, &dest)?; |
| 363 |
|
- |
| 364 |
|
- notify("OXWM", "Recompiled successfully! Restarting..."); |
| 365 |
|
- |
| 366 |
|
- Ok(()) |
| 367 |
|
- } |
| 368 |
|
- |
| 369 |
306 |
pub fn run(&mut self) -> Result<bool> { |
| 370 |
307 |
println!("oxwm started on display {}", self.screen_number); |
| 371 |
308 |
|
|
|
@@ -462,8 +399,12 @@ impl WindowManager { |
| 462 |
399 |
// Handled in handle_event |
| 463 |
400 |
} |
| 464 |
401 |
KeyAction::Recompile => { |
| 465 |
|
- if let Err(e) = self.recompile() { |
| 466 |
|
- eprintln!("Recompile failed: {}", e); |
|
402 |
+ match std::process::Command::new("oxwm") |
|
403 |
+ .arg("--recompile") |
|
404 |
+ .spawn() |
|
405 |
+ { |
|
406 |
+ Ok(_) => eprintln!("Recompiling in background"), |
|
407 |
+ Err(e) => eprintln!("Failed to spawn recompile: {}", e), |
| 467 |
408 |
} |
| 468 |
409 |
} |
| 469 |
410 |
KeyAction::ViewTag => { |
|
|
@@ -924,33 +865,3 @@ impl WindowManager { |
| 924 |
865 |
Ok(()) |
| 925 |
866 |
} |
| 926 |
867 |
} |
| 927 |
|
- |
| 928 |
|
-fn get_config_path() -> PathBuf { |
| 929 |
|
- dirs::config_dir() |
| 930 |
|
- .expect("Could not find config directory") |
| 931 |
|
- .join("oxwm") |
| 932 |
|
-} |
| 933 |
|
- |
| 934 |
|
-fn get_user_binary_path() -> PathBuf { |
| 935 |
|
- get_config_path().join("oxwm-user") |
| 936 |
|
-} |
| 937 |
|
- |
| 938 |
|
-fn can_recompile() -> bool { |
| 939 |
|
- std::process::Command::new("cargo") |
| 940 |
|
- .arg("--version") |
| 941 |
|
- .output() |
| 942 |
|
- .map(|o| o.status.success()) |
| 943 |
|
- .unwrap_or(false) |
| 944 |
|
-} |
| 945 |
|
- |
| 946 |
|
-fn notify(title: &str, body: &str) { |
| 947 |
|
- let _ = std::process::Command::new("notify-send") |
| 948 |
|
- .args(&[title, body]) |
| 949 |
|
- .spawn(); |
| 950 |
|
-} |
| 951 |
|
- |
| 952 |
|
-fn notify_error(title: &str, body: &str) { |
| 953 |
|
- let _ = std::process::Command::new("notify-send") |
| 954 |
|
- .args(&["-u", "critical", title, body]) |
| 955 |
|
- .spawn(); |
| 956 |
|
-} |