Skip to content

Commit 9929f35

Browse files
committed
fix: app crashes when favorites path is null
1 parent c193ec7 commit 9929f35

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/Api/favorites.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ class FavoritesAPI {
99
VIDEO_PATH: string;
1010
HOMEDIR_PATH: string;
1111
async build(): Promise<void> {
12-
this.DOCUMENT_PATH = await path.documentDir();
13-
this.DOWNLOAD_PATH = await path.downloadDir();
14-
this.DESKTOP_PATH = await path.desktopDir();
15-
this.PICTURE_PATH = await path.pictureDir();
16-
this.MUSIC_PATH = await path.audioDir();
17-
this.VIDEO_PATH = await path.videoDir();
18-
this.HOMEDIR_PATH = await path.homeDir();
12+
try {
13+
this.DOCUMENT_PATH = await path.documentDir();
14+
this.DOWNLOAD_PATH = await path.downloadDir();
15+
this.DESKTOP_PATH = await path.desktopDir();
16+
this.PICTURE_PATH = await path.pictureDir();
17+
this.MUSIC_PATH = await path.audioDir();
18+
this.VIDEO_PATH = await path.videoDir();
19+
// eslint-disable-next-line no-empty
20+
} catch (_) {}
21+
try {
22+
this.HOMEDIR_PATH = await path.homeDir();
23+
// eslint-disable-next-line no-empty
24+
} catch (_) {}
1925
}
2026
}
2127

src/Components/Favorites/favorites.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Favorites = async (): Promise<string> => {
2727
result += `<h1 class="section-title">${await Translate('Favorites')}</h1>`;
2828
const defaultFavoritesList = (await defaultFavorites()).map((favorite) => favorite.name);
2929
for (const favorite of favorites) {
30+
if (!favorite.path) continue;
3031
if (favorite.path === 'xplorer://Home') continue;
3132
const fileData = new FileAPI(favorite.path);
3233
const exists = await fileData.exists();

src/Components/Layout/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const createSidebar = async (): Promise<void> => {
4545
let favoritesElement = '';
4646
const defaultFavoritesList = (await defaultFavorites()).map((favorite) => favorite.name);
4747
for (const favorite of favorites) {
48+
if (!favorite.path) continue;
4849
const exists = await new FileAPI(favorite.path).exists();
4950
if (!(await isDefaultFavorite(favorite.path)) && !favorite.path.startsWith('xplorer://')) {
5051
if (!exists) continue;

0 commit comments

Comments
 (0)