|
185 | 185 | const appNamePromise = window.__TAURI__.app.getName(); |
186 | 186 | // for running tests, the user document dir is set to app data dir as we dont want to |
187 | 187 | // corrupt user documents dir for tests |
188 | | - let documentDirPromise; |
| 188 | + let documentDirPromise, homeDirPromise; |
189 | 189 | if(_isTestWindow()){ |
190 | 190 | documentDirPromise = window.__TAURI__.path.appLocalDataDir(); // appdata/testDocuments will be appended below |
191 | 191 | } else { |
192 | 192 | documentDirPromise = window.__TAURI__.path.documentDir(); |
| 193 | + homeDirPromise = window.__TAURI__.path.homeDir(); |
193 | 194 | } |
194 | 195 |
|
195 | 196 | const appLocalDirPromise = window.__TAURI__.path.appLocalDataDir(); |
196 | 197 | const tempDirPromise = window.__TAURI__.os.tempdir(); |
197 | 198 | window._tauriBootVars = {}; |
198 | 199 | const tauriBootStartTime = Date.now(); |
199 | | - window._tauriBootVarsPromise = Promise.all([appNamePromise, documentDirPromise, |
200 | | - appLocalDirPromise, tempDirPromise]) |
| 200 | + window._tauriBootVarsPromise = Promise.allSettled([appNamePromise, documentDirPromise, |
| 201 | + appLocalDirPromise, tempDirPromise, homeDirPromise]) |
201 | 202 | .then((results) => { |
202 | | - window._tauriBootVars.appname = results[0]; |
| 203 | + window._tauriBootVars.appname = results[0].value; |
| 204 | + |
| 205 | + if(results[1].status === "fulfilled"){ |
| 206 | + window._tauriBootVars.documentDir = results[1].value; |
| 207 | + } else if(results[4].status === "fulfilled"){ |
| 208 | + // some linux distros may not have Documents folder. so we use the home folder |
| 209 | + // https://github.com/phcode-dev/phoenix/issues/1729 |
| 210 | + window._tauriBootVars.documentDir = results[4].value; |
| 211 | + } else { |
| 212 | + console.error("unable to determine user documents dir, defaulting to app data dir documentdir:", |
| 213 | + results[1].reason, "home folder error: ", results[4].reason); |
| 214 | + window._tauriBootVars.documentDir = results[2].value; |
| 215 | + } |
203 | 216 |
|
204 | | - window._tauriBootVars.documentDir = results[1]; |
205 | 217 | // For tests, documents dir is localAppDataDir/testDocuments to keep user documents garbage free for tests |
206 | 218 | // Also In github actions, the tauri get doc dir call gets stuck indefinitely |
207 | 219 | if(_isTestWindow()){ |
|
212 | 224 | } |
213 | 225 | //Documents dir special case for tests |
214 | 226 |
|
215 | | - window._tauriBootVars.appLocalDir = results[2]; |
216 | | - window._tauriBootVars.tempDir = results[3]; |
| 227 | + window._tauriBootVars.appLocalDir = results[2].value; |
| 228 | + window._tauriBootVars.tempDir = results[3].value; |
217 | 229 | window._tauriBootVars.bootstrapTime = Date.now() - tauriBootStartTime; |
218 | 230 | localStorage.setItem(TAURI_BOOT_VARS_LOCALSTORAGE_KEY, JSON.stringify(window._tauriBootVars)); |
219 | 231 | }); |
|
0 commit comments