1
1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
3
3
const Gio = imports.gi.Gio;
4
const DBus = imports.dbus;
5
4
const Lang = imports.lang;
6
5
const Mainloop = imports.mainloop;
7
6
const Shell = imports.gi.Shell;
40
39
PENDING_DISCHARGE: 6
43
const PowerManagerInterface = {
44
name: 'org.gnome.SettingsDaemon.Power',
46
{ name: 'GetDevices', inSignature: '', outSignature: 'a(susdut)' },
47
{ name: 'GetPrimaryDevice', inSignature: '', outSignature: '(susdut)' },
50
{ name: 'Changed', inSignature: '' },
53
{ name: 'Icon', signature: 's', access: 'read' },
56
let PowerManagerProxy = DBus.makeProxyClass(PowerManagerInterface);
58
function Indicator() {
59
this._init.apply(this, arguments);
62
Indicator.prototype = {
63
__proto__: PanelMenu.SystemStatusButton.prototype,
42
const PowerManagerInterface = <interface name="org.gnome.SettingsDaemon.Power">
43
<method name="GetDevices">
44
<arg type="a(susdut)" direction="out" />
46
<method name="GetPrimaryDevice">
47
<arg type="(susdut)" direction="out" />
49
<property name="Icon" type="s" access="read" />
52
const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface);
54
const Indicator = new Lang.Class({
55
Name: 'PowerIndicator',
56
Extends: PanelMenu.SystemStatusButton,
65
58
_init: function() {
66
PanelMenu.SystemStatusButton.prototype._init.call(this, 'battery-missing');
67
this._proxy = new PowerManagerProxy(DBus.session, BUS_NAME, OBJECT_PATH);
59
this.parent('battery-missing', _("Battery"));
61
this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
69
63
this._deviceItems = [ ];
70
64
this._hasPrimary = false;
81
75
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
82
76
this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
84
this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
78
this._proxy.connect('g-properties-changed',
79
Lang.bind(this, this._devicesChanged));
85
80
this._devicesChanged();
88
83
_readPrimaryDevice: function() {
89
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(device, error) {
84
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
91
86
this._hasPrimary = false;
92
87
this._primaryDeviceId = null;
93
88
this._batteryItem.actor.hide();
96
let [device_id, device_type, icon, percentage, state, seconds] = device;
91
let [[device_id, device_type, icon, percentage, state, seconds]] = result;
97
92
if (device_type == UPDeviceType.BATTERY) {
98
93
this._hasPrimary = true;
99
94
let time = Math.round(seconds / 60);
132
127
_readOtherDevices: function() {
133
this._proxy.GetDevicesRemote(Lang.bind(this, function(devices, error) {
128
this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
134
129
this._deviceItems.forEach(function(i) { i.destroy(); });
135
130
this._deviceItems = [];
155
151
_devicesChanged: function() {
156
this._proxy.GetRemote('Icon', Lang.bind(this, function(icon, error) {
158
let gicon = Gio.icon_new_for_string(icon);
159
this.setGIcon(gicon);
152
let icon = this._proxy.Icon;
154
let gicon = Gio.icon_new_for_string(icon);
155
this.setGIcon(gicon);
166
161
this._readPrimaryDevice();
167
162
this._readOtherDevices();
171
function DeviceItem() {
172
this._init.apply(this, arguments);
175
DeviceItem.prototype = {
176
__proto__: PopupMenu.PopupBaseMenuItem.prototype,
166
const DeviceItem = new Lang.Class({
168
Extends: PopupMenu.PopupBaseMenuItem,
178
170
_init: function(device) {
179
PopupMenu.PopupBaseMenuItem.prototype._init.call(this, { reactive: false });
171
this.parent({ reactive: false });
181
173
let [device_id, device_type, icon, percentage, state, time] = device;