@@ -29,6 +29,9 @@ struct Opts {
29
29
/// Path to database override
30
30
#[ clap( long) ]
31
31
dbpath : Option < String > ,
32
+ /// Path to webui override
33
+ #[ clap( long) ]
34
+ webpath : Option < String > ,
32
35
/// Device ID override
33
36
#[ clap( long) ]
34
37
device_id : Option < String > ,
@@ -77,7 +80,10 @@ async fn main() -> Result<(), rocket::Error> {
77
80
} ;
78
81
info ! ( "Using DB at path {:?}" , db_path) ;
79
82
80
- let asset_path = get_asset_path ( ) ;
83
+ let asset_path = match opts. webpath {
84
+ Some ( webpath) => PathBuf :: from ( webpath) ,
85
+ None => get_asset_path ( ) ,
86
+ } ;
81
87
info ! ( "Using aw-webui assets at path {:?}" , asset_path) ;
82
88
83
89
let legacy_import = !opts. no_legacy_import ;
@@ -99,6 +105,7 @@ async fn main() -> Result<(), rocket::Error> {
99
105
endpoints:: build_rocket ( server_state, config) . launch ( ) . await
100
106
}
101
107
108
+ use std:: ffi:: OsString ;
102
109
use std:: path:: PathBuf ;
103
110
104
111
// The appdirs implementation of site_data_dir is broken on computers which has flatpak installed
@@ -110,16 +117,27 @@ use std::path::PathBuf;
110
117
// don't want this change?
111
118
fn site_data_dir ( app : Option < & str > , _: Option < & str > ) -> Result < PathBuf , ( ) > {
112
119
// Iterate over all XDG_DATA_DIRS and return first match that exists
113
- if let Some ( joined) = env:: var_os ( "XDG_DATA_DIRS" ) {
114
- for mut data_dir in env:: split_paths ( & joined) {
115
- if let Some ( app) = app {
116
- data_dir. push ( app) ;
120
+ let joined = match env:: var_os ( "XDG_DATA_DIRS" ) {
121
+ // If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
122
+ // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
123
+ Some ( path) => {
124
+ if path. is_empty ( ) {
125
+ OsString :: from ( "/usr/local/share:/usr/share" )
126
+ } else {
127
+ path
117
128
}
118
- if !data_dir. is_dir ( ) {
119
- continue ;
120
- }
121
- return Ok ( data_dir) ;
122
129
}
130
+ None => OsString :: from ( "/usr/local/share:/usr/share" ) ,
131
+ } ;
132
+
133
+ for mut data_dir in env:: split_paths ( & joined) {
134
+ if let Some ( app) = app {
135
+ data_dir. push ( app) ;
136
+ }
137
+ if !data_dir. is_dir ( ) {
138
+ continue ;
139
+ }
140
+ return Ok ( data_dir) ;
123
141
}
124
142
// If no dirs exists in XDG_DATA_DIRS, fallback to /usr/local/share
125
143
let default = "/usr/local/share" ;
@@ -139,8 +157,6 @@ fn site_data_dir(app: Option<&str>, _: Option<&str>) -> Result<PathBuf, ()> {
139
157
fn get_asset_path ( ) -> PathBuf {
140
158
use std:: env:: current_exe;
141
159
142
- // TODO: Add cmdline arg which can override asset path?
143
-
144
160
// Search order for asset path is:
145
161
// 1. ./aw-webui/dist
146
162
// 2. $current_exe_dir/aw_server_rust/static
0 commit comments