Skip to content

Commit de5adc3

Browse files
committed
fix: wint start up in some fedora distors coz no document folder in some
1 parent bf2d1ac commit de5adc3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/index.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,35 @@
185185
const appNamePromise = window.__TAURI__.app.getName();
186186
// for running tests, the user document dir is set to app data dir as we dont want to
187187
// corrupt user documents dir for tests
188-
let documentDirPromise;
188+
let documentDirPromise, homeDirPromise;
189189
if(_isTestWindow()){
190190
documentDirPromise = window.__TAURI__.path.appLocalDataDir(); // appdata/testDocuments will be appended below
191191
} else {
192192
documentDirPromise = window.__TAURI__.path.documentDir();
193+
homeDirPromise = window.__TAURI__.path.homeDir();
193194
}
194195

195196
const appLocalDirPromise = window.__TAURI__.path.appLocalDataDir();
196197
const tempDirPromise = window.__TAURI__.os.tempdir();
197198
window._tauriBootVars = {};
198199
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])
201202
.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+
}
203216

204-
window._tauriBootVars.documentDir = results[1];
205217
// For tests, documents dir is localAppDataDir/testDocuments to keep user documents garbage free for tests
206218
// Also In github actions, the tauri get doc dir call gets stuck indefinitely
207219
if(_isTestWindow()){
@@ -212,8 +224,8 @@
212224
}
213225
//Documents dir special case for tests
214226

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;
217229
window._tauriBootVars.bootstrapTime = Date.now() - tauriBootStartTime;
218230
localStorage.setItem(TAURI_BOOT_VARS_LOCALSTORAGE_KEY, JSON.stringify(window._tauriBootVars));
219231
});

0 commit comments

Comments
 (0)