Skip to content

Commit

Permalink
Fix notification management
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelRochet committed Mar 11, 2024
1 parent 56858bc commit ea2de9e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
33 changes: 17 additions & 16 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ let BOOT_WAIT = 15; // 15s
let CHECK_INTERVAL = 60*60; // 1h
let NOTIFY = false;
let HOWMUCH = 0;
let TRANSIENT = true;
let UPDATE_CMD = "gnome-terminal -- /bin/sh -c \"sudo pacman -Syu ; echo Done - Press enter to exit; read _\" ";
let CHECK_CMD = "/usr/bin/checkupdates";
let MANAGER_CMD = "";
Expand Down Expand Up @@ -225,7 +224,6 @@ class ArchUpdateIndicator extends Button {
CHECK_INTERVAL = 60 * this._settings.get_int('check-interval');
NOTIFY = this._settings.get_boolean('notify');
HOWMUCH = this._settings.get_int('howmuch');
TRANSIENT = this._settings.get_boolean('transient');
UPDATE_CMD = this._settings.get_string('update-cmd');
CHECK_CMD = this._settings.get_string('check-cmd');
DISABLE_PARSING = this._settings.get_boolean('disable-parsing');
Expand Down Expand Up @@ -574,29 +572,32 @@ class ArchUpdateIndicator extends Button {
}

_showNotification(title, message) {
// Destroy previous notification if still there
if (this._notification) {
this._notification.destroy(MessageTray.NotificationDestroyedReason.REPLACED);
}
// Prepare a notification Source with our name and icon
// It looks like notification Sources are destroyed when empty so we check every time
if (this._notifSource == null) {
// We have to prepare this only once
this._notifSource = new MessageTray.Source({
title: this._extension.metadata.name.toString(),
icon: this._getCustIcon("arch-lit-symbolic"),
});
// Take care of note leaving unneeded sources
// Take care of not leaving unneeded sources
this._notifSource.connect('destroy', ()=>{this._notifSource = null;});
Main.messageTray.add(this._notifSource);
}
let notification = null;
// We do not want to have multiple notifications stacked
// instead we will update previous
if (this._notifSource.notifications.length == 0) {
notification = new MessageTray.Notification(this._notifSource, title, message);
notification.gicon = this._getCustIcon("arch-updates-symbolic");
notification.addAction( _('Update now') , ()=>{this._updateNow();} );
} else {
notification = this._notifSource.notifications[0];
notification.update( title, message, { clear: true });
}
notification.setTransient(TRANSIENT);
this._notifSource.showNotification(notification);
// Creates a new notification
this._notification = new MessageTray.Notification({
source: this._notifSource,
title: title,
body: message
});
this._notification.gicon = this._getCustIcon("arch-updates-symbolic");
this._notification.addAction( _('Update now') , ()=>{this._updateNow();} );
this._notification.connect('destroy', ()=>{this._notification = null;});
this._notifSource.addNotification(this._notification);
}

});
Expand Down
1 change: 0 additions & 1 deletion prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default class ArchUpdatePreferences extends ExtensionPreferences {
settings.bind('show-count' , buildable.get_object('field_count') , 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('notify' , buildable.get_object('field_notify') , 'active' , Gio.SettingsBindFlags.DEFAULT);
settings.bind('howmuch', buildable.get_object('field_howmuch'), 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('transient', buildable.get_object('field_transient'), 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('strip-versions' , buildable.get_object('field_stripversions') , 'active' , Gio.SettingsBindFlags.DEFAULT);
settings.bind('strip-versions-in-notification' , buildable.get_object('field_stripversionsnotifications') , 'active' , Gio.SettingsBindFlags.DEFAULT);
settings.bind('check-cmd' , buildable.get_object('field_checkcmd') , 'text' , Gio.SettingsBindFlags.DEFAULT);
Expand Down
12 changes: 0 additions & 12 deletions prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,6 @@
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property translatable="yes" name="title">Use transient notifications (auto dismiss)</property>
<property name="activatable-widget">field_transient</property>
<child>
<object class="GtkSwitch" id="field_transient">
<property name="valign">3</property>
<property name="active">true</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property translatable="yes" name="title">How much information to show on notifications</property>
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
6 changes: 0 additions & 6 deletions schemas/org.gnome.shell.extensions.arch-update.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
<description>0:count, 1:list</description>
</key>

<key name="transient" type="b">
<default>true</default>
<summary>Use transient notifications (auto dismiss)</summary>
<description></description>
</key>

<key name="check-cmd" type="s">
<default>"/usr/bin/checkupdates"</default>
<summary>Command to run to check for updated packages.</summary>
Expand Down

0 comments on commit ea2de9e

Please sign in to comment.