From 47a2e58d45705b2b0c076a03e0999ffbacf482d1 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 19 Mar 2019 12:16:00 +0000 Subject: [PATCH] Introduce updates indicator https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/466 --- js/js-resources.gresource.xml | 1 + js/ui/panel.js | 9 ++ js/ui/status/automaticUpdates.js | 144 +++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 js/ui/status/automaticUpdates.js diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index a969b6292..a1bbbe18d 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -121,6 +121,7 @@ ui/components/keyring.js ui/status/accessibility.js + ui/status/automaticUpdates.js ui/status/brightness.js ui/status/location.js ui/status/keyboard.js diff --git a/js/ui/panel.js b/js/ui/panel.js index 1d9621ae3..ab5bffbb7 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -774,10 +774,17 @@ class AggregateMenu extends PanelMenu.Button { this._nightLight = new imports.ui.status.nightLight.Indicator(); this._thunderbolt = new imports.ui.status.thunderbolt.Indicator(); + if (Main.sessionMode.components.includes('updates')) + this._automaticUpdates = new imports.ui.status.automaticUpdates.Indicator(); + else + this._automaticUpdates = null; + this._indicators.add_child(this._thunderbolt.indicators); this._indicators.add_child(this._screencast.indicators); this._indicators.add_child(this._location.indicators); this._indicators.add_child(this._nightLight.indicators); + if (this._automaticUpdates) + this._indicators.add_child(this._automaticUpdates.indicators); if (this._network) { this._indicators.add_child(this._network.indicators); } @@ -796,6 +803,8 @@ class AggregateMenu extends PanelMenu.Button { if (this._network) { this.menu.addMenuItem(this._network.menu); } + if (this._automaticUpdates) + this.menu.addMenuItem(this._automaticUpdates.menu); if (this._bluetooth) { this.menu.addMenuItem(this._bluetooth.menu); } diff --git a/js/ui/status/automaticUpdates.js b/js/ui/status/automaticUpdates.js new file mode 100644 index 000000000..a438a3192 --- /dev/null +++ b/js/ui/status/automaticUpdates.js @@ -0,0 +1,144 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +// +// Copyright (C) 2018 Endless Mobile, Inc. +// +// This is a GNOME Shell component to wrap the interactions over +// D-Bus with the Mogwai system daemon. +// +// Licensed under the GNU General Public License Version 2 +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +const { Gio, GLib, Shell, St } = imports.gi; + +const UpdateManager = imports.misc.updateManager; + +const Main = imports.ui.main; +const MessageTray = imports.ui.messageTray; +const PanelMenu = imports.ui.panelMenu; +const PopupMenu = imports.ui.popupMenu; + +const NM_SETTING_AUTOMATIC_UPDATES_NOTIFICATION_TIME = "connection.automatic-updates-notification-time"; +const NM_SETTING_ALLOW_DOWNLOADS = 'connection.allow-downloads'; +const NM_SETTING_TARIFF_ENABLED = "connection.tariff-enabled"; + +const SchedulerInterface = '\ + \ + \ + \ + \ + \ +'; + +const SchedulerProxy = Gio.DBusProxy.makeProxyWrapper(SchedulerInterface); + +var Indicator = class extends PanelMenu.SystemIndicator { + constructor() { + super(); + + this._indicator = this._addIndicator(); + this._indicator.visible = false; + + this._item = new PopupMenu.PopupSubMenuMenuItem("", true); + this._toggleItem = this._item.menu.addAction("", this._toggleAutomaticUpdates.bind(this)); + this._item.menu.addAction(_("Updates Queue"), () => { + let params = new GLib.Variant('(sava{sv})', [ 'set-mode', [ new GLib.Variant('s', 'updates') ], {} ]); + Gio.DBus.session.call('org.gnome.Software', + '/org/gnome/Software', + 'org.gtk.Actions', + 'Activate', + params, + null, + Gio.DBusCallFlags.NONE, + 5000, + null, + (conn, result) => { + try { + conn.call_finish(result); + } catch (e) { + logError(e, 'Failed to start gnome-software'); + } + }); + + }); + this._item.menu.addSettingsAction(_("Set a Schedule"), 'gnome-updates-panel.desktop'); + this.menu.addMenuItem(this._item); + + this._manager = UpdateManager.getUpdateManager(); + this._manager.connect('notify::state', this._updateState.bind(this)); + + this._updateState(); + } + + _updateState() { + this._updateStatus(); + } + + _sessionUpdated() { + let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter; + this.menu.setSensitive(sensitive); + } + + _updateStatus() { + // Toggle item name + this._updateItem(); + + // Icons + let icon = this._getIcon() + + this._item.icon.gicon = icon; + this._indicator.gicon = icon; + + // Only show the Automatic Updates icon at the bottom bar when it is + // both enabled, and there are updates being downloaded or installed. + this._updateVisibility(); + + // The status label + this._item.label.text = _("Automatic Updates"); + } + + _updateItem() { + let state = this._manager.state; + + if (state == UpdateManager.State.DISABLED) + this._toggleItem.label.text = _("Turn On"); + else + this._toggleItem.label.text = _("Turn Off"); + } + + _toggleAutomaticUpdates() { + this._manager.toggleAutomaticUpdates(); + } + + _getIcon() { + let state = this._manager.state; + let iconName = UpdateManager.stateToIconName(state); + + if (!iconName) + return null; + + let iconFile = Gio.File.new_for_uri(iconName); + let gicon = new Gio.FileIcon({ file: iconFile }); + + return gicon; + } + + _updateVisibility() { + let state = this._manager.state; + + this._item.actor.visible = (state != UpdateManager.State.DISCONNECTED); + this._indicator.visible = (state == UpdateManager.State.DOWNLOADING); + } +};