forked from Shinonome/dots-hyprland
notifications: time is "Now" within 1 minute
This commit is contained in:
@@ -25,6 +25,19 @@ function exists(widget) {
|
|||||||
return widget !== null;
|
return widget !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getFriendlyNotifTimeString = (timeObject) => {
|
||||||
|
const messageTime = GLib.DateTime.new_from_unix_local(timeObject);
|
||||||
|
const oneMinuteAgo = GLib.DateTime.new_now_local().add_seconds(-60);
|
||||||
|
if (messageTime.compare(oneMinuteAgo) > 0)
|
||||||
|
return 'Now';
|
||||||
|
else if (messageTime.get_day_of_year() == GLib.DateTime.new_now_local().get_day_of_year())
|
||||||
|
return messageTime.format(userOptions.time.format);
|
||||||
|
else if (messageTime.get_day_of_year() == GLib.DateTime.new_now_local().get_day_of_year() - 1)
|
||||||
|
return 'Yesterday';
|
||||||
|
else
|
||||||
|
return messageTime.format(userOptions.time.dateFormat);
|
||||||
|
}
|
||||||
|
|
||||||
const NotificationIcon = (notifObject) => {
|
const NotificationIcon = (notifObject) => {
|
||||||
// { appEntry, appIcon, image }, urgency = 'normal'
|
// { appEntry, appIcon, image }, urgency = 'normal'
|
||||||
if (notifObject.image) {
|
if (notifObject.image) {
|
||||||
@@ -218,14 +231,7 @@ export default ({
|
|||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
let notifTime = '';
|
|
||||||
const messageTime = GLib.DateTime.new_from_unix_local(notifObject.time);
|
|
||||||
if (messageTime.get_day_of_year() == GLib.DateTime.new_now_local().get_day_of_year())
|
|
||||||
notifTime = messageTime.format(userOptions.time.format);
|
|
||||||
else if (messageTime.get_day_of_year() == GLib.DateTime.new_now_local().get_day_of_year() - 1)
|
|
||||||
notifTime = 'Yesterday';
|
|
||||||
else
|
|
||||||
notifTime = messageTime.format(userOptions.time.dateFormat);
|
|
||||||
const notifTextSummary = Label({
|
const notifTextSummary = Label({
|
||||||
xalign: 0,
|
xalign: 0,
|
||||||
className: 'txt-small txt-semibold titlefont',
|
className: 'txt-small txt-semibold titlefont',
|
||||||
@@ -237,11 +243,15 @@ export default ({
|
|||||||
useMarkup: notifObject.summary.startsWith('<'),
|
useMarkup: notifObject.summary.startsWith('<'),
|
||||||
label: notifObject.summary,
|
label: notifObject.summary,
|
||||||
});
|
});
|
||||||
|
const initTimeString = getFriendlyNotifTimeString(notifObject.time);
|
||||||
const notifTextBody = Label({
|
const notifTextBody = Label({
|
||||||
vpack: 'center',
|
vpack: 'center',
|
||||||
justification: 'right',
|
justification: 'right',
|
||||||
className: 'txt-smaller txt-semibold',
|
className: 'txt-smaller txt-semibold',
|
||||||
label: notifTime,
|
label: initTimeString,
|
||||||
|
setup: initTimeString == 'Now' ? (self) => {
|
||||||
|
Utils.timeout(60000, () => self.label = getFriendlyNotifTimeString(notifObject.time))
|
||||||
|
} : () => {},
|
||||||
});
|
});
|
||||||
const notifText = Box({
|
const notifText = Box({
|
||||||
valign: Gtk.Align.CENTER,
|
valign: Gtk.Align.CENTER,
|
||||||
|
|||||||
Reference in New Issue
Block a user