Factor out the JSON string generation
This commit is contained in:
parent
5d97d022c7
commit
bf9c74666d
@ -64,8 +64,8 @@
|
|||||||
'emacs-mule)
|
'emacs-mule)
|
||||||
"Coding system of the file `org-clock-waybar-filename'.")
|
"Coding system of the file `org-clock-waybar-filename'.")
|
||||||
|
|
||||||
(defun org-clock-waybar--get-clocked-task-json (buffer)
|
(defun org-clock-waybar--get-clocked-task-json ()
|
||||||
"Save the currently clocked-in task’s data to BUFFER.
|
"Get the currently clocked-in task’s data as a stringified JSON object.
|
||||||
|
|
||||||
The output is in JSON format constructed in a way so Waybar can process it.
|
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
|
If there is no clocked in task, alt becomes empty and text will be set to the
|
||||||
@ -75,25 +75,24 @@ value of `org-clock-waybar-not-clocked-in-text'."
|
|||||||
(title (when org-clock-current-task
|
(title (when org-clock-current-task
|
||||||
(substring-no-properties org-clock-current-task)))
|
(substring-no-properties org-clock-current-task)))
|
||||||
(output (json-new-object)))
|
(output (json-new-object)))
|
||||||
(with-current-buffer buffer
|
(setq output (json-add-to-object
|
||||||
(setq output (json-add-to-object
|
output
|
||||||
output
|
"text"
|
||||||
"text"
|
(if title
|
||||||
(if title
|
title
|
||||||
title
|
org-clock-waybar-not-clocked-in-text)))
|
||||||
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 "alt" (if category category "")))
|
(setq output (json-add-to-object output "tooltip" ""))
|
||||||
(setq output (json-add-to-object output "tooltip" ""))
|
(setq output (json-add-to-object output "class" ""))
|
||||||
(setq output (json-add-to-object output "class" ""))
|
(setq output (json-add-to-object output "percentage" ""))
|
||||||
(setq output (json-add-to-object output "percentage" ""))
|
(json-encode output)))
|
||||||
(insert (json-encode output)))))
|
|
||||||
|
|
||||||
(defun org-clock-waybar-save-task ()
|
(defun org-clock-waybar-save-task ()
|
||||||
"Save the current clocked in task to `org-clock-waybar-filename'."
|
"Save the current clocked in task to `org-clock-waybar-filename'."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(set-buffer-file-coding-system org-clock-waybar-filename-coding-system)
|
(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)))
|
(write-file org-clock-waybar-filename)))
|
||||||
|
|
||||||
(defun org-clock-waybar-setup ()
|
(defun org-clock-waybar-setup ()
|
||||||
|
Loading…
Reference in New Issue
Block a user