Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[email protected]: Add 24H support to Timelet themes #908

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion [email protected]/files/[email protected]/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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" });
Expand Down
16 changes: 12 additions & 4 deletions [email protected]/files/[email protected]/po/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -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 ""

Expand All @@ -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 ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 7 additions & 3 deletions [email protected]/files/[email protected]/themes/flair.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
Expand Down
5 changes: 4 additions & 1 deletion [email protected]/files/[email protected]/themes/metro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion [email protected]/files/[email protected]/themes/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
*
Expand Down
Loading