diff --git a/js/ui/status/power.js b/js/ui/status/power.js index 429db7a8f..eda8c01e3 100644 --- a/js/ui/status/power.js +++ b/js/ui/status/power.js @@ -8,20 +8,20 @@ const Main = imports.ui.main; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; -const BUS_NAME = 'org.gnome.SettingsDaemon.Power'; -const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power'; +const BUS_NAME = 'org.freedesktop.UPower'; +const OBJECT_PATH = '/org/freedesktop/UPower/devices/DisplayDevice'; -const PowerManagerInterface = - - - - - - - +const DisplayDeviceInterface = + + + + + + + ; -const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface); +const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(DisplayDeviceInterface); const Indicator = new Lang.Class({ Name: 'PowerIndicator', @@ -32,7 +32,7 @@ const Indicator = new Lang.Class({ this._indicator = this._addIndicator(); - this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, + this._proxy = new PowerManagerProxy(Gio.DBus.system, BUS_NAME, OBJECT_PATH, Lang.bind(this, function(proxy, error) { if (error) { log(error.message); @@ -43,7 +43,7 @@ const Indicator = new Lang.Class({ this._sync(); })); - this._item = new PopupMenu.PopupSubMenuMenuItem(_("Battery"), true); + this._item = new PopupMenu.PopupSubMenuMenuItem("", true); this._item.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop'); this.menu.addMenuItem(this._item); @@ -56,11 +56,18 @@ const Indicator = new Lang.Class({ this.menu.setSensitive(sensitive); }, - _statusForDevice: function(device) { - let [device_id, device_type, icon, percentage, state, seconds] = device; + _getStatus: function() { + let seconds = 0; - if (state == UPower.DeviceState.FULLY_CHARGED) + if (this._proxy.State == UPower.DeviceState.FULLY_CHARGED) return _("Fully Charged"); + else if (this._proxy.State == UPower.DeviceState.CHARGING) + seconds = this._proxy.TimeToFull; + else if (this_proxy.State == UPower.DeviceState.DISCHARGING) + seconds = this._proxy.TimeToEmpty; + // state is one of PENDING_CHARGING, PENDING_DISCHARGING + else + return _("Estimating…"); let time = Math.round(seconds / 60); if (time == 0) { @@ -82,34 +89,33 @@ const Indicator = new Lang.Class({ return _("%d\u2236%02d Until Full (%d%%)").format(hours, minutes, percentage); } - // state is one of PENDING_CHARGING, PENDING_DISCHARGING - return _("Estimating…"); + return null; }, _sync: function() { - function isBattery(result) { - if (!result) - return false; - - let [device] = result; - let [, deviceType] = device; - return (deviceType == UPower.DeviceKind.BATTERY); + // Do we have batteries or a UPS? + let visible = this._proxy.IsPresent; + if (visible) { + this._item.actor.show(); + } else { + // If there's no battery, then we use the power icon. + this._item.actor.hide(); + this._indicator.icon_name = 'system-shutdown-symbolic'; + return; } - this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) { - if (isBattery(result)) { - let [device] = result; - let [,, icon] = device; - let gicon = Gio.icon_new_for_string(icon); - this._indicator.gicon = gicon; - this._item.icon.gicon = gicon; - this._item.status.text = this._statusForDevice(device); - this._item.actor.show(); - } else { - // If there's no battery, then we use the power icon. - this._indicator.icon_name = 'system-shutdown-symbolic'; - this._item.actor.hide(); - } - })); + // The icons + let icon = this._proxy.IconName; + this._indicator.icon_name = icon; + this._item.icon.icon_name = icon; + + // The status label + this._item.status.text = this._getStatus(); + + // The sub-menu heading + if (this._proxy.Type == UPower.DeviceKind.UPS) + this._item.label.text = _("UPS"); + else + this._item.label.text = _("Battery"); }, });