Added "relative-timestamps" config to switch between "25 minutes ago" and "2023-06-25T20:05:27-07" (#286)

Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
This commit is contained in:
dev 2023-07-08 03:57:16 -07:00 committed by GitHub
parent 98240489ba
commit 9bac0d09af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 5 deletions

View File

@ -124,16 +124,22 @@ config file to be able to detect config errors
default: true ++
description: Whether the control center should expand vertically to fill the screen
*relative-timestamps* ++
type: bool ++
default: true ++
description: Display notification timestamps relative to now e.g. \"26 minutes ago\". ++
If false, a local iso8601-formatted absolute timestamp is displayed.
*control-center-height* ++
type: integer ++
default: 500 ++
description: The control centers height in pixels.
This setting is ignored when _fit-to-screen_ it set to "true"
description: The control center height in pixels ++
This setting is ignored when _fit-to-screen_ is set to "true".
*control-center-width* ++
type: integer ++
default: 500 ++
description: The control centers width in pixels
description: The control center width in pixels
*notification-visibility* ++
type: object ++

View File

@ -19,6 +19,7 @@
"timeout-low": 5,
"timeout-critical": 0,
"fit-to-screen": true,
"relative-timestamps": true,
"control-center-width": 500,
"control-center-height": 600,
"notification-window-width": 500,

View File

@ -523,6 +523,12 @@ namespace SwayNotificationCenter {
/** Whether to expand the notification center across both edges of the screen */
public bool fit_to_screen { get; set; default = true; }
/**
* Display notification timestamp relative to now e.g. "26 minutes ago".
* If false, a local iso8601-formatted absolute timestamp is displayed.
*/
public bool relative_timestamps { get; set; default = true; }
/**
* Notification center's height, in pixels.
* Set `fit_to_screen` to true to ignore the height setting.

View File

@ -128,6 +128,11 @@
"description": "If the control center should expand to both edges of the screen",
"default": true
},
"relative-timestamps": {
"type": "boolean",
"description": "Display notification timestamps relative to now e.g. \"26 minutes ago\". If false, a local iso8601-formatted absolute timestamp is displayed.",
"default": true
},
"control-center-height": {
"type": "integer",
"description": "Height of the control center in pixels. Ignored when 'fit-to-screen' is set to 'true'",

View File

@ -556,10 +556,14 @@ namespace SwayNotificationCenter {
}
public void set_time () {
this.time.set_text (get_readable_time ());
if (ConfigModel.instance.relative_timestamps) {
this.time.set_text (get_relative_time ());
} else {
this.time.set_text (get_iso8601_time ());
}
}
private string get_readable_time () {
private string get_relative_time () {
string value = "";
double diff = (get_real_time () * 0.000001) - param.time;
@ -590,6 +594,11 @@ namespace SwayNotificationCenter {
return value;
}
private string get_iso8601_time () {
var dtime = new DateTime.from_unix_local (param.time);
return dtime.format_iso8601 ();
}
public void close_notification (bool is_timeout = false) {
remove_noti_timeout ();
this.revealer.set_reveal_child (false);