From ed84541050f3c5fbed18935519abaeb267a23cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 26 Jan 2020 23:47:24 +0100 Subject: [PATCH] extensionSystem: Show notification when updates are available Now that the extensions app has the ability to handle updates, we can use it as source of updates notifications. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1968 --- js/ui/extensionSystem.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 432859733..e520186d9 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -1,12 +1,13 @@ // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- /* exported init connect disconnect */ -const { GLib, Gio, St } = imports.gi; +const { GLib, Gio, GObject, Shell, St } = imports.gi; const Signals = imports.signals; const ExtensionUtils = imports.misc.extensionUtils; const FileUtils = imports.misc.fileUtils; const Main = imports.ui.main; +const MessageTray = imports.ui.messageTray; const { ExtensionState, ExtensionType } = ExtensionUtils; @@ -19,6 +20,7 @@ var ExtensionManager = class { constructor() { this._initialized = false; this._enabled = false; + this._updateNotified = false; this._extensions = new Map(); this._enabledExtensions = []; @@ -206,6 +208,18 @@ var ExtensionManager = class { extension.hasUpdate = true; this.emit('extension-state-changed', extension); + + if (!this._updateNotified) { + this._updateNotified = true; + + let source = new ExtensionUpdateSource(); + Main.messageTray.add(source); + + let notification = new MessageTray.Notification(source, + _('Extension Updates Available'), + _('Extension updates are ready to be installed.')); + source.showNotification(notification); + } } logExtensionError(uuid, error) { @@ -557,3 +571,27 @@ var ExtensionManager = class { } }; Signals.addSignalMethods(ExtensionManager.prototype); + +const ExtensionUpdateSource = GObject.registerClass( +class ExtensionUpdateSource extends MessageTray.Source { + _init() { + let appSys = Shell.AppSystem.get_default(); + this._app = appSys.lookup_app('org.gnome.Extensions.desktop'); + + super._init(this._app.get_name()); + } + + getIcon() { + return this._app.app_info.get_icon(); + } + + _createPolicy() { + return new MessageTray.NotificationApplicationPolicy(this._app.id); + } + + open() { + this._app.activate(); + Main.overview.hide(); + Main.panel.closeCalendar(); + } +});