feat: add option to hide seconds on calendar (#343)

This commit is contained in:
Rubin Bhandari
2024-10-21 01:52:29 +05:45
committed by GitHub
parent 166120f603
commit 5b01d3e60e
3 changed files with 35 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
import { BoxWidget } from 'lib/types/widget'; import { BoxWidget } from 'lib/types/widget';
import options from 'options'; import options from 'options';
const { military } = options.menus.clock.time; const { military, hideSeconds } = options.menus.clock.time;
const time = Variable('', { const time = Variable('', {
poll: [1000, 'date "+%I:%M:%S"'], poll: [1000, 'date "+%I:%M:%S"'],
@@ -26,7 +26,9 @@ const TimeWidget = (): BoxWidget => {
vpack: 'center', vpack: 'center',
hpack: 'center', hpack: 'center',
class_name: 'clock-content-items', class_name: 'clock-content-items',
children: military.bind('value').as((is24hr) => { children: Utils.merge(
[military.bind('value'), hideSeconds.bind('value')],
(is24hr: boolean, hideSeconds: boolean) => {
if (!is24hr) { if (!is24hr) {
return [ return [
Widget.Box({ Widget.Box({
@@ -34,7 +36,7 @@ const TimeWidget = (): BoxWidget => {
children: [ children: [
Widget.Label({ Widget.Label({
class_name: 'clock-content-time', class_name: 'clock-content-time',
label: time.bind(), label: hideSeconds ? time.bind().as((str) => str.slice(0, -3)) : time.bind(),
}), }),
], ],
}), }),
@@ -57,12 +59,15 @@ const TimeWidget = (): BoxWidget => {
children: [ children: [
Widget.Label({ Widget.Label({
class_name: 'clock-content-time', class_name: 'clock-content-time',
label: militaryTime.bind(), label: hideSeconds
? militaryTime.bind().as((str) => str.slice(0, -3))
: militaryTime.bind(),
}), }),
], ],
}), }),
]; ];
}), },
),
}), }),
}); });
}; };

View File

@@ -1137,6 +1137,7 @@ const options = mkOptions(OPTIONS, {
clock: { clock: {
time: { time: {
military: opt(false), military: opt(false),
hideSeconds: opt(false),
}, },
weather: { weather: {
enabled: opt(true), enabled: opt(true),

View File

@@ -14,6 +14,7 @@ export const ClockMenuSettings = (): Scrollable<Child, Attribute> => {
children: [ children: [
Header('Time'), Header('Time'),
Option({ opt: options.menus.clock.time.military, title: 'Use 24hr time', type: 'boolean' }), Option({ opt: options.menus.clock.time.military, title: 'Use 24hr time', type: 'boolean' }),
Option({ opt: options.menus.clock.time.hideSeconds, title: 'Hide seconds', type: 'boolean' }),
Header('Weather'), Header('Weather'),
Option({ opt: options.menus.clock.weather.enabled, title: 'Enabled', type: 'boolean' }), Option({ opt: options.menus.clock.weather.enabled, title: 'Enabled', type: 'boolean' }),