aboutsummaryrefslogtreecommitdiffstats
path: root/l/src/main.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'l/src/main.lisp')
-rw-r--r--l/src/main.lisp22
1 files changed, 19 insertions, 3 deletions
diff --git a/l/src/main.lisp b/l/src/main.lisp
index 8665412..5e44158 100644
--- a/l/src/main.lisp
+++ b/l/src/main.lisp
@@ -1,10 +1,13 @@
(in-package :extreload)
(defvar *wg* (wait-group:make-wait-group))
-(defvar *devtools-root-call-id* (make-instance 'call-id))
-(defvar *devtools-secondary-call-id* (make-instance 'call-id))
+(defvar *devtools-root-call-id* (make-instance 'call-id)
+ "DevTools Protocol call ID.")
+(defvar *devtools-secondary-call-id* (make-instance 'call-id)
+ "DevTools Protocol call ID used for messages to individual target sessions.")
-(defconstant +timeout-seconds+ 5)
+(defconstant +timeout-seconds+ 5
+ "Global timeout. The program will exit at the end of this delay.")
(defun main ()
(handler-bind ((error #'(lambda (e)
@@ -30,6 +33,7 @@
(wait-group:wait *wg*)))))
(defun ws-on-message (message extension-ids config)
+ "Called when a WebSocket message is received."
(let* ((response (jsown:parse message))
(targets (parse-get-targets-response response)))
(when (debug-output config)
@@ -64,6 +68,8 @@
(wait-group:done *wg*)))
(defun json-obj-get (obj key)
+ "Get the value of `key` from `obj` (a `jsown` object). Return nil if `key` is
+not defined."
(handler-case
(jsown:val obj key)
(simple-error (e)
@@ -72,6 +78,8 @@
nil)))))
(defun attach-extensions (targets extension-ids)
+ "Attach to all extensions in `targets` that match the IDs in
+`extension-ids`."
(labels ((requested-extension-p (target)
(find-if
#'(lambda (id)
@@ -84,6 +92,7 @@
(attach-to-target extension))))
(defun attach-to-target (extension)
+ "Send a message to the target in `extension` asking to attach to the target."
(let ((target-id (json-obj-get extension "targetId")))
(websocket-send (ws-client *config*)
(target-attach-to-target-msg
@@ -91,6 +100,8 @@
target-id))))
(defun reload-extension (session-id)
+ "Send a message to an extension page corresponding to `session-id`, telling
+the target extension to reload itself."
(websocket-send
(ws-client *config*)
(runtime-evaluate-msg
@@ -99,6 +110,9 @@
"chrome.runtime.reload()")))
(defun reload-tab (session-id)
+ "Send a message to an extension page corresponding to `session-id`, telling
+the target to reload the current tab."
+
;; Two response messages always come back from the `chrome.tabs.reload()`
;; messages, so we need to add a second increment to the wait group.
(wait-group:add *wg*)
@@ -111,6 +125,7 @@
"chrome.tabs.reload()")))
(defun extension-targets (targets)
+ "Filter `targets`, returning a list of targets corresponding to extensions."
(labels ((extensionp (target)
(string= (json-obj-get target "type")
"background_page")))
@@ -118,6 +133,7 @@
(filter #'extensionp targets)))
(defun websocket-send (client data)
+ "Send `data` to WebSocket `client` and increment `*wg*`."
(when (debug-output *config*)
(format t "Sending: ~a~%" data))