Skip to content

Commit

Permalink
[REF] Port demo target to Eldev
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyWeeUsr committed Dec 11, 2024
1 parent 3899779 commit aa5744e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
33 changes: 33 additions & 0 deletions Eldev
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,36 @@
(when (< 0 (call-process "git" nil buff nil "tag" tag "--sign"))
(eldev-output (with-current-buffer buff (buffer-string)))
(error "Failed to tag and sign"))))

(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"))
(port (or (getenv "DEMO_PORT") "5000"))
(socket (or (getenv "DEMO_SOCKET") "/run/user/1000/emacs/server"))
(proto "http")
flask-proc demo-proc)

(unless (executable-find flask)
(error "Flask not found"))
(unless (executable-find client)
(error "Emacsclient not found"))

(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))))
56 changes: 28 additions & 28 deletions demo/demo.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
(load (concat default-directory "syncthing.el"))
(defun syncthing-demo (name addr)
(dotimes (_ 30) (sleep-for 0.1))
(setq syncthing-debug t)
(syncthing-with-base name addr "dummy-token")
(setq syncthing-debug nil)
(end-of-buffer)
(save-window-excursion
(beginning-of-buffer)
(let (buf)
(dolist (item (buffer-list))
(when (and (string-match (regexp-quote name) (buffer-name item))
(not buf))
(setq buf item)))
(switch-to-buffer buf)
(while (string= "" (buffer-string))
(sleep-for 0.01))
(syncthing-auto-refresh-mode 0)
(goto-char 0)
(dotimes (_ 8) (next-line))
(dotimes (_ 3)
(syncthing--newline (point))
(previous-line))
(dotimes (_ 3) (previous-line))
(syncthing--newline (point))
(previous-line)
(syncthing--newline (point))
(menu-bar-mode 0)
(toggle-frame-fullscreen)
(text-scale-adjust -1)
(message "Demo layout done"))))
(let ((syncthing-debug t))
(syncthing-with-base name addr "dummy-token")
(setq syncthing-debug nil)
(call-interactively 'end-of-buffer)
(save-window-excursion
(call-interactively 'beginning-of-buffer)
(let (buf)
(dolist (item (buffer-list))
(when (and (string-match (regexp-quote name) (buffer-name item))
(not buf))
(setq buf item)))
(switch-to-buffer buf)
(while (string= "" (buffer-string))
(sleep-for 0.01))
(syncthing-auto-refresh-mode 0)
(goto-char 0)
(dotimes (_ 8) (call-interactively 'next-line))
(dotimes (_ 3)
(execute-kbd-macro (kbd "RET"))
(call-interactively 'previous-line))
(dotimes (_ 3) (call-interactively 'previous-line))
(execute-kbd-macro (kbd "RET"))
(call-interactively 'previous-line)
(execute-kbd-macro (kbd "RET"))
(menu-bar-mode 0)
(toggle-frame-fullscreen)
(text-scale-adjust -1)
(message "Demo layout done")))))

0 comments on commit aa5744e

Please sign in to comment.