diff options
Diffstat (limited to 'l/src')
| -rw-r--r-- | l/src/config.lisp | 33 | ||||
| -rw-r--r-- | l/src/main.lisp | 2 | ||||
| -rw-r--r-- | l/src/option.lisp | 5 | 
3 files changed, 33 insertions, 7 deletions
| diff --git a/l/src/config.lisp b/l/src/config.lisp index 6b31dac..eb8bede 100644 --- a/l/src/config.lisp +++ b/l/src/config.lisp @@ -13,10 +13,35 @@       :initarg :reload-current-tab       :initform nil       :reader reload-current-tab -     :documentation "True if the current tab should be reloaded"))) +     :documentation "True if the current tab should be reloaded") + +   (ws-client +     :documentation "WebSocket client")))  (defmethod print-object ((object config) stream)    (print-unreadable-object (object stream :type t) -    (with-slots (socket-url extension-ids reload-current-tab) object -      (format stream ":socket-url ~s :extension-ids ~s :reload-current-tab ~s" -              socket-url extension-ids reload-current-tab)))) +    (with-slots (socket-url extension-ids reload-current-tab ws-client) object +      (format stream +              ":socket-url ~s :extension-ids ~s :reload-current-tab ~s :ws-client ~s" +              socket-url extension-ids reload-current-tab ws-client)))) + +;; TODO: (make-config) instead, initialise ws-client in initialiser +(defgeneric (setf socket-url) (url config)) + +(defmethod (setf socket-url) (url (config config)) +  "Set `socket-url` and initialise a new `websocket-driver:client` in the +`ws-client` slot" +  (setf (slot-value config 'socket-url) url) + +  (setf (slot-value config 'ws-client) (wsd:make-client url))) + +(defun make-config (&key socket-url extension-ids reload-current-tab) +  (let ((config (make-instance 'config +                               :socket-url socket-url +                               :extension-ids extension-ids +                               :reload-current-tab reload-current-tab))) + +    ;; Initialise a new websocket-driver client +    (setf (slot-value config 'ws-client) (wsd:make-client socket-url)) + +    config)) diff --git a/l/src/main.lisp b/l/src/main.lisp index afa79d8..a84e0cd 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -26,6 +26,8 @@      ;; 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      (websocket-send *client* (target-get-targets-msg 1)) diff --git a/l/src/option.lisp b/l/src/option.lisp index 22e6052..2c3f0d0 100644 --- a/l/src/option.lisp +++ b/l/src/option.lisp @@ -37,6 +37,5 @@          (opts:exit 64)) -    (make-instance 'config -                   :socket-url (getf options :socket-url) -                   :extension-ids free-args))) +    (make-config :socket-url (getf options :socket-url) +                 :extension-ids free-args))) | 
