File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ extern crate chrono;
1717extern crate dirs;
1818
1919use std:: collections:: HashSet ;
20+ use std:: env;
2021use std:: fmt;
2122use std:: fmt:: Write as _; // import without risk of name clashing
2223use std:: fs:: { self , File } ;
@@ -74,8 +75,18 @@ impl Timelog {
7475 }
7576
7677 pub fn get_default_file ( ) -> PathBuf {
77- let mut log_path = dirs:: home_dir ( ) . expect ( "Cannot determine home directory" ) ;
78- log_path. push ( ".gtimelog" ) ;
78+ let mut legacy_dir = dirs:: home_dir ( ) . unwrap ( ) ;
79+ legacy_dir. push ( ".gtimelog" ) ;
80+ let mut log_path = if legacy_dir. is_dir ( ) {
81+ legacy_dir
82+ } else {
83+ let mut data_dir = match env:: var_os ( "XDG_DATA_HOME" ) {
84+ Some ( val) => PathBuf :: from ( val. into_string ( ) . unwrap ( ) ) ,
85+ None => dirs:: data_dir ( ) . unwrap ( ) ,
86+ } ;
87+ data_dir. push ( "gtimelog" ) ;
88+ data_dir
89+ } ;
7990 log_path. push ( "timelog.txt" ) ;
8091 log_path
8192 }
You can’t perform that action at this time.
0 commit comments