fix: no console window and a writable config dir on Windows
This commit is contained in:
parent
4360e45233
commit
6bb850b9af
1 changed files with 22 additions and 3 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -3,6 +3,10 @@
|
||||||
//! master, 0600), `carrier.db` (fumi-core's sealed store) and `read.txt`
|
//! master, 0600), `carrier.db` (fumi-core's sealed store) and `read.txt`
|
||||||
//! (read marks, carrier's own sidecar).
|
//! (read marks, carrier's own sidecar).
|
||||||
|
|
||||||
|
// No console window when the Windows release build is double-clicked.
|
||||||
|
// Debug builds keep it for eprintln output.
|
||||||
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
mod demo;
|
mod demo;
|
||||||
|
|
@ -26,9 +30,7 @@ fn main() {
|
||||||
fn config_dir() -> PathBuf {
|
fn config_dir() -> PathBuf {
|
||||||
let base = match std::env::var("XDG_CONFIG_HOME") {
|
let base = match std::env::var("XDG_CONFIG_HOME") {
|
||||||
Ok(xdg) if !xdg.is_empty() => PathBuf::from(xdg).join("carrier"),
|
Ok(xdg) if !xdg.is_empty() => PathBuf::from(xdg).join("carrier"),
|
||||||
_ => PathBuf::from(std::env::var("HOME").unwrap_or_default())
|
_ => default_config_root(),
|
||||||
.join(".config")
|
|
||||||
.join("carrier"),
|
|
||||||
};
|
};
|
||||||
// Dev builds get their own profile, seeded with sample data in
|
// Dev builds get their own profile, seeded with sample data in
|
||||||
// `demo.rs`, so layout work never touches the real account.
|
// `demo.rs`, so layout work never touches the real account.
|
||||||
|
|
@ -36,3 +38,20 @@ fn config_dir() -> PathBuf {
|
||||||
let base = base.with_file_name("carrier-demo");
|
let base = base.with_file_name("carrier-demo");
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HOME is rarely set on Windows, and when it is missing the Unix
|
||||||
|
// fallback would resolve .config\carrier against the working
|
||||||
|
// directory - for an installed copy that's Program Files, which isn't
|
||||||
|
// writable, so the app would die on startup. Roaming AppData is the
|
||||||
|
// per-user config location there.
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn default_config_root() -> PathBuf {
|
||||||
|
PathBuf::from(std::env::var("APPDATA").unwrap_or_default()).join("carrier")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn default_config_root() -> PathBuf {
|
||||||
|
PathBuf::from(std::env::var("HOME").unwrap_or_default())
|
||||||
|
.join(".config")
|
||||||
|
.join("carrier")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue