From 79fd107332b138fe9dc15d74239a18926540f201 Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Sun, 16 Sep 2018 13:48:17 +0200 Subject: [PATCH] Add extension files --- batime@martin.zurowietz.de/extension.js | 34 ++++++++++++++++++++ batime@martin.zurowietz.de/metadata.json | 11 +++++++ batime@martin.zurowietz.de/power.js | 40 ++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 batime@martin.zurowietz.de/extension.js create mode 100644 batime@martin.zurowietz.de/metadata.json create mode 100644 batime@martin.zurowietz.de/power.js diff --git a/batime@martin.zurowietz.de/extension.js b/batime@martin.zurowietz.de/extension.js new file mode 100644 index 0000000..dcdb2f7 --- /dev/null +++ b/batime@martin.zurowietz.de/extension.js @@ -0,0 +1,34 @@ +const ExtensionUtils = imports.misc.extensionUtils; +const BaTime = ExtensionUtils.getCurrentExtension(); +const Lang = imports.lang; +const Panel = imports.ui.main.panel; + +var BaTimeExtension = new Lang.Class({ + Name: 'BaTime', + _init: function () { + this.aggregateMenu = Panel.statusArea['aggregateMenu']; + this.originalIndicator = this.aggregateMenu._power; + this.customIndicator = new BaTime.imports.power.Indicator(); + this.aggregateMenu._indicators.replace_child( + this.originalIndicator.indicators, + this.customIndicator.indicators + ); + }, + destroy: function () { + this.aggregateMenu._indicators.replace_child( + this.customIndicator.indicators, + this.originalIndicator.indicators + ); + }, +}); + +let baTime; + +function enable() { + baTime = new BaTimeExtension(); +} + +function disable() { + baTime.destroy(); + baTime = null; +} diff --git a/batime@martin.zurowietz.de/metadata.json b/batime@martin.zurowietz.de/metadata.json new file mode 100644 index 0000000..89f7363 --- /dev/null +++ b/batime@martin.zurowietz.de/metadata.json @@ -0,0 +1,11 @@ + +{ + "shell-version": ["3.28", "3.30"], + "uuid": "batime@martin.zurowietz.de", + "url": "https://github.com/mzur/gnome-shell-batime", + "settings-schema": "org.gnome.shell.extensions.batime", + "gettext-domain": "batime", + "version": -1, + "name": "Battery Time", + "description": "Show the remaining time until fully charged/discharged instead of the battery charge in percent in the panel." +} diff --git a/batime@martin.zurowietz.de/power.js b/batime@martin.zurowietz.de/power.js new file mode 100644 index 0000000..ccd8877 --- /dev/null +++ b/batime@martin.zurowietz.de/power.js @@ -0,0 +1,40 @@ +const Lang = imports.lang; +const UPower = imports.gi.UPowerGlib; + +var Indicator = new Lang.Class({ + Name: 'PowerIndicator', + + Extends: imports.ui.status.power.Indicator, + + // Adapted from _getStatus of the parent. + _getTime() { + let seconds = 0; + + if (this._proxy.State == UPower.DeviceState.CHARGING) { + seconds = this._proxy.TimeToFull; + } else if (this._proxy.State == UPower.DeviceState.DISCHARGING) { + seconds = this._proxy.TimeToEmpty; + } else { + // state is one of PENDING_CHARGING, PENDING_DISCHARGING + return _("Estimating…"); + } + + let time = Math.round(seconds / 60); + if (time == 0) { + // 0 is reported when UPower does not have enough data + // to estimate battery life + return _("Estimating…"); + } + + let minutes = time % 60; + let hours = Math.floor(time / 60); + + // Translators: this is : + return _("%d\u2236%02d").format(hours, minutes); + }, + + _sync() { + this.parent(); + this._percentageLabel.clutter_text.set_markup('' + this._getTime() + ''); + }, +});