Skip to content

Commit

Permalink
feat: Split create/update notification to its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy authored and daniellandau committed Apr 2, 2024
1 parent 90fb5ae commit 00e1fd8
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/shell/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,11 @@ const Source = GObject.registerClass({
}

/*
* Override to control notification spawning
* Add notification to source or update existing notification with extra
* GsConnect information
*/
addNotification(notification) {
this._notificationPending = true;

_createNotification(notification) {
const [idMatch, deviceId, requestReplyId, remoteId, localId] = this._parseNotificationId(notification.id);

// Fix themed icons
if (notification.icon) {
let gicon = notification.icon;

if (gicon instanceof Gio.ThemedIcon) {
gicon = getIcon(gicon.names[0]);
notification.icon = gicon.serialize();
}
}

let cachedNotification = this._notifications[localId];

// Check if this is a repeat
Expand All @@ -258,10 +246,8 @@ const Source = GObject.registerClass({
: null;

if (cachedNotification.title === title &&
cachedNotification.bannerBodyText === body) {
this._notificationPending = false;
cachedNotification.bannerBodyText === body)
return;
}

cachedNotification.title = title;
cachedNotification.bannerBodyText = body;
Expand Down Expand Up @@ -289,8 +275,27 @@ const Source = GObject.registerClass({
});
this._notifications[localId] = cachedNotification;
}
return cachedNotification;
}

/*
* Override to control notification spawning
*/
addNotification(notification) {
this._notificationPending = true;

// Fix themed icons
if (notification.icon) {
let gicon = notification.icon;

if (gicon instanceof Gio.ThemedIcon) {
gicon = getIcon(gicon.names[0]);
notification.icon = gicon.serialize();
}
}

this._addNotificationToMessageTray(cachedNotification);
const createdNotification = this._createNotification(notification);
this._addNotificationToMessageTray(createdNotification);

this._notificationPending = false;
}
Expand Down Expand Up @@ -341,6 +346,7 @@ export function patchGSConnectNotificationSource() {
// Patch in the subclassed methods
source._closeGSConnectNotification = Source.prototype._closeGSConnectNotification;
source._parseNotificationId = Source.prototype._parseNotificationId;
source._createNotification = Source.prototype._createNotification;
source.addNotification = Source.prototype.addNotification;
source._addNotificationToMessageTray = Source.prototype._addNotificationToMessageTray;
source.createBanner = Source.prototype.createBanner;
Expand Down Expand Up @@ -370,6 +376,7 @@ const _ensureAppSource = function (appId) {
if (source._appId === APP_ID) {
source._closeGSConnectNotification = Source.prototype._closeGSConnectNotification;
source._parseNotificationId = Source.prototype._parseNotificationId;
source._createNotification = Source.prototype._createNotification;
source.addNotification = Source.prototype.addNotification;
source._addNotificationToMessageTray = Source.prototype._addNotificationToMessageTray;
source.createBanner = Source.prototype.createBanner;
Expand Down

0 comments on commit 00e1fd8

Please sign in to comment.