Skip to content

Commit

Permalink
Enable notification badges
Browse files Browse the repository at this point in the history
Closes #1695
  • Loading branch information
ibauersachs authored Dec 1, 2022
1 parent 4a6f3b3 commit 434cc70
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Pango = imports.gi.Pango;
const St = imports.gi.St;
const Signals = imports.signals;
const Utils = Me.imports.utils;
const Main = imports.ui.main;


var ProgressManager = class {
Expand Down Expand Up @@ -285,6 +286,7 @@ var ProgressIndicator = class {
constructor(source, progressManager) {
this._source = source;
this._progressManager = progressManager;
this._messageTray = Main.messageTray;
this._signalsHandler = new Utils.GlobalSignalsHandler();

this._sourceDestroyId = this._source.connect('destroy', () => {
Expand Down Expand Up @@ -317,6 +319,18 @@ var ProgressIndicator = class {
this._progressManager,
'progress-entry-removed',
this._onEntryRemoved.bind(this)
], [
this._messageTray,
'source-added',
this._updateBadge.bind(this)
], [
this._messageTray,
'source-removed',
this._updateBadge.bind(this)
], [
this._messageTray,
'queue-changed',
this._updateBadge.bind(this)
]);
}

Expand Down Expand Up @@ -368,6 +382,27 @@ var ProgressIndicator = class {
}
}

_updateBadge() {
// FIXME - Probably not the best way to get the show counter badge setting
// It is already present in AppProgress class, not sure how to get it here
const showBadge = Me.settings.get_boolean('progress-show-count');
if (showBadge) {
let items = this._messageTray.getSources();
let unreadCount = 0;
for (let i = 0; i < items.length; i++) {
let item = items[i];
// FIXME - Check if these 12 symbols are enough
if (this._source.app.get_name().includes(item.title.substring(0, 12))) {
unreadCount += item.notifications.length;
}
}
if (unreadCount != this._notificationBadgeCount) {
this.setNotificationBadge(unreadCount);
this.toggleNotificationBadge(showBadge);
}
}
}

setNotificationBadge(count) {
this._notificationBadgeCount = count;
let text = this._notificationBadgeCountToText(count);
Expand Down

0 comments on commit 434cc70

Please sign in to comment.