+
Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

feat/settings-menu #48

Merged
merged 14 commits into from
Aug 26, 2020
Merged
71 changes: 70 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ajour"
description = "A World of Warcraft addon manager"
version = "0.1.0-beta5"
version = "0.2.1"
authors = ["Casper Rogild Storm"]
license = "MIT"
homepage = "https://github.com/casperstorm/ajour"
Expand All @@ -22,6 +22,7 @@ isahc = { version = "0.9.6", features = ["json"] }
zip = "0.5.6"
percent-encoding = "2.1.0"
image = "0.23.8"
native-dialog = "0.4.1"

[build-dependencies]
embed-resource = "1.3.3"
2 changes: 2 additions & 0 deletions src/addon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Addon {
// States for GUI
pub details_btn_state: iced::button::State,
pub update_btn_state: iced::button::State,
pub force_btn_state: iced::button::State,
pub delete_btn_state: iced::button::State,
}

Expand Down Expand Up @@ -65,6 +66,7 @@ impl Addon {
repository_identifiers,
details_btn_state: Default::default(),
update_btn_state: Default::default(),
force_btn_state: Default::default(),
delete_btn_state: Default::default(),
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn create_default_config<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
/// 1. $HOME/.config/ajour/ajour.yml
/// 2. $HOME/.ajour.yml
#[cfg(not(windows))]
fn find_or_create_config() -> Result<PathBuf> {
pub fn find_or_create_config() -> Result<PathBuf> {
let home = env::var("HOME").expect("user home directory not found.");

// Primary location path: $HOME/.config/ajour/ajour.yml.
Expand All @@ -111,7 +111,7 @@ fn find_or_create_config() -> Result<PathBuf> {
/// 1. %APPDATA%\ajour\ajour.yml
/// 2. In the same directory as the executable
#[cfg(windows)]
fn find_or_create_config() -> Result<PathBuf> {
pub fn find_or_create_config() -> Result<PathBuf> {
// Primary location path: %APPDATA%\ajour\ajour.yml.
let pri_location = dirs::config_dir()
.map(|path| path.join("ajour\\ajour.yml"))
Expand Down Expand Up @@ -151,6 +151,22 @@ fn parse_config(path: &PathBuf) -> Result<Config> {
}
}

/// This function will save the current `Config` to disk.
/// This is used if we have updated the `Config` from the application,
/// and want to make sure it persist.
pub fn persist_config(config: &Config) -> Result<()> {
// Find the used config.
let path = find_or_create_config()?;

// Serialize the config
let default_config_content = serde_yaml::to_string(config)?;

// Write to config.
fs::write(&path, &default_config_content)?;

Ok(())
}

/// Returns a Config.
///
/// This functions handles the initialization of a Config.
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载