Debian Codegraph @

src/widgets/detailsButton.js

raw
1 /* exported FlatsealDetailsButton */
2
3 /* detailsButton.js
4 *
5 * Copyright 2020 Martin Abente Lahaye
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 const {Gio, GObject, Gtk, GLib} = imports.gi;
22
23 const GSActivateIface = `
24 <node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
25 <interface name='org.gtk.Actions'>
26 <method name='Activate'>
27 <arg type='s' name='action_name'/>
28 <arg type='av' name='parameter'/>
29 <arg type='a{sv}' name='platorm_data'/>
30 </method>
31 </interface>
32 </node>
33 `;
34
35 const DBListNamesIface = `
36 <node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
37 <interface name='org.freedesktop.DBus'>
38 <method name='ListActivatableNames'>
39 <arg type='as' direction='out'/>
40 </method>
41 </interface>
42 </node>
43 `;
44
45
46 var FlatsealDetailsButton = GObject.registerClass({
47 GTypeName: 'FlatsealDetailsButton',
48 }, class FlatsealDetailsButton extends Gtk.Button {
49 _init(permissions) {
50 super._init();
51 this._setup(permissions);
52 }
53
54 _setup(permissions) {
55 this._proxy = null;
56 this._permissions = permissions;
57 this._foundManager = false;
58
59 this.set_use_underline(true);
60 this.set_label(_('_Show Details'));
61
62 this.connect('clicked', this._clicked.bind(this));
63 this._checkSoftwareManager();
64 }
65
66 _checkSoftwareManager() {
67 try {
68 const DBListNamesProxy = Gio.DBusProxy.makeProxyWrapper(DBListNamesIface);
69 const proxy = new DBListNamesProxy(
70 Gio.DBus.session, 'org.freedesktop.DBus', '/org/freedesktop/DBus');
71 proxy.ListActivatableNamesRemote(([services], err) => {
72 this._foundManager = !err && services.indexOf('org.gnome.Software') !== -1;
73 this._update();
74 });
75 } catch (err) {
76 this._foundManager = false;
77 this._update();
78 }
79 }
80
81 _clicked() {
82 try {
83 const GSProxy = Gio.DBusProxy.makeProxyWrapper(GSActivateIface);
84 this._proxy = new GSProxy(
85 Gio.DBus.session,
86 'org.gnome.Software',
87 '/org/gnome/Software',
88 this._launchSoftwareManager.bind(this));
89 } catch (err) {
90 logError(err);
91 }
92 }
93
94 _launchSoftwareManager() {
95 try {
96 const args = GLib.Variant.new('(ss)', [this._permissions.appId, '']);
97 this._proxy.ActivateRemote('details', [args], null);
98 } catch (err) {
99 logError(err);
100 }
101 }
102
103 _update() {
104 this.sensitive = this._foundManager && this._permissions.appId;
105
106 if (this.sensitive)
107 this.set_tooltip_text(_('Show application in a software manager'));
108 else
109 this.set_tooltip_text(_('No software manager found'));
110 }
111
112 enable() {
113 this._update();
114 }
115
116 disable() {
117 this.sensitive = false;
118 this.set_tooltip_text('');
119 }
120 });