Notifications for the server stopping and starting

This commit is contained in:
Jakub 2026-05-09 12:58:47 +08:00
parent 9168cecfd4
commit 65887da8da

View file

@ -18,7 +18,7 @@
;;; Commentary: ;;; Commentary:
;; Depends on websocket and request. ;; Depends on websocket, request, and notifications.
;;; Code: ;;; Code:
@ -34,7 +34,11 @@
(defvar gomuks-socket-buffer "*gomuks-socket-frame*") (defvar gomuks-socket-buffer "*gomuks-socket-frame*")
(defvar gomuks-server-name "*gomuks-server*") (defvar gomuks-server-name "*gomuks-server*")
(defcustom gomuks-server-binary "~/Downloads/gomuks" (defvar gomuks-auth-cookie nil)
(defvar gomuks-websocket nil)
(defvar gomuks-ping-timer nil)
(defcustom gomuks-server-binary "~/tmp/gomuks"
"The Gomuks backend binary." "The Gomuks backend binary."
:type 'string :type 'string
:group 'gomuks) :group 'gomuks)
@ -42,12 +46,16 @@
(defun gomuks-server-start () (defun gomuks-server-start ()
"Start the gomuks server process" "Start the gomuks server process"
(interactive) (interactive)
(start-process gomuks-server-name (get-buffer-create gomuks-server-buffer) gomuks-server-bin)) (start-process gomuks-server-name (get-buffer-create gomuks-server-buffer) gomuks-server-binary)
(notifications-notify :title "Gomuks Server Running" :app-name "gomuks.el"))
(defun gomuks-server-kill () (defun gomuks-server-kill ()
"Kill the gomuks server process" "Kill the gomuks server process"
(interactive) (interactive)
(kill-process gomuks-server-name)) (when (websocket-openp gomuks-websocket)
(gomuks-disconnect))
(kill-process gomuks-server-name)
(notifications-notify :title "Gomuks Server Closed" :app-name "gomuks.el"))
(defvar gomuks-url "http://localhost:29325") (defvar gomuks-url "http://localhost:29325")
(defvar gomuks-auth-endpoint (concat gomuks-url "/_gomuks/auth")) (defvar gomuks-auth-endpoint (concat gomuks-url "/_gomuks/auth"))
@ -55,13 +63,10 @@
(defvar gomuks-ws-endpoint (concat gomuks-url "/_gomuks/websocket")) (defvar gomuks-ws-endpoint (concat gomuks-url "/_gomuks/websocket"))
(defvar gomuks-auth-cookie nil)
(defvar gomuks-websocket nil)
(defvar gomuks-ping-timer nil)
(defun gomuks-connect (gomuks-username) (defun gomuks-connect (gomuks-username)
"Opens a websocket connection with the specified gomuks endpoint" "Opens a websocket connection with the specified gomuks endpoint"
(interactive "sGomuks Username: \n") (interactive "sGomuks Username: \n")
(let ((gomuks-password (read-passwd "Gomuks Password:"))) (let ((gomuks-password (read-passwd "Gomuks Password: ")))
(setq gomuks-auth-cookie (let ((request--curl-cookie-jar (expand-file-name (make-temp-name "gomuks-cookie-") (setq gomuks-auth-cookie (let ((request--curl-cookie-jar (expand-file-name (make-temp-name "gomuks-cookie-")
temporary-file-directory))) temporary-file-directory)))
(request gomuks-auth-endpoint (request gomuks-auth-endpoint