emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/hyperdrive 4742b430fa 07/19: Fix: Killing monitor buffer


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive 4742b430fa 07/19: Fix: Killing monitor buffer
Date: Thu, 1 Aug 2024 01:00:11 -0400 (EDT)

branch: elpa/hyperdrive
commit 4742b430fa87b2891d23c03cf05a5dbfbdeee0d9
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Fix: Killing monitor buffer
---
 hyperdrive-download-monitor.el | 50 +++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/hyperdrive-download-monitor.el b/hyperdrive-download-monitor.el
index 71cedf3941..f00f4b461e 100644
--- a/hyperdrive-download-monitor.el
+++ b/hyperdrive-download-monitor.el
@@ -39,11 +39,13 @@
 (cl-defun h/download-monitor
     (&key buffer-name path total-size setup-fn canceled-fn
           (update-interval 1) (completed-fn
-                               (lambda ()
-                                 (let ((buffer (current-buffer)))
-                                   (quit-window)
+                               (lambda (buffer)
+                                 (let ((buffer-window (get-buffer-window 
buffer)))
+                                   (when buffer-window
+                                     (quit-window nil buffer-window))
                                    (kill-buffer buffer)))))
-  "Return buffer that monitors the download to PATH."
+  "Return buffer that monitors the download to PATH.
+COMPLETED-FN is called with the monitor buffer as its argument."
   (let* ((buffer (generate-new-buffer buffer-name)))
     (with-current-buffer buffer
       (setf (map-elt h/download-monitor-etc :path) path
@@ -59,25 +61,27 @@
     buffer))
 
 (defun h/download-monitor-update (buffer)
-  (with-current-buffer buffer
-    (pcase-let* (((map :path :total-size :completed-fn)
-                  h/download-monitor-etc))
-      (if (file-exists-p path)
-          (let* ((attributes (file-attributes path))
-                 (current-size (file-attribute-size attributes)))
-            (if (= current-size total-size)
-                ;; Download complete.
-                (funcall (map-elt h/download-monitor-etc :completed-fn))
-              ;; Download in progress: update buffer.
-              (erase-buffer)
-              (insert "Downloading:\n\n"
-                      "File: " path "\n"
-                      "Downloaded: " (file-size-human-readable current-size 
nil " ")
-                      " / " (file-size-human-readable total-size) "\n")))
-        ;; Download completed or canceled.
-        ;; FIXME: We just assume here that it completed and wasn't canceled.
-        (when completed-fn
-          (funcall completed-fn))))))
+  (let (completedp)
+    (with-current-buffer buffer
+      (pcase-let* (((map :path :total-size) h/download-monitor-etc))
+        (if (file-exists-p path)
+            (let* ((attributes (file-attributes path))
+                   (current-size (file-attribute-size attributes)))
+              (if (= current-size total-size)
+                  ;; Download complete.
+                  (setf completedp t)
+                ;; Download in progress: update buffer.
+                (erase-buffer)
+                (insert "Downloading:\n\n"
+                        "File: " path "\n"
+                        "Downloaded: " (file-size-human-readable current-size 
nil " ")
+                        " / " (file-size-human-readable total-size) "\n")))
+          ;; Download completed or canceled.
+          (setf completedp t))))
+    (when completedp
+      ;; FIXME: We just assume here that it completed and wasn't canceled.
+      (when-let ((completed-fn (map-elt h/download-monitor-etc :completed-fn)))
+        (funcall completed-fn buffer)))))
 
 (provide 'hyperdrive-download-monitor)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]