Skip to content

Commit

Permalink
Merge pull request #415 from chewing/rust/path
Browse files Browse the repository at this point in the history
refactor(path): switch to directories-rs
  • Loading branch information
kanru authored Dec 31, 2023
2 parents a313e41 + 70d9374 commit e8ad8de
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 26 deletions.
114 changes: 93 additions & 21 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include = ["src/**/*.rs", "Cargo.toml", "AUTHORS", "COPYING", "NEWS"]

[dependencies]
bytemuck = { version = "1.13.1", features = ["derive"] }
dirs-next = "2.0.0"
directories = "5.0.0"
indexmap = "2.0.0"
riff = "2.0.0"
rusqlite = "0.30.0"
Expand Down
17 changes: 13 additions & 4 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
path::{Path, PathBuf},
};

use dirs_next::{data_dir as user_data_dir, home_dir};
use directories::{BaseDirs, ProjectDirs};

const UNIX_SYS_PATH: &str = "/usr/share/libchewing";

Expand Down Expand Up @@ -78,17 +78,26 @@ pub fn data_dir() -> Option<PathBuf> {
return Some(path);
}
}
user_data_dir().map(|path| path.join("chewing"))
ProjectDirs::from("im", "chewing", "chewing")
.as_ref()
.map(ProjectDirs::data_dir)
.map(Path::to_owned)
}

fn legacy_data_dir() -> Option<PathBuf> {
#[cfg(target_os = "windows")]
return home_dir().map(|path| path.join("ChewingTextService"));
return BaseDirs::new()
.as_ref()
.map(BaseDirs::home_dir)
.map(|path| path.join("ChewingTextService"));

#[cfg(any(target_os = "macos", target_os = "ios"))]
return Some("/Library/ChewingOSX".into());

home_dir().map(|path| path.join(".chewing"))
BaseDirs::new()
.as_ref()
.map(BaseDirs::home_dir)
.map(|path| path.join(".chewing"))
}

/// Returns the path to the user's default userphrase database file.
Expand Down

0 comments on commit e8ad8de

Please sign in to comment.