Skip to content

Commit

Permalink
Add simple notification for new wallpapers
Browse files Browse the repository at this point in the history
  • Loading branch information
ifl0w committed Oct 9, 2023
1 parent f297005 commit 612f7a8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Main = imports.ui.main;

import {HistoryEntry} from './history.js';

/**
* A convenience class for presenting notifications to the user.
*/
class Notification {
/**
* Show a notification for the newly set wallpapers.
*
* @param {HistoryEntry[]} historyEntries The history elements representing the new wallpapers
*/
static newWallpaper(historyEntries: HistoryEntry[]): void {
const infoString = `Source: ${historyEntries.map(h => `${h.source.source}`).join(', ')}`;
const message = `A new wallpaper was set!\n${infoString}`;
Main.notify('New Wallpaper', message);
}
}

export {Notification};

4 changes: 4 additions & 0 deletions src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class RandomWallpaperSettings {
this._builder.get_object('hide_panel_icon'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('show-notifications',
this._builder.get_object('show_notifications'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('fetch-on-startup',
this._builder.get_object('fetch_on_startup'),
'active',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
<description>Removes the panel icon from the gnome shell.</description>
</key>

<key type='b' name='show-notifications'>
<default>false</default>
<summary>Show notifications</summary>
<description>Whether system notifications should be displayed for additional information.</description>
</key>

<key type='as' name='sources'>
<default>[]</default>
<summary>Configured Wallpaper Sources</summary>
Expand Down
9 changes: 9 additions & 0 deletions src/ui/pageGeneral.blp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Adw.PreferencesPage page_general {
}
}

Adw.ActionRow {
title: _("Show notifications");
subtitle: _("System notifications will be displayed to provide information, such as when a new wallpaper is set.");

Switch show_notifications {
valign: center;
}
}

Adw.ActionRow {
title: _("Disable hover preview");
subtitle: _("Disable the desktop preview of the background while hovering the history items. Try enabling if you encounter crashes or lags of the gnome-shell while using the extension.");
Expand Down
4 changes: 4 additions & 0 deletions src/wallpaperController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Utils from './utils.js';
import {AFTimer as Timer} from './timer.js';
import {Logger} from './logger.js';
import {Mode} from './manager/wallpaperManager.js';
import {Notification} from './notifications.js';

// SourceAdapter
import {BaseAdapter} from './adapter/baseAdapter.js';
Expand Down Expand Up @@ -560,6 +561,9 @@ class WallpaperController {
this._historyController.insert(newImageEntries.reverse());

this._runPostCommands();

if (this._settings.getBoolean('show-notifications'))
Notification.newWallpaper(newImageEntries.reverse());
} catch (error) {
Logger.error(error, this);
} finally {
Expand Down

0 comments on commit 612f7a8

Please sign in to comment.