diff options
author | Teddy Wing | 2021-02-04 00:16:36 +0100 |
---|---|---|
committer | Teddy Wing | 2021-02-04 00:22:04 +0100 |
commit | 5beb4694cf112bb0261d0915cf54201109f7ea2d (patch) | |
tree | 91804d14f87ebbdb02baa981fbc08aa26b673cc7 | |
parent | c9f396fffa84f7178b5ee929cfb412485ee256b3 (diff) | |
download | extreload-5beb4694cf112bb0261d0915cf54201109f7ea2d.tar.bz2 |
Make DevTools Protocol call ID auto-incrementing
Remove the hard-coded call IDs and replace them with a class that keeps
track of the current call ID and allows for easy incrementing to get the
next ID.
This should allow us to give multiple extension IDs on the command line
and send messages with properly incrementing call IDs.
Didn't touch the `runtime-evaluate-msg` message call ID because that one
is local to the target it's attached to, so we can keep it at ID "1".
-rw-r--r-- | l/extreload.asd | 1 | ||||
-rw-r--r-- | l/src/call-id.lisp | 12 | ||||
-rw-r--r-- | l/src/main.lisp | 9 |
3 files changed, 20 insertions, 2 deletions
diff --git a/l/extreload.asd b/l/extreload.asd index 551076e..7dffd1c 100644 --- a/l/extreload.asd +++ b/l/extreload.asd @@ -10,6 +10,7 @@ (:file "macro") (:file "config") (:file "option") + (:file "call-id") (:file "devtools-protocol") (:file "main")))) diff --git a/l/src/call-id.lisp b/l/src/call-id.lisp new file mode 100644 index 0000000..bf0bcec --- /dev/null +++ b/l/src/call-id.lisp @@ -0,0 +1,12 @@ +(in-package :extreload) + +(defclass call-id () + ((id + :initform 0 + :documentation "Current call ID."))) + +(defgeneric next-call-id (call-id) + (:documentation "Increment the call ID and return the result.")) + +(defmethod next-call-id ((call-id call-id)) + (incf (slot-value call-id 'id))) diff --git a/l/src/main.lisp b/l/src/main.lisp index 9a0ea79..fbe3357 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -1,6 +1,7 @@ (in-package :extreload) (defvar *wg* (wait-group:make-wait-group)) +(defvar *devtools-root-call-id* (make-instance 'call-id)) (opts:define-opts (:name :socket-url @@ -30,7 +31,8 @@ ; (wsd:on :message *client* #'(lambda (message) (ws-on-message message))) ;; TODO: Maybe defvar *config* and store client in the config - (websocket-send *client* (target-get-targets-msg 1)) + (websocket-send *client* (target-get-targets-msg + (next-call-id *devtools-root-call-id*))) (wait-group:wait *wg*)))) @@ -73,9 +75,12 @@ (defun attach-to-target (extension) (let ((target-id (json-obj-get extension "targetId"))) (websocket-send *client* - (target-attach-to-target-msg 2 target-id)))) + (target-attach-to-target-msg + (next-call-id *devtools-root-call-id*) + target-id)))) (defun reload-extension (session-id) + ;; Use call ID "1" as this is the first message sent to the attached target. (websocket-send *client* (runtime-evaluate-msg 1 session-id "chrome.runtime.reload()"))) |