mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-05-07 22:58:05 +03:00
fix: write a default config.toml on every Config::new()
The previous fix created the config directory but left config.toml absent on a first launch, which surfaced as two "No such file or directory (os error 2)" warnings (one from the main process, one from the spawned daemon child) and left the app starting up with config_toml=None until the GUI persisted something. Write ConfigToml::default() to the path if it doesn't exist, so every entry point — GUI main, spawned daemon, CLI, test commands — gets a concrete file to read, and first-launch logs stay clean. Also reorders Config::new() so both the directory creation and the file bootstrap run before the first read attempt, eliminating the warning at the source rather than hiding it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Ferdinand Schober
parent
5e79743bd0
commit
cbdb86ce05
@@ -334,6 +334,23 @@ impl Config {
|
||||
.config
|
||||
.clone()
|
||||
.unwrap_or(default_path()?.join(CONFIG_FILE_NAME));
|
||||
let config_dir = config_path
|
||||
.parent()
|
||||
.expect("config directory")
|
||||
.to_path_buf();
|
||||
|
||||
// Ensure the config directory exists and write a default config file
|
||||
// if none is present. Runs on every Config::new(), regardless of which
|
||||
// entry path (GUI main, spawned daemon, CLI, test commands) we're on,
|
||||
// so a fresh Mac never hits "No such file or directory" on config.toml
|
||||
// and notify::Watcher (which requires the dir to exist on macOS
|
||||
// FSEvents and some Linux backends) has a concrete path to watch.
|
||||
fs::create_dir_all(&config_dir)?;
|
||||
if !config_path.exists() {
|
||||
let default_toml = toml::to_string_pretty(&ConfigToml::default())
|
||||
.expect("default ConfigToml serialization cannot fail");
|
||||
fs::write(&config_path, default_toml)?;
|
||||
}
|
||||
|
||||
let config_toml = match ConfigToml::new(&config_path) {
|
||||
Err(e) => {
|
||||
@@ -358,15 +375,6 @@ impl Config {
|
||||
},
|
||||
notify::Config::default(),
|
||||
)?;
|
||||
let config_dir = config_path
|
||||
.parent()
|
||||
.expect("config directory")
|
||||
.to_path_buf();
|
||||
// notify::Watcher requires the directory to exist on macOS (FSEvents)
|
||||
// and some Linux backends. Create it eagerly so a first launch on a
|
||||
// fresh machine — where ~/.config/lan-mouse/ has never been touched —
|
||||
// doesn't surface as a notify::Error out of Config::new().
|
||||
fs::create_dir_all(&config_dir)?;
|
||||
let mut config = Config {
|
||||
args,
|
||||
cert_path,
|
||||
|
||||
Reference in New Issue
Block a user