Factor out the title and category queries to separate functions

This commit is contained in:
Gergely Polonkai 2021-03-11 17:47:35 +01:00
parent bc61218f92
commit eb03af79d9
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -64,6 +64,14 @@
'emacs-mule)
"Coding system of the file `org-clock-waybar-filename'.")
(defsubst org-clock-waybar--get-task-title (task)
"Get the title of TASK."
(when task (substring-no-properties task)))
(defsubst org-clock-waybar--get-task-category (task)
"Get the category of TASK."
(when task (get-text-property 0 'org-category task)))
(defun org-clock-waybar-tooltip ()
"The default tooltip to send to waybar."
(when org-clock-current-task
@ -84,18 +92,16 @@ If CLOCKING-OUT is non-nil, `org-clock-current-task' will be treated as if it
were nil; this is required because `org-clock-out' calls the hook functions
before setting `org-clock-current-task' to nil."
(let* ((task (if clocking-out nil org-clock-current-task))
(category (when task (get-text-property 0 'org-category task)))
(title (when task (substring-no-properties task)))
(category (org-clock-waybar--get-task-title task))
(title (org-clock-waybar--get-task-category task))
(tooltip (org-clock-waybar-tooltip))
(output (json-new-object)))
(setq output (json-add-to-object
output
"text"
(if title
title
org-clock-waybar-not-clocked-in-text)))
(setq output (json-add-to-object output "alt" (if category category "")))
(setq output (json-add-to-object output "tooltip" (if tooltip tooltip "")))
(or title org-clock-waybar-not-clocked-in-text)))
(setq output (json-add-to-object output "alt" (or category "")))
(setq output (json-add-to-object output "tooltip" (or tooltip "")))
(setq output (json-add-to-object output "class" ""))
(setq output (json-add-to-object output "percentage" ""))
(json-encode output)))