From 074b4375a54e4bbf4539d37b1418eacb2a70f87a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 3 Feb 2021 20:21:03 +0100 Subject: main: Get WebSocket URL from command line for `*client*` Keep the `*client*` global variable, but use the client in `config`, constructed from the WebSocket URL passed from the command line. Not a huge fan of the global variable, but it's way easier to keep it like this rather than passing the client down to the `attach-to-target` and `reload-extension` functions. --- l/src/config.lisp | 1 + l/src/main.lisp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'l/src') diff --git a/l/src/config.lisp b/l/src/config.lisp index eb8bede..4e3cbbf 100644 --- a/l/src/config.lisp +++ b/l/src/config.lisp @@ -16,6 +16,7 @@ :documentation "True if the current tab should be reloaded") (ws-client + :reader ws-client :documentation "WebSocket client"))) (defmethod print-object ((object config) stream) diff --git a/l/src/main.lisp b/l/src/main.lisp index a84e0cd..caadfe3 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -1,7 +1,5 @@ (in-package :extreload) -(defvar *client* (wsd:make-client "ws://127.0.0.1:55755/devtools/browser/20c6f8a1-6540-4226-a876-44b72c176ad5")) - (defvar *wg* (wait-group:make-wait-group)) (opts:define-opts @@ -21,17 +19,18 @@ (defun main () (let ((config (parse-options))) - (format t "~a~%" config)) + ;; Store the WebSocket client as a global. + (defvar *client* (ws-client config)) ;; TODO: error if no `socket-url` - (with-websocket-connection (*client*) - (wsd:on :message *client* #'ws-on-message) - ; (wsd:on :message *client* #'(lambda (message) (ws-on-message message))) - ;; TODO: Maybe defvar *config* and store client in the config + (with-websocket-connection (*client*) + (wsd:on :message *client* #'ws-on-message) + ; (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 1)) - (wait-group:wait *wg*))) + (wait-group:wait *wg*)))) (defun ws-on-message (message) (let* ((response (jsown:parse message)) -- cgit v1.2.3