summaryrefslogtreecommitdiff
path: root/org-roam-ui.el
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-07-29 13:50:17 +0200
committerThomas F. K. Jorna <[email protected]>2021-07-29 13:50:17 +0200
commit1af5088eccd00fa16bdf930a356893c99c7411fe (patch)
treea0e40a8f89c129c9c3b90a7f076e3a9935715d11 /org-roam-ui.el
parent1541dde979d201860f7f43e369f050d4ece00574 (diff)
made websocket automatically reconnect
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r--org-roam-ui.el22
1 files changed, 15 insertions, 7 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el
index f9eb8dc..fe8881c 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -86,6 +86,8 @@ E.g. '((bg . '#1E2029')
:type 'list)
(defvar org-roam-ui--ws-current-node nil)
+(defvar oru-ws nil
+ "The websocket for org-roam-ui.")
;;;###autoload
(define-minor-mode
@@ -105,13 +107,18 @@ This serves the web-build and API over HTTP."
(websocket-server
35903
:host 'local
- :on-open (lambda (ws) (progn (setq oru-ws ws) (org-roam-ui--send-graphdata) (org-roam-ui-sync-theme--advice) (message "Connection established with org-roam-ui")
- (add-hook 'post-command-hook #'org-roam-ui--update-current-node)
+ :on-open (lambda (ws) (progn (setq oru-ws
+ ws) (org-roam-ui--send-graphdata) (org-roam-ui-sync-theme--advice) (message "Connection
+ established with org-roam-ui")
+ (add-hook 'post-command-hook
+ #'org-roam-ui--update-current-node)
))
- :on-close (lambda (_websocket) (setq oru-ws nil) (message "Connection with org-roam-ui closed succesfully."))))
+ :on-close (lambda (_websocket) (setq oru-ws
+ nil) (message "Connection with org-roam-ui closed
+ succesfully."))))
(if (boundp 'counsel-load-theme)
-(advice-add 'counsel-load-theme :after #'org-roam-ui-sync-theme--advice)
- (advice-add 'load-theme :after #'org-roam-ui-sync-theme-manually))
+(advice-add 'counsel-load-theme :around #'org-roam-ui-sync-theme--advice)
+ (advice-add 'load-theme :around #'org-roam-ui-sync-theme--advice))
(add-hook 'post-command-hook #'org-roam-ui--update-current-node))
;(add-hook 'post-command-hook #'org-roam-ui-update))
(t
@@ -137,12 +144,12 @@ This serves the web-build and API over HTTP."
(websocket-send-text oru-ws (json-encode `((type . "graphdata") (data . ,response))))))
(defun org-roam-ui--update-current-node ()
- (when (websocket-openp oru-ws)
+ (when (and (boundp 'org-roam-ui-websocket) (websocket-openp org-roam-ui-websocket))
(let* ((node (org-roam-id-at-point)))
(unless (string-match-p (regexp-quote "Minibuf") (buffer-name (current-buffer)))
(unless (string= org-roam-ui--ws-current-node node)
(setq org-roam-ui--ws-current-node node)
- (websocket-send-text oru-ws (json-encode `((type . "command") (data . ((commandName . "follow") (id . ,node))))))))))
+ (websocket-send-text org-roam-ui-websocket (json-encode `((type . "command") (data . ((commandName . "follow") (id . ,node))))))))))
)
(defun org-roam-ui-show-node ()
@@ -152,6 +159,7 @@ This serves the web-build and API over HTTP."
(defun org-roam-ui-sync-theme--advice ()
"Function which is called after load-theme to sync your current theme with org-roam-ui."
+ (message "Syncing theme")
(websocket-send-text oru-ws (json-encode `((type . "theme") (data . ,(org-roam-ui--update-theme))))))
(defun org-roam-ui-sync-theme-manually ()