summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2019-03-19 12:16:00 +0000
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2019-03-19 12:18:54 +0000
commit47a2e58d45705b2b0c076a03e0999ffbacf482d1 (patch)
tree0577469276c1da88df6a413532a96a4e3e22a7d7
parent20d73be57db0c46368ee5e35cfdbb6b383b84aa8 (diff)
downloadgnome-shell-gbsneto/automatic-updates.tar.gz
Introduce updates indicatorgbsneto/automatic-updates
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/466
-rw-r--r--js/js-resources.gresource.xml1
-rw-r--r--js/ui/panel.js9
-rw-r--r--js/ui/status/automaticUpdates.js144
3 files changed, 154 insertions, 0 deletions
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 @@
<file>ui/components/keyring.js</file>
<file>ui/status/accessibility.js</file>
+ <file>ui/status/automaticUpdates.js</file>
<file>ui/status/brightness.js</file>
<file>ui/status/location.js</file>
<file>ui/status/keyboard.js</file>
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 = '\
+<node> \
+ <interface name="com.endlessm.DownloadManager1.Scheduler"> \
+ <property name="ActiveEntryCount" type="u" access="read" /> \
+ <property name="EntryCount" type="u" access="read" /> \
+ </interface> \
+</node>';
+
+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);
+ }
+};