Skip to content

Commit

Permalink
[FIX] Running demo w/ Eldev command
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyWeeUsr committed Dec 17, 2024
1 parent 2228fb0 commit f5b9731
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
52 changes: 26 additions & 26 deletions Eldev
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@
(eldev-output (with-current-buffer buff (buffer-string)))
(error "Failed to tag and sign"))))

(defsubst eval-in-client (name script)
(unless (consp script)
(user-error "Invalid script: %s" script))

(let ((client (or (getenv "EMACSCLIENT") "emacsclient"))
(sock (or (getenv "EMACS_SOCKET_NAME") "/run/user/1000/emacs/server")))
(unless (executable-find client)
(error "Emacsclient not found"))

(start-process name nil client "--socket-name" sock "--eval"
(format "%S" script))))

(eldev-defcommand demo ()
"Run demo"
(let* ((client (or (getenv "EMACSCLIENT") "emacsclient"))
(flask (or (getenv "FLASK") "flask"))
(host (or (getenv "DEMO_HOST") "127.0.0.1"))
(let* ((host (or (getenv "DEMO_HOST") "127.0.0.1"))
(port (or (getenv "DEMO_PORT") "5000"))
(socket (or (getenv "DEMO_SOCKET") "/run/user/1000/emacs/server"))
(proto "http")
flask-proc demo-proc)
(demo-addr (format "%s://%s:%s" proto host port))
(data-dir (or (getenv "DEMO_DATA") default-directory))
(server-name "syncthing-demo-server"))

(unless (executable-find flask)
(error "Flask not found"))
(unless (executable-find client)
(error "Emacsclient not found"))
(eval-in-client "syncthing-demo"
`(progn (load-file "demo/demo.el")
(syncthing-demo "Demo" ,demo-addr)))

(setq demo-proc
(start-process
"syncthing-demo" nil client "--socket-name" socket "--eval"
(format
"(progn (load \"demo/demo.el\") (syncthing-demo \"Demo\" \"%s\"))"
(format "%s://%s:%s" proto host port))))
(setq flask-proc
(start-process
"syncthing-demo-server" nil flask "--app" "demo/demo.py"
"run" "--reload" "--host" host "--port" port))
(set-process-filter flask-proc (lambda (_ str) (message str)))

;; For some weird reason (call-process) with SIGINT to eldev command keeps
;; the server running even though various approaches to signal handling
;; have been tried from (global-set-key [signal X]), through kill-emacs*
;; hooks, (condition-case), (unwind-protect)... it simply doesn't care...
(while t (sleep-for 1))))
(let ((process-environment
(append process-environment
`(,(format "DEMO_HOST=%s" host)
,(format "DEMO_PORT=%s" port)
,(format "DEMO_DATA=%s" data-dir)))))
(load-file "demo/demo-server.el"))
(while t (sit-for 1))))
4 changes: 2 additions & 2 deletions demo/demo-server.el
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(defun demo-server-load-handlers ()
(let ((data (or (getenv "DEMO_DATA")
(file-name-concat default-directory "testdata")))
(format "%s/%s" default-directory "testdata")))
handlers)
(dolist (item (directory-files data))
(when (string-suffix-p ".json" item)
(with-temp-buffer
(insert-file-contents (file-name-concat data item))
(insert-file-contents (format "%s/%s" data item))
(let ((tmp (buffer-substring-no-properties
(line-beginning-position) (1+ (line-end-position)))))
(delete-region (line-beginning-position) (1+ (line-end-position)))
Expand Down

0 comments on commit f5b9731

Please sign in to comment.