Merge pull request #1111 from fredizzimo/fix_settings

Fix for non-existing data directory
macos-click-through
LoipesMas 3 years ago committed by GitHub
commit 53ee286e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

19
Cargo.lock generated

@ -570,6 +570,15 @@ dependencies = [
"dirs-sys", "dirs-sys",
] ]
[[package]]
name = "dirs"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309"
dependencies = [
"dirs-sys",
]
[[package]] [[package]]
name = "dirs-sys" name = "dirs-sys"
version = "0.3.6" version = "0.3.6"
@ -1325,7 +1334,7 @@ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
"clap", "clap",
"derive-new", "derive-new",
"dirs", "dirs 2.0.2",
"euclid", "euclid",
"flexi_logger", "flexi_logger",
"futures 0.3.17", "futures 0.3.17",
@ -1353,6 +1362,7 @@ dependencies = [
"winapi", "winapi",
"winit 0.24.0 (git+https://github.com/neovide/winit?branch=new-keyboard-all)", "winit 0.24.0 (git+https://github.com/neovide/winit?branch=new-keyboard-all)",
"winres", "winres",
"xdg",
] ]
[[package]] [[package]]
@ -2673,9 +2683,12 @@ dependencies = [
[[package]] [[package]]
name = "xdg" name = "xdg"
version = "2.2.0" version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" checksum = "3a23fe958c70412687039c86f578938b4a0bb50ec788e96bce4d6ab00ddd5803"
dependencies = [
"dirs 3.0.2",
]
[[package]] [[package]]
name = "xkbcommon-dl" name = "xkbcommon-dl"

@ -44,6 +44,7 @@ winit = { git = "https://github.com/neovide/winit", branch = "new-keyboard-all"
gl = "0.14.0" gl = "0.14.0"
swash = "0.1.4" swash = "0.1.4"
clap="2.33.3" clap="2.33.3"
xdg="2.4.0"
[dev-dependencies] [dev-dependencies]
mockall = "0.7.0" mockall = "0.7.0"

@ -2,20 +2,32 @@ use crate::settings::SETTINGS;
use crate::utils::Dimensions; use crate::utils::Dimensions;
use crate::window::WindowSettings; use crate::window::WindowSettings;
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(unix)] #[cfg(unix)]
const SETTINGS_PATH: &str = ".local/share/nvim/neovide-settings.json"; use xdg;
#[cfg(windows)]
const SETTINGS_PATH: &str = "AppData/Local/nvim-data/neovide-settings.json"; const SETTINGS_FILE: &str = "neovide-settings.json";
pub const DEFAULT_WINDOW_GEOMETRY: Dimensions = Dimensions { pub const DEFAULT_WINDOW_GEOMETRY: Dimensions = Dimensions {
width: 100, width: 100,
height: 50, height: 50,
}; };
#[cfg(windows)]
fn neovim_std_datapath() -> PathBuf { fn neovim_std_datapath() -> PathBuf {
let mut settings_path = dirs::home_dir().unwrap(); let mut data_path = dirs::home_dir().unwrap();
settings_path.push(SETTINGS_PATH); data_path.push("AppData/local/nvim-data");
data_path
}
#[cfg(unix)]
fn neovim_std_datapath() -> PathBuf {
let xdg_dirs = xdg::BaseDirectories::with_prefix("nvim").unwrap();
xdg_dirs.get_data_home()
}
fn settings_path() -> PathBuf {
let mut settings_path = neovim_std_datapath();
settings_path.push(SETTINGS_FILE);
settings_path settings_path
} }
@ -42,7 +54,8 @@ pub fn maybe_save_window_size(grid_size: Option<Dimensions>) {
DEFAULT_WINDOW_GEOMETRY DEFAULT_WINDOW_GEOMETRY
}; };
let settings_path = neovim_std_datapath(); let settings_path = settings_path();
std::fs::create_dir_all(neovim_std_datapath()).unwrap();
let json = serde_json::to_string(&saved_window_size).unwrap(); let json = serde_json::to_string(&saved_window_size).unwrap();
log::debug!("Saved Window Size: {}", json); log::debug!("Saved Window Size: {}", json);
std::fs::write(settings_path, json).unwrap(); std::fs::write(settings_path, json).unwrap();

Loading…
Cancel
Save