Skip to content

Commit

Permalink
Merge pull request #49 from your-local-developer/time-formatting
Browse files Browse the repository at this point in the history
Add time formatting so the shutdown timer shows hours and minutes
  • Loading branch information
neumann-d authored Jul 24, 2022
2 parents aa808a3 + 7fd0960 commit 1ebb4b4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 35 deletions.
18 changes: 11 additions & 7 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ function _getTimerStartValue() {
// update timer value if slider has changed
function _onSliderChanged() {
settings.set_int('slider-value', (slider.value * 100));
switcher.label.text = _getTimerStartValue().toString() + ' min';
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
switcher.label.text = hours + ' ' +_("h : ") + minutes + ' min';

if (settings.get_boolean('root-mode-value')) {
switcher.label.text = _getTimerStartValue().toString() + ' min (root)';
switcher.label.text = hours + ' ' +_("h : ") + minutes + ' min (root)';
}
}

function _onSettingsChanged() {
let sliderValue = settings.get_int('slider-value') / 100.0;
slider.value = sliderValue;
switcher.label.text = _getTimerStartValue().toString() + ' ' +_("min");
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
switcher.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min");

if (settings.get_boolean('root-mode-value')) {
switcher.label.text = _getTimerStartValue().toString() + ' ' +_("min (root)");
switcher.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min (root)");
}
}

Expand All @@ -92,8 +94,9 @@ function _onShowSettingsButtonChanged() {
function _onToggle() {
if(switcher.state) {
timer.startTimer();
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
_showTextbox( _("System will shutdown in")+ ' '
+ _getTimerStartValue().toString() + ' '+_("minutes"));
+ hours + ' ' +_("h : ") + minutes + ' '+_("minutes"));
} else {
timer.stopTimer();
_showTextbox(_("Shutdown Timer stopped"));
Expand All @@ -104,9 +107,10 @@ function _onToggle() {
// menu items switcher and slider
function _createSwitcherItem() {
let switchMenuItem = new PopupMenu.PopupSwitchMenuItem('', false);
switchMenuItem.label.text = _getTimerStartValue().toString() + ' ' +_("min");
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min");
if(settings.get_boolean('root-mode-value')) {
switchMenuItem.label.text = _getTimerStartValue().toString() + ' ' +_("min (root)");
switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min (root)");
}

switchMenuItem.connect('toggled', _onToggle);
Expand Down
36 changes: 23 additions & 13 deletions src/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,55 @@ msgid ""
msgstr ""
"Project-Id-Version: Shutdown Timer GNOME Shell Extension\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-05-28 22:48+0200\n"
"PO-Revision-Date: 2021-05-28 22:50+0200\n"
"POT-Creation-Date: 2022-02-08 10:49+0100\n"
"PO-Revision-Date: 2022-02-08 10:49+0100\n"
"Last-Translator: Daniel Neumann\n"
"Language-Team: GERMAN Jonatan Zeidler <[email protected]>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"X-Generator: Poedit 3.0\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: _\n"
"X-Poedit-Basepath: ../../..\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SearchPath-0: .\n"

#: extension.js:82 extension.js:105
#: extension.js:69 extension.js:72 extension.js:80 extension.js:83
#: extension.js:99 extension.js:111 extension.js:113 timer.js:40 timer.js:61
msgid "h : "
msgstr "h : "

#: extension.js:80 extension.js:111
msgid "min"
msgstr "min"

#: extension.js:85 extension.js:107
#: extension.js:83 extension.js:113
msgid "min (root)"
msgstr "min (root)"

#: extension.js:93
#: extension.js:98
msgid "System will shutdown in"
msgstr "System wird herunterfahren in"

#: extension.js:94
#: extension.js:99
msgid "minutes"
msgstr "Minuten"

#: extension.js:97
#: extension.js:102
msgid "Shutdown Timer stopped"
msgstr "Ausschaltuhr gestoppt"

#: extension.js:98 extension.js:188
#: extension.js:103 extension.js:182
msgid "Shutdown Timer"
msgstr "Ausschaltuhr"

#: extension.js:116
#: extension.js:122
msgid "Settings"
msgstr "Einstellungen"

#: prefs.js:35
#: prefs.js:33
msgid "Maximum timer value (in minutes)"
msgstr "Maximaler Uhrenwert (in Minuten)"

Expand Down Expand Up @@ -120,6 +125,11 @@ msgstr ""
msgid "Use suspend instead of shutdown command."
msgstr "Verwende Ruhezustand anstelle des Ausschalten-Kommandos."

#: timer.js:44 timer.js:64
#: timer.js:40 timer.js:61
msgid "min till shutdown"
msgstr "min bis zum Herunterfahren"

#, fuzzy
#~| msgid "Slider position"
#~ msgid "Hide Applications"
#~ msgstr "Schieberegler-Position"
34 changes: 22 additions & 12 deletions src/po/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Shutdown Timer GNOME Shell Extension\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-05-28 22:47+0200\n"
"PO-Revision-Date: 2021-07-12 14:00+0200\n"
"POT-Creation-Date: 2022-02-08 10:51+0100\n"
"PO-Revision-Date: 2022-02-08 10:52+0100\n"
"Last-Translator: Heimen Stoffels <[email protected]>\n"
"Language-Team: Dutch\n"
"Language: nl\n"
Expand All @@ -17,38 +17,43 @@ msgstr ""
"X-Generator: Poedit 3.0\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: _\n"
"X-Poedit-Basepath: ../../..\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-SearchPath-0: .\n"

#: extension.js:82 extension.js:105
#: extension.js:69 extension.js:72 extension.js:80 extension.js:83
#: extension.js:99 extension.js:111 extension.js:113 timer.js:40 timer.js:61
msgid "h : "
msgstr "h : "

#: extension.js:80 extension.js:111
msgid "min"
msgstr "min."

#: extension.js:85 extension.js:107
#: extension.js:83 extension.js:113
msgid "min (root)"
msgstr "min. (root)"

#: extension.js:93
#: extension.js:98
msgid "System will shutdown in"
msgstr "Het systeem wordt afgesloten over"

#: extension.js:94
#: extension.js:99
msgid "minutes"
msgstr "minuten"

#: extension.js:97
#: extension.js:102
msgid "Shutdown Timer stopped"
msgstr "Afsluitklok is gestopt"

#: extension.js:98 extension.js:188
#: extension.js:103 extension.js:182
msgid "Shutdown Timer"
msgstr "Afsluitklok"

#: extension.js:116
#: extension.js:122
msgid "Settings"
msgstr "Voorkeuren"

#: prefs.js:35
#: prefs.js:33
msgid "Maximum timer value (in minutes)"
msgstr "Maximale tijdklokwaarde (in minuten)"

Expand Down Expand Up @@ -119,6 +124,11 @@ msgstr ""
msgid "Use suspend instead of shutdown command."
msgstr "Zet de computer in de pauzestand in plaats van deze af te sluiten."

#: timer.js:44 timer.js:64
#: timer.js:40 timer.js:61
msgid "min till shutdown"
msgstr "aantal min. tot afsluiten"

#, fuzzy
#~| msgid "Slider position"
#~ msgid "Hide Applications"
#~ msgstr "Schuifbalkpositie"
19 changes: 16 additions & 3 deletions src/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object {
if(this._settings.get_boolean('use-suspend-value') || !this._settings.get_boolean('root-mode-value')) {
this._startTime = GLib.get_monotonic_time();
this._timerId = Mainloop.timeout_add_seconds(1, () => this._timerCallback());
this._menuLabel.text = this._timerValue.toString() + ' ' + _("min till shutdown");
const [hours, minutes] = this.convertTime(this._timerValue)
this._menuLabel.text = hours + ' ' + _("h : ") + minutes + ' ' + _("min till shutdown");
} else {
let pkexec_path = GLib.find_program_in_path('pkexec');
let shutdown_path = GLib.find_program_in_path('shutdown');
Expand All @@ -55,8 +56,9 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object {
let secondsElapsed = Math.floor((currentTime - this._startTime) / 1000000);

let secondsLeft = (this._timerValue*60) - secondsElapsed;
if (this._menuLabel && (secondsLeft%60 == 0)) {
this._menuLabel.text = Math.floor(secondsLeft/60).toString()+' '+_("min till shutdown");
if (this._menuLabel && (secondsLeft % 60 == 0)) {
const [hours, minutes] = this.convertTime(Math.floor(secondsLeft / 60))
this._menuLabel.text = hours + ' ' +_("h : ") + minutes +' ' +_("min till shutdown");
}
if (secondsLeft > 0) {
return true;
Expand All @@ -66,5 +68,16 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object {
return false;
}

/**
* Calculates hours and minutes from a time in minutes
* @param {number} timeInMinutes
* @returns {Array<number>} hours at index 0, minutes at index 1
*/
convertTime(timeInMinutes) {
const hours = Math.floor(timeInMinutes / 60)
const minutes = timeInMinutes - hours * 60
return [hours, minutes]
}

});

0 comments on commit 1ebb4b4

Please sign in to comment.