diff --git a/Eldev b/Eldev index 54c2f6e..96f758f 100644 --- a/Eldev +++ b/Eldev @@ -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)))) diff --git a/demo/demo.el b/demo/demo.el index 521548e..e8a1d99 100644 --- a/demo/demo.el +++ b/demo/demo.el @@ -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")))))