Factor out the JSON string generation

This commit is contained in:
Gergely Polonkai 2021-03-11 06:53:21 +01:00
parent 5d97d022c7
commit bf9c74666d
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -64,8 +64,8 @@
'emacs-mule)
"Coding system of the file `org-clock-waybar-filename'.")
(defun org-clock-waybar--get-clocked-task-json (buffer)
"Save the currently clocked-in tasks data to BUFFER.
(defun org-clock-waybar--get-clocked-task-json ()
"Get the currently clocked-in tasks data as a stringified JSON object.
The output is in JSON format constructed in a way so Waybar can process it.
If there is no clocked in task, alt becomes empty and text will be set to the
@ -75,7 +75,6 @@ value of `org-clock-waybar-not-clocked-in-text'."
(title (when org-clock-current-task
(substring-no-properties org-clock-current-task)))
(output (json-new-object)))
(with-current-buffer buffer
(setq output (json-add-to-object
output
"text"
@ -86,14 +85,14 @@ value of `org-clock-waybar-not-clocked-in-text'."
(setq output (json-add-to-object output "tooltip" ""))
(setq output (json-add-to-object output "class" ""))
(setq output (json-add-to-object output "percentage" ""))
(insert (json-encode output)))))
(json-encode output)))
(defun org-clock-waybar-save-task ()
"Save the current clocked in task to `org-clock-waybar-filename'."
(with-temp-buffer
(erase-buffer)
(set-buffer-file-coding-system org-clock-waybar-filename-coding-system)
(org-clock-waybar--get-clocked-task-json (current-buffer))
(insert (org-clock-waybar--get-clocked-task-json))
(write-file org-clock-waybar-filename)))
(defun org-clock-waybar-setup ()