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 | 23 | let cache_binary = get_cache_binary_path(); |
| 23 | 24 | |
| 24 | - if cache_binary.exists() { | |
| 25 | - let config_path = get_config_path().join("config.rs"); | |
| 26 | - if should_recompile(&config_path, &cache_binary)? { | |
| 27 | - println!("Config changed, recompiling..."); | |
| 28 | - recompile_config()?; | |
| 29 | - } | |
| 30 | - | |
| 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 | - } | |
| 25 | + if !config_path.exists() { | |
| 26 | + init_config()?; | |
| 27 | + notify( | |
| 28 | + "OXWM First Run", | |
| 29 | + "Config created at ~/.config/oxwm/config.rs\nEdit and reload with Mod+Shift+R", | |
| 30 | + ); | |
| 31 | + } | |
| 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 | 43 | #[derive(Debug)] |
| @@ -84,12 +68,6 @@ fn init_config() -> Result<()> { | ||
| 84 | 68 | let config_dir = get_config_path(); |
| 85 | 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 | 71 | let config_template = include_str!("../../templates/config.rs"); |
| 94 | 72 | std::fs::write(config_dir.join("config.rs"), config_template)?; |
| 95 | 73 | |
| @@ -129,20 +107,8 @@ pkgs.mkShell { | ||
| 129 | 107 | } |
| 130 | 108 | "#; |
| 131 | 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 | 112 | Ok(()) |
| 147 | 113 | } |
| 148 | 114 | |
| @@ -182,14 +148,7 @@ fn recompile_config() -> Result<()> { | ||
| 182 | 148 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 183 | 149 | eprintln!("\n❌ Compilation failed:\n{}", stderr); |
| 184 | 150 | |
| 185 | - let _ = Command::new("notify-send") | |
| 186 | - .args(&[ | |
| 187 | - "-u", | |
| 188 | - "critical", | |
| 189 | - "OXWM Compile Error", | |
| 190 | - "Check terminal for details", | |
| 191 | - ]) | |
| 192 | - .spawn(); | |
| 151 | + notify_error("OXWM Compile Error", "Check terminal for details"); | |
| 193 | 152 | |
| 194 | 153 | anyhow::bail!("Failed to compile configuration"); |
| 195 | 154 | } |
| @@ -211,12 +170,10 @@ fn recompile_config() -> Result<()> { | ||
| 211 | 170 | |
| 212 | 171 | println!("✓ Compiled successfully"); |
| 213 | 172 | |
| 214 | - let _ = Command::new("notify-send") | |
| 215 | - .args(&[ | |
| 216 | - "OXWM", | |
| 217 | - "Configuration recompiled! Hit Mod+Shift+R to restart.", | |
| 218 | - ]) | |
| 219 | - .spawn(); | |
| 173 | + notify( | |
| 174 | + "OXWM", | |
| 175 | + "Configuration recompiled! Hit Mod+Shift+R to restart.", | |
| 176 | + ); | |
| 220 | 177 | |
| 221 | 178 | Ok(()) |
| 222 | 179 | } |
| @@ -270,24 +227,27 @@ fn get_cache_binary_path() -> PathBuf { | ||
| 270 | 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 | 240 | fn print_help() { |
| 274 | 241 | println!("OXWM - A dynamic window manager written in Rust\n"); |
| 275 | 242 | println!("USAGE:"); |
| 276 | 243 | println!(" oxwm [OPTIONS]\n"); |
| 277 | 244 | println!("OPTIONS:"); |
| 278 | - println!(" --init Initialize user configuration in ~/.config/oxwm"); | |
| 279 | - println!(" --recompile Recompile user configuration"); | |
| 245 | + println!(" --init Recreate config template in ~/.config/oxwm"); | |
| 246 | + println!(" --recompile Manually recompile configuration"); | |
| 280 | 247 | println!(" --version Print version information"); |
| 281 | 248 | println!(" --help Print this help message\n"); |
| 282 | - println!("CONFIGURATION:"); | |
| 283 | - println!(" Without --init: Runs with built-in defaults"); | |
| 284 | - println!(" With --init: Uses custom config from ~/.config/oxwm/config.rs"); | |
| 285 | - println!(" Reload hotkey: Mod+Shift+R (auto-recompiles if needed)\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"); | |
| 249 | + println!("FIRST RUN:"); | |
| 250 | + println!(" Just run 'oxwm' - config will be auto-generated at:"); | |
| 251 | + println!(" ~/.config/oxwm/config.rs"); | |
| 252 | + println!("\n Edit your config and reload with Mod+Shift+R\n"); | |
| 293 | 253 | } |