branch: externals/dtache commit 5d9c8aa54f1e9129745037107c18b03f484183e5 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Add macOS support Previously it was not possible to create a monitor for a session on a macOS host. The users previously had to resort to a hack mentioned in the README. This patch adds special handling for monitors on macOS and the users don't need to configure that themselves anymore. --- CHANELOG.org | 2 ++ README.org | 16 ---------------- dtache.el | 45 +++++++++++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/CHANELOG.org b/CHANELOG.org index e3a1370758..128aadf69f 100644 --- a/CHANELOG.org +++ b/CHANELOG.org @@ -4,6 +4,8 @@ * Development +- macOS (monitor) support is added to the package. + * Version 0.2 (2021-12-23) - With the recent improvements to =dtache-open-session=, the package is ready to harmonize the user interface. This means deprecating =dtache-list-sessions=. diff --git a/README.org b/README.org index 658db79ad6..edc4bd5872 100644 --- a/README.org +++ b/README.org @@ -202,22 +202,6 @@ Some programs doesn't play well with =tee=, which =dtache= relies upon to redire Here a command beginning with =ls= would from now on be using redirect only. * Tips & Tricks -** macOS support - -=Dtache= depends on =filenotify= to trigger events when a =dtach socket= is deleted, which defines the transition from active to inactive for a dtache session. Currently this implementation causes issues for macOS users, it should work, but until the root cause has been identified this provides a workaround solution. - -#+begin_src elisp :lexical t :results none - (defun my/dtache--add-end-of-session-notification-advice (session) - "Trigger an event when SESSION transition to inactive." - (let ((dtache-timer-configuration - '(:seconds 0.5 :repeat 0.5 :function run-with-idle-timer))) - (dtache--session-timer session))) - - (advice-add 'dtache--add-end-of-session-notification :override #'my/dtache--add-end-of-session-notification-advice) -#+end_src - -We replace the notification function with one based on a timer instead. This timer will periodically check if a session has gotten deactivated. - ** System notifications By default =dtache= uses the echo area to notify the user when a session has finished. An alternative is to utilize the [[https://github.com/jwiegley/alert][alert]] package to get a system notification instead. diff --git a/dtache.el b/dtache.el index c5bb0635da..76ab90404a 100644 --- a/dtache.el +++ b/dtache.el @@ -468,10 +468,10 @@ Sessions running on current host or localhost are updated." (dtache-update-session session)))) (dtache--db-get-sessions)) - ;; Setup notifications + ;; Start monitors (thread-last (dtache--db-get-sessions) (seq-filter #'dtache--session-active) - (seq-do #'dtache-setup-notification)))) + (seq-do #'dtache-start-session-monitor)))) (defun dtache-cleanup-host-sessions (host) "Run cleanuup on HOST sessions." @@ -548,11 +548,13 @@ Sessions running on current host or localhost are updated." (cand (completing-read "Select session: " collection nil t))) (cdr (assoc cand candidates)))) -(defun dtache-setup-notification (session) - "Setup notification for SESSION." +(defun dtache-start-session-monitor (session) + "Start to monitor SESSION activity." (if (file-remote-p (dtache--session-working-directory session)) - (dtache--session-timer session) - (dtache--add-end-of-session-notification session))) + (dtache--session-timer-monitor session) + (if (eq system-type 'darwin) + (dtache--session-macos-monitor session) + (dtache--session-filenotify-monitor session)))) (defun dtache-dtach-command (session) "Return a dtach command for SESSION." @@ -697,8 +699,9 @@ Sessions running on current host or localhost are updated." "") "\n")) -(defun dtache--session-timer (session) - "Create a timmer for SESSION according to `dtache-timer-configuration'." +(defun dtache--session-timer-monitor (session) + "Configure a timer to monitor SESSION activity. + The timer object is configured according to `dtache-timer-configuration'." (let* ((timer) (callback (lambda () @@ -711,6 +714,22 @@ Sessions running on current host or localhost are updated." (plist-get dtache-timer-configuration :repeat) callback)))) +(defun dtache--session-filenotify-monitor (session) + "Configure `filenotify' to monitor SESSION activity." + (file-notify-add-watch + (dtache-session-file session 'socket) + '(change) + (lambda (event) + (pcase-let ((`(,_ ,action ,_) event)) + (when (eq action 'deleted) + (dtache--session-final-update session)))))) + +(defun dtache--session-macos-monitor (session) + "Configure a timer to monitor SESSION activity on macOS." + (let ((dtache-timer-configuration + '(:seconds 0.5 :repeat 0.5 :function run-with-idle-timer))) + (dtache--session-timer-monitor session))) + ;;;;; Database (defun dtache--db-initialize () @@ -764,16 +783,6 @@ Sessions running on current host or localhost are updated." ('attach "-a") (_ "-n"))) -(defun dtache--add-end-of-session-notification (session) - "Trigger an event when SESSION is stopped." - (file-notify-add-watch - (dtache-session-file session 'socket) - '(change) - (lambda (event) - (pcase-let ((`(,_ ,action ,_) event)) - (when (eq action 'deleted) - (dtache--session-final-update session)))))) - (defun dtache--session-final-update (session) "Make a final update to SESSION." (if (dtache--session-missing-p session)