diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 3e64218..ee24348 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -72,20 +72,6 @@ (error (e) (notify-request-error e)))) -(defmacro with-enqueue-request ((method-name id &rest args) &body on-error) - `(ev:with-enqueued-process-and-unblock () - (handler-case - (comm:make-request ,method-name ,id ,@args) - (error (the-error) ; anaphora - (declare (ignorable the-error)) - ,@on-error)))) - -(defun enqueue-request-and-wait-results (method-name id priority &rest args) - (ev:push-function-and-wait-results (lambda () (apply #'comm:make-request method-name id args)) - :push-event-fn #'ev:push-event-unblock - :priority priority)) - - (defun slurp-gemini-stream (iri &key (use-cache t) (process-function #'identity) diff --git a/src/gui/client/menu-command.lisp b/src/gui/client/menu-command.lisp index 9a6664a..be34e19 100644 --- a/src/gui/client/menu-command.lisp +++ b/src/gui/client/menu-command.lisp @@ -13,6 +13,6 @@ (gui:pack editor :fill :both))))) (defun quit () - (comm:close-server) + (gui:break-mainloop) (client-events:stop-events-loop) - (gui:break-mainloop)) + (comm:close-server)) diff --git a/src/gui/client/program-events.lisp b/src/gui/client/program-events.lisp index c0728f1..02a1c73 100644 --- a/src/gui/client/program-events.lisp +++ b/src/gui/client/program-events.lisp @@ -4,18 +4,41 @@ (defparameter *events-loop-lock* (bt:make-lock "events-loop-lock")) +(defparameter *events-loop-thread* nil) + (defun events-loop-running-p () (misc:with-lock (*events-loop-lock*) (not *stop-events-loop*))) (defun stop-events-loop () (misc:with-lock (*events-loop-lock*) - (setf *stop-events-loop* t))) + (setf *stop-events-loop* t)) + #+debug-mode (misc:dbg "Stopping gui event thread") + (ev:with-enqueued-process-and-unblock () + #+debug-mode (misc:dbg "Stopping dummy event")) + #+debug-mode (misc:dbg "Stopped gui event thread")) (defun start-events-loop () (misc:with-lock (*events-loop-lock*) (setf *stop-events-loop* nil)) - (bt:make-thread (lambda () - (loop while (events-loop-running-p) do - (when (not (ev:stop-event-dispatching-p)) - (ev:dispatch-program-events-or-wait)))))) + (setf *events-loop-thread* + (bt:make-thread (lambda () + (loop while (events-loop-running-p) do + (misc:dbg "event loop!") + (ev:dispatch-program-events-or-wait) + (misc:dbg "dipacth event loop! ~a run + ~a " *stop-events-loop* (events-loop-running-p))) + (misc:dbg "event loop fine! ~a" *stop-events-loop*))))) + +(defmacro with-enqueue-request ((method-name id &rest args) &body on-error) + `(ev:with-enqueued-process-and-unblock () + (handler-case + (comm:make-request ,method-name ,id ,@args) + (error (the-error) ; anaphora + (declare (ignorable the-error)) + ,@on-error)))) + +(defun enqueue-request-and-wait-results (method-name id priority &rest args) + (ev:push-function-and-wait-results (lambda () (apply #'comm:make-request method-name id args)) + :push-event-fn #'ev:push-event-unblock + :priority priority)) diff --git a/src/package.lisp b/src/package.lisp index 97af4fe..967e8b8 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -3253,9 +3253,10 @@ :constants :text-utils :misc-utils) - (:local-nicknames (:re :cl-ppcre) - (:a :alexandria) - (:ev :program-events)) + (:local-nicknames (:comm :json-rpc-communication) + (:re :cl-ppcre) + (:a :alexandria) + (:ev :program-events)) (:export :events-loop-running-p :stop-events-loop @@ -3267,11 +3268,11 @@ :constants :misc :text-utils) - (:local-nicknames (:comm :json-rpc-communication) - (:re :cl-ppcre) - (:a :alexandria) - (:gui :nodgui) - (:gui-utils :nodgui.utils)) + (:local-nicknames (:comm :json-rpc-communication) + (:re :cl-ppcre) + (:a :alexandria) + (:gui :nodgui) + (:gui-utils :nodgui.utils)) (:export :+icon-dir+ :load-icons @@ -3287,11 +3288,11 @@ :cl :config :constants) - (:local-nicknames (:comm :json-rpc-communication) - (:re :cl-ppcre) - (:a :alexandria) - (:gui :nodgui) - (:gui-utils :nodgui.utils)) + (:local-nicknames (:comm :json-rpc-communication) + (:re :cl-ppcre) + (:a :alexandria) + (:gui :nodgui) + (:gui-utils :nodgui.utils)) (:export :validator :regexp-validator @@ -3333,6 +3334,7 @@ :text-utils :misc-utils) (:local-nicknames (:comm :json-rpc-communication) + (:ev :program-events) (:re :cl-ppcre) (:a :alexandria) (:gui :nodgui)