diff --git a/src/notifications.ts b/src/notifications.ts index c5f2045..82a4f25 100644 --- a/src/notifications.ts +++ b/src/notifications.ts @@ -16,6 +16,20 @@ class Notification { const message = `A new wallpaper was set!\n${infoString}`; notify('New Wallpaper', message); } + + /** + * Show an error notification for failed wallpaper downloads. + * + * @param {unknown} error The error that was thrown when fetching a new wallpaper + */ + static fetchWallpaperFailed(error: unknown): void { + let errorMessage = String(error); + + if (error instanceof Error) + errorMessage = error.message; + + notify('RandomWallpaperGnome3: Wallpaper Download Failed!', errorMessage); + } } export {Notification}; diff --git a/src/wallpaperController.ts b/src/wallpaperController.ts index 27cbdcf..2913701 100644 --- a/src/wallpaperController.ts +++ b/src/wallpaperController.ts @@ -562,6 +562,8 @@ class WallpaperController { Notification.newWallpaper(newImageEntries.reverse()); } catch (error) { Logger.error(error, this); + if (this._settings.getBoolean('show-notifications')) + Notification.fetchWallpaperFailed(error); } finally { this._stopLoadingHooks.forEach(element => element()); }