Skip to content

Commit 1ebb4b4

Browse files
authored
Merge pull request #49 from your-local-developer/time-formatting
Add time formatting so the shutdown timer shows hours and minutes
2 parents aa808a3 + 7fd0960 commit 1ebb4b4

File tree

4 files changed

+72
-35
lines changed

4 files changed

+72
-35
lines changed

src/extension.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ function _getTimerStartValue() {
6565
// update timer value if slider has changed
6666
function _onSliderChanged() {
6767
settings.set_int('slider-value', (slider.value * 100));
68-
switcher.label.text = _getTimerStartValue().toString() + ' min';
68+
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
69+
switcher.label.text = hours + ' ' +_("h : ") + minutes + ' min';
6970

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

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

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

@@ -92,8 +94,9 @@ function _onShowSettingsButtonChanged() {
9294
function _onToggle() {
9395
if(switcher.state) {
9496
timer.startTimer();
97+
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
9598
_showTextbox( _("System will shutdown in")+ ' '
96-
+ _getTimerStartValue().toString() + ' '+_("minutes"));
99+
+ hours + ' ' +_("h : ") + minutes + ' '+_("minutes"));
97100
} else {
98101
timer.stopTimer();
99102
_showTextbox(_("Shutdown Timer stopped"));
@@ -104,9 +107,10 @@ function _onToggle() {
104107
// menu items switcher and slider
105108
function _createSwitcherItem() {
106109
let switchMenuItem = new PopupMenu.PopupSwitchMenuItem('', false);
107-
switchMenuItem.label.text = _getTimerStartValue().toString() + ' ' +_("min");
110+
const [hours, minutes] = timer.convertTime(_getTimerStartValue())
111+
switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min");
108112
if(settings.get_boolean('root-mode-value')) {
109-
switchMenuItem.label.text = _getTimerStartValue().toString() + ' ' +_("min (root)");
113+
switchMenuItem.label.text = hours + ' ' +_("h : ") + minutes + ' ' +_("min (root)");
110114
}
111115

112116
switchMenuItem.connect('toggled', _onToggle);

src/po/de.po

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,55 @@ msgid ""
55
msgstr ""
66
"Project-Id-Version: Shutdown Timer GNOME Shell Extension\n"
77
"Report-Msgid-Bugs-To: \n"
8-
"POT-Creation-Date: 2021-05-28 22:48+0200\n"
9-
"PO-Revision-Date: 2021-05-28 22:50+0200\n"
8+
"POT-Creation-Date: 2022-02-08 10:49+0100\n"
9+
"PO-Revision-Date: 2022-02-08 10:49+0100\n"
1010
"Last-Translator: Daniel Neumann\n"
1111
"Language-Team: GERMAN Jonatan Zeidler <jonatan_zeidler@gmx.de>\n"
1212
"Language: de\n"
1313
"MIME-Version: 1.0\n"
1414
"Content-Type: text/plain; charset=UTF-8\n"
1515
"Content-Transfer-Encoding: 8bit\n"
16-
"X-Generator: Poedit 2.3\n"
16+
"X-Generator: Poedit 3.0\n"
1717
"X-Poedit-SourceCharset: UTF-8\n"
1818
"X-Poedit-KeywordsList: _\n"
19-
"X-Poedit-Basepath: ../../..\n"
19+
"X-Poedit-Basepath: ..\n"
2020
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
2121
"X-Poedit-SearchPath-0: .\n"
2222

23-
#: extension.js:82 extension.js:105
23+
#: extension.js:69 extension.js:72 extension.js:80 extension.js:83
24+
#: extension.js:99 extension.js:111 extension.js:113 timer.js:40 timer.js:61
25+
msgid "h : "
26+
msgstr "h : "
27+
28+
#: extension.js:80 extension.js:111
2429
msgid "min"
2530
msgstr "min"
2631

27-
#: extension.js:85 extension.js:107
32+
#: extension.js:83 extension.js:113
2833
msgid "min (root)"
2934
msgstr "min (root)"
3035

31-
#: extension.js:93
36+
#: extension.js:98
3237
msgid "System will shutdown in"
3338
msgstr "System wird herunterfahren in"
3439

35-
#: extension.js:94
40+
#: extension.js:99
3641
msgid "minutes"
3742
msgstr "Minuten"
3843

39-
#: extension.js:97
44+
#: extension.js:102
4045
msgid "Shutdown Timer stopped"
4146
msgstr "Ausschaltuhr gestoppt"
4247

43-
#: extension.js:98 extension.js:188
48+
#: extension.js:103 extension.js:182
4449
msgid "Shutdown Timer"
4550
msgstr "Ausschaltuhr"
4651

47-
#: extension.js:116
52+
#: extension.js:122
4853
msgid "Settings"
4954
msgstr "Einstellungen"
5055

51-
#: prefs.js:35
56+
#: prefs.js:33
5257
msgid "Maximum timer value (in minutes)"
5358
msgstr "Maximaler Uhrenwert (in Minuten)"
5459

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

123-
#: timer.js:44 timer.js:64
128+
#: timer.js:40 timer.js:61
124129
msgid "min till shutdown"
125130
msgstr "min bis zum Herunterfahren"
131+
132+
#, fuzzy
133+
#~| msgid "Slider position"
134+
#~ msgid "Hide Applications"
135+
#~ msgstr "Schieberegler-Position"

src/po/nl.po

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ msgid ""
55
msgstr ""
66
"Project-Id-Version: Shutdown Timer GNOME Shell Extension\n"
77
"Report-Msgid-Bugs-To: \n"
8-
"POT-Creation-Date: 2021-05-28 22:47+0200\n"
9-
"PO-Revision-Date: 2021-07-12 14:00+0200\n"
8+
"POT-Creation-Date: 2022-02-08 10:51+0100\n"
9+
"PO-Revision-Date: 2022-02-08 10:52+0100\n"
1010
"Last-Translator: Heimen Stoffels <vistausss@fastmail.com>\n"
1111
"Language-Team: Dutch\n"
1212
"Language: nl\n"
@@ -17,38 +17,43 @@ msgstr ""
1717
"X-Generator: Poedit 3.0\n"
1818
"X-Poedit-SourceCharset: UTF-8\n"
1919
"X-Poedit-KeywordsList: _\n"
20-
"X-Poedit-Basepath: ../../..\n"
20+
"X-Poedit-Basepath: ..\n"
2121
"X-Poedit-SearchPath-0: .\n"
2222

23-
#: extension.js:82 extension.js:105
23+
#: extension.js:69 extension.js:72 extension.js:80 extension.js:83
24+
#: extension.js:99 extension.js:111 extension.js:113 timer.js:40 timer.js:61
25+
msgid "h : "
26+
msgstr "h : "
27+
28+
#: extension.js:80 extension.js:111
2429
msgid "min"
2530
msgstr "min."
2631

27-
#: extension.js:85 extension.js:107
32+
#: extension.js:83 extension.js:113
2833
msgid "min (root)"
2934
msgstr "min. (root)"
3035

31-
#: extension.js:93
36+
#: extension.js:98
3237
msgid "System will shutdown in"
3338
msgstr "Het systeem wordt afgesloten over"
3439

35-
#: extension.js:94
40+
#: extension.js:99
3641
msgid "minutes"
3742
msgstr "minuten"
3843

39-
#: extension.js:97
44+
#: extension.js:102
4045
msgid "Shutdown Timer stopped"
4146
msgstr "Afsluitklok is gestopt"
4247

43-
#: extension.js:98 extension.js:188
48+
#: extension.js:103 extension.js:182
4449
msgid "Shutdown Timer"
4550
msgstr "Afsluitklok"
4651

47-
#: extension.js:116
52+
#: extension.js:122
4853
msgid "Settings"
4954
msgstr "Voorkeuren"
5055

51-
#: prefs.js:35
56+
#: prefs.js:33
5257
msgid "Maximum timer value (in minutes)"
5358
msgstr "Maximale tijdklokwaarde (in minuten)"
5459

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

122-
#: timer.js:44 timer.js:64
127+
#: timer.js:40 timer.js:61
123128
msgid "min till shutdown"
124129
msgstr "aantal min. tot afsluiten"
130+
131+
#, fuzzy
132+
#~| msgid "Slider position"
133+
#~ msgid "Hide Applications"
134+
#~ msgstr "Schuifbalkpositie"

src/timer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object {
3636
if(this._settings.get_boolean('use-suspend-value') || !this._settings.get_boolean('root-mode-value')) {
3737
this._startTime = GLib.get_monotonic_time();
3838
this._timerId = Mainloop.timeout_add_seconds(1, () => this._timerCallback());
39-
this._menuLabel.text = this._timerValue.toString() + ' ' + _("min till shutdown");
39+
const [hours, minutes] = this.convertTime(this._timerValue)
40+
this._menuLabel.text = hours + ' ' + _("h : ") + minutes + ' ' + _("min till shutdown");
4041
} else {
4142
let pkexec_path = GLib.find_program_in_path('pkexec');
4243
let shutdown_path = GLib.find_program_in_path('shutdown');
@@ -55,8 +56,9 @@ const Timer = GObject.registerClass({}, class Timer extends GObject.Object {
5556
let secondsElapsed = Math.floor((currentTime - this._startTime) / 1000000);
5657

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

71+
/**
72+
* Calculates hours and minutes from a time in minutes
73+
* @param {number} timeInMinutes
74+
* @returns {Array<number>} hours at index 0, minutes at index 1
75+
*/
76+
convertTime(timeInMinutes) {
77+
const hours = Math.floor(timeInMinutes / 60)
78+
const minutes = timeInMinutes - hours * 60
79+
return [hours, minutes]
80+
}
81+
6982
});
7083

0 commit comments

Comments
 (0)