From 020586064ec611c777ac2deb3baf8cf4a3fe7e0d Mon Sep 17 00:00:00 2001 From: your-local-developer <73035294+your-local-developer@users.noreply.github.com> Date: Tue, 8 Feb 2022 11:01:02 +0100 Subject: [PATCH 1/2] Add time formatting so the shutdown timer shows hours and minutes Also includes localisation --- src/extension.js | 18 +++++++++++------- src/po/de.po | 36 +++++++++++++++++++++++------------- src/po/nl.po | 34 ++++++++++++++++++++++------------ src/timer.js | 19 ++++++++++++++++--- 4 files changed, 72 insertions(+), 35 deletions(-) diff --git a/src/extension.js b/src/extension.js index a20078b..337f23e 100644 --- a/src/extension.js +++ b/src/extension.js @@ -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 [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) + switcher.label.text = houers + ' ' +_("h : ") + minutes + ' min'; if (settings.get_boolean('root-mode-value')) { - switcher.label.text = _getTimerStartValue().toString() + ' min (root)'; + switcher.label.text = houers + ' ' +_("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 [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) + switcher.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min"); if (settings.get_boolean('root-mode-value')) { - switcher.label.text = _getTimerStartValue().toString() + ' ' +_("min (root)"); + switcher.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); } } @@ -92,8 +94,9 @@ function _onShowSettingsButtonChanged() { function _onToggle() { if(switcher.state) { timer.startTimer(); + const [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) _showTextbox( _("System will shutdown in")+ ' ' - + _getTimerStartValue().toString() + ' '+_("minutes")); + + houers + ' ' +_("h : ") + minutes + ' '+_("minutes")); } else { timer.stopTimer(); _showTextbox(_("Shutdown Timer stopped")); @@ -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 [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) + switchMenuItem.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min"); if(settings.get_boolean('root-mode-value')) { - switchMenuItem.label.text = _getTimerStartValue().toString() + ' ' +_("min (root)"); + switchMenuItem.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); } switchMenuItem.connect('toggled', _onToggle); diff --git a/src/po/de.po b/src/po/de.po index a5ee72d..c88e567 100644 --- a/src/po/de.po +++ b/src/po/de.po @@ -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 \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)" @@ -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" diff --git a/src/po/nl.po b/src/po/nl.po index 3a6a283..0f3e4fa 100644 --- a/src/po/nl.po +++ b/src/po/nl.po @@ -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 \n" "Language-Team: Dutch\n" "Language: nl\n" @@ -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)" @@ -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" diff --git a/src/timer.js b/src/timer.js index b53a414..d1611aa 100755 --- a/src/timer.js +++ b/src/timer.js @@ -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 [houers, minutes] = this.calculateTimeStamp(this._timerValue) + this._menuLabel.text = houers + ' ' + _("h : ") + minutes + ' ' + _("min till shutdown"); } else { let pkexec_path = GLib.find_program_in_path('pkexec'); let shutdown_path = GLib.find_program_in_path('shutdown'); @@ -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 [houers, minutes] = this.calculateTimeStamp(Math.floor(secondsLeft / 60)) + this._menuLabel.text = houers + ' ' +_("h : ") + minutes +' ' +_("min till shutdown"); } if (secondsLeft > 0) { return true; @@ -66,5 +68,16 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object { return false; } + /** + * Calculates houers and minutes from a time in minutes + * @param {number} timeInMinutes + * @returns {number[]} houers at i = 0, minutes at i = 1 + */ + calculateTimeStamp(timeInMinutes) { + const hours = Math.floor(timeInMinutes / 60) + const minutes = timeInMinutes - hours * 60 + return [hours, minutes] + } + }); From 7fd09605127af5166fc7ee5a78519f81a1f637e7 Mon Sep 17 00:00:00 2001 From: your-local-developer Date: Thu, 21 Jul 2022 15:52:11 +0000 Subject: [PATCH 2/2] Correct spelling mistake and rename timer.calculateTimeStamp --- src/extension.js | 22 +++++++++++----------- src/timer.js | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/extension.js b/src/extension.js index 337f23e..34914f0 100644 --- a/src/extension.js +++ b/src/extension.js @@ -65,22 +65,22 @@ function _getTimerStartValue() { // update timer value if slider has changed function _onSliderChanged() { settings.set_int('slider-value', (slider.value * 100)); - const [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) - switcher.label.text = houers + ' ' +_("h : ") + minutes + ' min'; + const [hours, minutes] = timer.convertTime(_getTimerStartValue()) + switcher.label.text = hours + ' ' +_("h : ") + minutes + ' min'; if (settings.get_boolean('root-mode-value')) { - switcher.label.text = houers + ' ' +_("h : ") + minutes + ' min (root)'; + switcher.label.text = hours + ' ' +_("h : ") + minutes + ' min (root)'; } } function _onSettingsChanged() { let sliderValue = settings.get_int('slider-value') / 100.0; slider.value = sliderValue; - const [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) - switcher.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min"); + const [hours, minutes] = timer.convertTime(_getTimerStartValue()) + switcher.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min"); if (settings.get_boolean('root-mode-value')) { - switcher.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); + switcher.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); } } @@ -94,9 +94,9 @@ function _onShowSettingsButtonChanged() { function _onToggle() { if(switcher.state) { timer.startTimer(); - const [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) + const [hours, minutes] = timer.convertTime(_getTimerStartValue()) _showTextbox( _("System will shutdown in")+ ' ' - + houers + ' ' +_("h : ") + minutes + ' '+_("minutes")); + + hours + ' ' +_("h : ") + minutes + ' '+_("minutes")); } else { timer.stopTimer(); _showTextbox(_("Shutdown Timer stopped")); @@ -107,10 +107,10 @@ function _onToggle() { // menu items switcher and slider function _createSwitcherItem() { let switchMenuItem = new PopupMenu.PopupSwitchMenuItem('', false); - const [houers, minutes] = timer.calculateTimeStamp(_getTimerStartValue()) - switchMenuItem.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min"); + const [hours, minutes] = timer.convertTime(_getTimerStartValue()) + switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min"); if(settings.get_boolean('root-mode-value')) { - switchMenuItem.label.text = houers + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); + switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min (root)"); } switchMenuItem.connect('toggled', _onToggle); diff --git a/src/timer.js b/src/timer.js index d1611aa..ee26edf 100755 --- a/src/timer.js +++ b/src/timer.js @@ -36,8 +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()); - const [houers, minutes] = this.calculateTimeStamp(this._timerValue) - this._menuLabel.text = houers + ' ' + _("h : ") + minutes + ' ' + _("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'); @@ -57,8 +57,8 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object { let secondsLeft = (this._timerValue*60) - secondsElapsed; if (this._menuLabel && (secondsLeft % 60 == 0)) { - const [houers, minutes] = this.calculateTimeStamp(Math.floor(secondsLeft / 60)) - this._menuLabel.text = houers + ' ' +_("h : ") + minutes +' ' +_("min till shutdown"); + const [hours, minutes] = this.convertTime(Math.floor(secondsLeft / 60)) + this._menuLabel.text = hours + ' ' +_("h : ") + minutes +' ' +_("min till shutdown"); } if (secondsLeft > 0) { return true; @@ -69,11 +69,11 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object { } /** - * Calculates houers and minutes from a time in minutes + * Calculates hours and minutes from a time in minutes * @param {number} timeInMinutes - * @returns {number[]} houers at i = 0, minutes at i = 1 + * @returns {Array} hours at index 0, minutes at index 1 */ - calculateTimeStamp(timeInMinutes) { + convertTime(timeInMinutes) { const hours = Math.floor(timeInMinutes / 60) const minutes = timeInMinutes - hours * 60 return [hours, minutes]