Fixed unecessary init requirement if user already has config file.
Browse files
+36 −76 src/bin/main.rs
| @@ -19,41 +19,25 @@ fn main() -> Result<()> { | |||
| 19 | _ => {} | 19 | _ => {} |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | + let config_path = get_config_path().join("config.rs"); | ||
| 22 | let cache_binary = get_cache_binary_path(); | 23 | let cache_binary = get_cache_binary_path(); |
| 23 | 24 | ||
| 24 | - if cache_binary.exists() { | 25 | + if !config_path.exists() { |
| 25 | - let config_path = get_config_path().join("config.rs"); | 26 | + init_config()?; |
| 26 | - if should_recompile(&config_path, &cache_binary)? { | 27 | + notify( |
| 27 | - println!("Config changed, recompiling..."); | 28 | + "OXWM First Run", |
| 28 | - recompile_config()?; | 29 | + "Config created at ~/.config/oxwm/config.rs\nEdit and reload with Mod+Shift+R", |
| 29 | - } | 30 | + ); |
| 30 | - | 31 | + } |
| 31 | - use std::os::unix::process::CommandExt; | ||
| 32 | - let err = Command::new(&cache_binary).args(&args[1..]).exec(); | ||
| 33 | - anyhow::bail!("Failed to exec user binary: {}", err); | ||
| 34 | - } else { | ||
| 35 | - eprintln!("╔════════════════════════════════════════╗"); | ||
| 36 | - eprintln!("║ OXWM: Running with default config ║"); | ||
| 37 | - eprintln!("╚════════════════════════════════════════╝"); | ||
| 38 | - eprintln!(); | ||
| 39 | - eprintln!("ℹ️ Run 'oxwm --init' to create a custom config"); | ||
| 40 | - eprintln!(); | ||
| 41 | - | ||
| 42 | - let config = oxwm::Config::default(); | ||
| 43 | - | ||
| 44 | - let mut wm = oxwm::window_manager::WindowManager::new(config)?; | ||
| 45 | - let should_restart = wm.run()?; | ||
| 46 | - | ||
| 47 | - drop(wm); | ||
| 48 | - | ||
| 49 | - if should_restart { | ||
| 50 | - use std::os::unix::process::CommandExt; | ||
| 51 | - let err = Command::new(&args[0]).args(&args[1..]).exec(); | ||
| 52 | - eprintln!("Failed to restart: {}", err); | ||
| 53 | - } | ||
| 54 | 32 | ||
| 55 | - Ok(()) | 33 | + if !cache_binary.exists() || should_recompile(&config_path, &cache_binary)? { |
| 34 | + recompile_config()?; | ||
| 56 | } | 35 | } |
| 36 | + | ||
| 37 | + use std::os::unix::process::CommandExt; | ||
| 38 | + let err = Command::new(&cache_binary).args(&args[1..]).exec(); | ||
| 39 | + eprintln!("Failed to exec: {}", err); | ||
| 40 | + std::process::exit(1); | ||
| 57 | } | 41 | } |
| 58 | 42 | ||
| 59 | #[derive(Debug)] | 43 | #[derive(Debug)] |
| @@ -84,12 +68,6 @@ fn init_config() -> Result<()> { | |||
| 84 | let config_dir = get_config_path(); | 68 | let config_dir = get_config_path(); |
| 85 | std::fs::create_dir_all(&config_dir)?; | 69 | std::fs::create_dir_all(&config_dir)?; |
| 86 | 70 | ||
| 87 | - if config_dir.join("config.rs").exists() { | ||
| 88 | - eprintln!("Config already exists at ~/.config/oxwm/config.rs"); | ||
| 89 | - eprintln!("Remove it first if you want to reinitialize."); | ||
| 90 | - return Ok(()); | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | let config_template = include_str!("../../templates/config.rs"); | 71 | let config_template = include_str!("../../templates/config.rs"); |
| 94 | std::fs::write(config_dir.join("config.rs"), config_template)?; | 72 | std::fs::write(config_dir.join("config.rs"), config_template)?; |
| 95 | 73 | ||
| @@ -129,20 +107,8 @@ pkgs.mkShell { | |||
| 129 | } | 107 | } |
| 130 | "#; | 108 | "#; |
| 131 | std::fs::write(config_dir.join("shell.nix"), shell_nix)?; | 109 | std::fs::write(config_dir.join("shell.nix"), shell_nix)?; |
| 132 | - println!("✓ Created shell.nix for NixOS"); | ||
| 133 | } | 110 | } |
| 134 | 111 | ||
| 135 | - println!("✓ Created ~/.config/oxwm/config.rs"); | ||
| 136 | - println!("✓ Created ~/.config/oxwm/main.rs"); | ||
| 137 | - println!("✓ Edit ~/.config/oxwm/config.rs to customize your setup"); | ||
| 138 | - | ||
| 139 | - println!("\nCompiling initial configuration..."); | ||
| 140 | - recompile_config()?; | ||
| 141 | - | ||
| 142 | - println!("\n✓ Setup complete!"); | ||
| 143 | - println!(" Your custom config is now active"); | ||
| 144 | - println!(" Reload config anytime with Mod+Shift+R"); | ||
| 145 | - | ||
| 146 | Ok(()) | 112 | Ok(()) |
| 147 | } | 113 | } |
| 148 | 114 | ||
| @@ -182,14 +148,7 @@ fn recompile_config() -> Result<()> { | |||
| 182 | let stderr = String::from_utf8_lossy(&output.stderr); | 148 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 183 | eprintln!("\n❌ Compilation failed:\n{}", stderr); | 149 | eprintln!("\n❌ Compilation failed:\n{}", stderr); |
| 184 | 150 | ||
| 185 | - let _ = Command::new("notify-send") | 151 | + notify_error("OXWM Compile Error", "Check terminal for details"); |
| 186 | - .args(&[ | ||
| 187 | - "-u", | ||
| 188 | - "critical", | ||
| 189 | - "OXWM Compile Error", | ||
| 190 | - "Check terminal for details", | ||
| 191 | - ]) | ||
| 192 | - .spawn(); | ||
| 193 | 152 | ||
| 194 | anyhow::bail!("Failed to compile configuration"); | 153 | anyhow::bail!("Failed to compile configuration"); |
| 195 | } | 154 | } |
| @@ -211,12 +170,10 @@ fn recompile_config() -> Result<()> { | |||
| 211 | 170 | ||
| 212 | println!("✓ Compiled successfully"); | 171 | println!("✓ Compiled successfully"); |
| 213 | 172 | ||
| 214 | - let _ = Command::new("notify-send") | 173 | + notify( |
| 215 | - .args(&[ | 174 | + "OXWM", |
| 216 | - "OXWM", | 175 | + "Configuration recompiled! Hit Mod+Shift+R to restart.", |
| 217 | - "Configuration recompiled! Hit Mod+Shift+R to restart.", | 176 | + ); |
| 218 | - ]) | ||
| 219 | - .spawn(); | ||
| 220 | 177 | ||
| 221 | Ok(()) | 178 | Ok(()) |
| 222 | } | 179 | } |
| @@ -270,24 +227,27 @@ fn get_cache_binary_path() -> PathBuf { | |||
| 270 | .join("oxwm/oxwm-binary") | 227 | .join("oxwm/oxwm-binary") |
| 271 | } | 228 | } |
| 272 | 229 | ||
| 230 | +fn notify(title: &str, body: &str) { | ||
| 231 | + let _ = Command::new("notify-send").args(&[title, body]).spawn(); | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +fn notify_error(title: &str, body: &str) { | ||
| 235 | + let _ = Command::new("notify-send") | ||
| 236 | + .args(&["-u", "critical", title, body]) | ||
| 237 | + .spawn(); | ||
| 238 | +} | ||
| 239 | + | ||
| 273 | fn print_help() { | 240 | fn print_help() { |
| 274 | println!("OXWM - A dynamic window manager written in Rust\n"); | 241 | println!("OXWM - A dynamic window manager written in Rust\n"); |
| 275 | println!("USAGE:"); | 242 | println!("USAGE:"); |
| 276 | println!(" oxwm [OPTIONS]\n"); | 243 | println!(" oxwm [OPTIONS]\n"); |
| 277 | println!("OPTIONS:"); | 244 | println!("OPTIONS:"); |
| 278 | - println!(" --init Initialize user configuration in ~/.config/oxwm"); | 245 | + println!(" --init Recreate config template in ~/.config/oxwm"); |
| 279 | - println!(" --recompile Recompile user configuration"); | 246 | + println!(" --recompile Manually recompile configuration"); |
| 280 | println!(" --version Print version information"); | 247 | println!(" --version Print version information"); |
| 281 | println!(" --help Print this help message\n"); | 248 | println!(" --help Print this help message\n"); |
| 282 | - println!("CONFIGURATION:"); | 249 | + println!("FIRST RUN:"); |
| 283 | - println!(" Without --init: Runs with built-in defaults"); | 250 | + println!(" Just run 'oxwm' - config will be auto-generated at:"); |
| 284 | - println!(" With --init: Uses custom config from ~/.config/oxwm/config.rs"); | 251 | + println!(" ~/.config/oxwm/config.rs"); |
| 285 | - println!(" Reload hotkey: Mod+Shift+R (auto-recompiles if needed)\n"); | 252 | + println!("\n Edit your config and reload with Mod+Shift+R\n"); |
| 286 | - println!("SETUP:"); | ||
| 287 | - println!(" 1. Add 'exec oxwm' to your ~/.xinitrc (works immediately with defaults)"); | ||
| 288 | - println!(" 2. Optionally run 'oxwm --init' to create custom config"); | ||
| 289 | - println!(" 3. Edit ~/.config/oxwm/config.rs to customize"); | ||
| 290 | - println!(" 4. Restart with Mod+Shift+R\n"); | ||
| 291 | - println!("ADVANCED:"); | ||
| 292 | - println!(" Create flake.nix or shell.nix in ~/.config/oxwm to use nix builds"); | ||
| 293 | } | 253 | } |