Skip to content

Commit 566bcec

Browse files
authored
[Fix] cannot parse correct home dir on windows (#108)
1 parent 5da3092 commit 566bcec

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Cargo.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ url = "2.5.4"
3434
hyperpolyglot_fork = { version = "0.1.7", optional = true }
3535
theme-converter = "0.1.2"
3636
plist = "1.8.0"
37+
home = "0.5.11"
3738

3839
[features]
3940
default = []

core/src/themes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub async fn parse_remote_code_theme(path: &str, code_theme: &str) -> anyhow::Re
5252
}
5353

5454
pub async fn parse_code_theme(code_theme: &str) -> anyhow::Result<String> {
55-
let remote_theme_folder_path = get_config_home_path()?.join("remote_themes");
55+
let remote_theme_folder_path = get_config_home_path().join("remote_themes");
5656

5757
if !remote_theme_folder_path.exists() {
5858
fs::create_dir_all(&remote_theme_folder_path)?;

core/src/utils/path.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ fn create_temp_file_name() -> String {
1818
format!("CodeSnap_{}", formatted_time)
1919
}
2020

21-
pub fn parse_home_variable(path: &str) -> Result<String, VarError> {
22-
if cfg!(windows) {
23-
return Ok(path.to_string());
24-
}
25-
26-
let home_path = var("HOME")?;
21+
pub fn parse_home_variable(path: &str) -> String {
22+
let home_path = home::home_dir().unwrap().to_string_lossy().to_string();
2723
let regex = Regex::new(r"(~|$HOME)").unwrap();
2824
let path = regex.replace_all(path, home_path);
2925

30-
Ok(path.to_string())
26+
path.to_string()
3127
}
3228

3329
pub fn parse_file_name(path: &str) -> Result<String, VarError> {
34-
let path_str = parse_home_variable(path)?;
30+
let path_str = parse_home_variable(path);
3531
let path = Path::new(&path_str);
3632
let parsed_path = if path.is_dir() {
3733
path.join(create_temp_file_name())
@@ -45,13 +41,13 @@ pub fn parse_file_name(path: &str) -> Result<String, VarError> {
4541
Ok(parsed_path)
4642
}
4743

48-
pub fn get_config_home_path() -> Result<PathBuf, VarError> {
49-
let home = parse_home_variable("~")?;
44+
pub fn get_config_home_path() -> PathBuf {
45+
let home = parse_home_variable("~");
5046
let config_home_path = Path::new(&home).join(".config").join("codesnap");
5147

5248
if !config_home_path.exists() {
5349
std::fs::create_dir_all(&config_home_path).unwrap();
5450
}
5551

56-
Ok(config_home_path)
52+
config_home_path
5753
}

0 commit comments

Comments
 (0)