From ddb9f8943b056438d62406e648429d856ce8ecf2 Mon Sep 17 00:00:00 2001 From: Gobinath Loganathan Date: Thu, 10 Aug 2023 21:44:10 -0400 Subject: [PATCH] Add 24H support to timelet@linuxedo.com --- .../files/timelet@linuxedo.com/desklet.js | 3 ++- .../po/timelet@linuxedo.com.pot | 16 ++++++++++++---- .../timelet@linuxedo.com/settings-schema.json | 6 ++++++ .../files/timelet@linuxedo.com/themes/digital.js | 2 +- .../files/timelet@linuxedo.com/themes/flair.js | 10 +++++++--- .../files/timelet@linuxedo.com/themes/gotham.js | 2 +- .../files/timelet@linuxedo.com/themes/jelly.js | 2 +- .../files/timelet@linuxedo.com/themes/metro.js | 5 ++++- .../files/timelet@linuxedo.com/themes/theme.js | 12 +++++++++++- 9 files changed, 45 insertions(+), 13 deletions(-) diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/desklet.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/desklet.js index 37436c2ed..efe5a8ecb 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/desklet.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/desklet.js @@ -51,6 +51,7 @@ Timelet.prototype = { this.settings = new Settings.DeskletSettings(this, this.metadata["uuid"], this.instance_id); this.settings.bind("themeName", "themeName", this.onSettingChanged); + this.settings.bind("use24H", "use24H", this.onSettingChanged); this.settings.bind("textColor", "textColor", this.onSettingChanged); this.settings.bind("bgColor", "bgColor", this.onSettingChanged); this.settings.bind("scale", "scale", this.onSettingChanged); @@ -80,7 +81,7 @@ Timelet.prototype = { _setTheme() { // Set the theme - this._theme = Themes.getTheme(this.themeName, new Config(this.scale, this.textColor)); + this._theme = Themes.getTheme(this.themeName, new Config(this.use24H, this.scale, this.textColor)); // Define the desklet container let deskletContainer = new St.BoxLayout({ vertical: true,style_class: "desklet" }); diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/po/timelet@linuxedo.com.pot b/timelet@linuxedo.com/files/timelet@linuxedo.com/po/timelet@linuxedo.com.pot index e1cc76d27..4b15f05cc 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/po/timelet@linuxedo.com.pot +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/po/timelet@linuxedo.com.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-12 06:11-0500\n" +"POT-Creation-Date: 2023-08-10 21:39-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -21,15 +21,15 @@ msgstr "" msgid "Timelet" msgstr "" -#: themes/theme.js:133 +#: themes/theme.js:143 msgid "AM" msgstr "" -#: themes/theme.js:135 +#: themes/theme.js:145 msgid "Noon" msgstr "" -#: themes/theme.js:137 +#: themes/theme.js:147 msgid "PM" msgstr "" @@ -45,6 +45,14 @@ msgstr "" msgid "Theme" msgstr "" +#. settings-schema.json->use24H->description +msgid "Use 24H" +msgstr "" + +#. settings-schema.json->use24H->tooltip +msgid "Display time in 24H if the theme supports it" +msgstr "" + #. settings-schema.json->textColor->description msgid "Text color" msgstr "" diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/settings-schema.json b/timelet@linuxedo.com/files/timelet@linuxedo.com/settings-schema.json index aec5d4eea..d995f6b84 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/settings-schema.json +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/settings-schema.json @@ -9,6 +9,12 @@ "options": {}, "description": "Theme" }, + "use24H": { + "type": "checkbox", + "default": false, + "description": "Use 24H", + "tooltip": "Display time in 24H" + }, "textColor": { "type": "colorchooser", "indent": true, diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/digital.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/digital.js index e20fd8b00..c7fa6a21c 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/digital.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/digital.js @@ -43,7 +43,7 @@ var DigitalTheme = class DigitalTheme extends Theme { } setDateTime(date, locale) { - let time = this.to2Digit(date.getHours()) + ":" + this.to2Digit(date.getMinutes()) + ":" + this.to2Digit(date.getSeconds()); + let time = this.to2Digit(this.is24H() ? date.getHours() : this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()) + ":" + this.to2Digit(date.getSeconds()); this._time.set_text(time); } } \ No newline at end of file diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/flair.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/flair.js index 4c6848db8..f25a4f135 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/flair.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/flair.js @@ -44,14 +44,18 @@ var FlairTheme = class FlairTheme extends Theme { this._timeContainer.add(this._time); this._PeriodContainer.add(this._period); this._clockContainer.add(this._timeContainer); - this._clockContainer.add(this._PeriodContainer); + if (!this.is24H()) { + this._clockContainer.add(this._PeriodContainer); + } return this._clockContainer; } setDateTime(date, locale) { - let time = this.to2Digit(this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()); + let time = this.to2Digit(this.is24H() ? date.getHours() : this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()); this._time.set_text(time); - this._period.set_text(this.toPeriod(date.getHours())); + if (!this.is24H()) { + this._period.set_text(this.toPeriod(date.getHours())); + } } } \ No newline at end of file diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/gotham.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/gotham.js index adde69775..b50499a0c 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/gotham.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/gotham.js @@ -57,7 +57,7 @@ var GothamTheme = class GothamTheme extends Theme { } setDateTime(date, locale) { - let time = this.to2Digit(this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()); + let time = this.to2Digit(this.is24H() ? date.getHours() : this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()); this._time.set_text(time); this._weekday.set_text(this.formatDateTime(date, locale, { weekday: "long" })); this._date.set_text(this.formatDateTime(date, locale, { day: "2-digit" })); diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/jelly.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/jelly.js index d924ed763..4d72e922c 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/jelly.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/jelly.js @@ -63,7 +63,7 @@ var JellyTheme = class JellyTheme extends Theme { } setDateTime(date, locale) { - this._hour.set_text(this.to2Digit(date.getHours())); + this._hour.set_text(this.to2Digit(this.is24H() ? date.getHours() : this.to12Hours(date.getHours()))); this._seperator.set_text(":"); this._minute.set_text(this.to2Digit(date.getMinutes())); this._weekday.set_text(this.formatDateTime(date, locale, { weekday: "long" })); diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/metro.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/metro.js index 0ee621f94..b3ebee0fd 100644 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/metro.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/metro.js @@ -51,7 +51,10 @@ var MetroTheme = class MetroTheme extends Theme { setDateTime(date, locale) { let month = this.formatDateTime(date, locale, { month: "long" }); - let time = this.to2Digit(this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()) + " " + this.toPeriod(date.getHours()); + let time = this.to2Digit(this.is24H() ? date.getHours() : this.to12Hours(date.getHours())) + ":" + this.to2Digit(date.getMinutes()); + if (!this.is24H()) { + time += " " + this.toPeriod(date.getHours()); + } this._weekday.set_text(this.formatDateTime(date, locale, { weekday: "long" })); this._date_month.set_text(month + " " + this.to2Digit(date.getDate())); this._time.set_text(time); diff --git a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/theme.js b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/theme.js index 2f770e305..dd61805ff 100755 --- a/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/theme.js +++ b/timelet@linuxedo.com/files/timelet@linuxedo.com/themes/theme.js @@ -31,7 +31,8 @@ function _(str) { * This class is used to pass user configurations to themes. */ var Config = class Config { - constructor(scale, textColor) { + constructor(use24H, scale, textColor) { + this.use24H = use24H; this.scale = scale; this.textColor = textColor; } @@ -90,6 +91,15 @@ var Theme = class Theme { return dateFormatter.format(date); } + /** + * Returns true if user prefers time in 24H format. + * + * @returns true if user prefers 24H + */ + is24H() { + return this._config.use24H; + } + /** * A utility function to format a single digit number to a 2 digit string. *