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

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

[nongnu] elpa/hyperdrive 84b59e1f8f 02/19: WIP: hyperdrive-download-moni


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive 84b59e1f8f 02/19: WIP: hyperdrive-download-monitor
Date: Thu, 1 Aug 2024 01:00:10 -0400 (EDT)

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

    WIP: hyperdrive-download-monitor
---
 hyperdrive-download-monitor.el | 81 ++++++++++++++++++++++++++++++++++++++++++
 hyperdrive.el                  |  6 ++++
 2 files changed, 87 insertions(+)

diff --git a/hyperdrive-download-monitor.el b/hyperdrive-download-monitor.el
new file mode 100644
index 0000000000..c93ab79477
--- /dev/null
+++ b/hyperdrive-download-monitor.el
@@ -0,0 +1,81 @@
+;;; hyperdrive-download-monitor.el ---    -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 USHIN, Inc.
+
+;; Author: Joseph Turner <joseph@ushin.org>
+;; Author: Adam Porter <adam@alphapapa.net>
+;; Maintainer: Joseph Turner <~ushin/ushin@lists.sr.ht>
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Affero General Public License
+;; as published by the Free Software Foundation; either version 3 of
+;; the License, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public
+;; License along with this program. If not, see
+;; <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Monitor a file download's progress in a buffer.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'map)
+(require 'pcase)
+
+;;;; Variables
+
+(defvar-local h/download-monitor-etc nil)
+
+;;;; Functions
+
+(cl-defun h/download-monitor
+    (&key buffer-name path total-size setup-fn completed-fn canceled-fn
+          (update-interval 1))
+  "Return buffer that monitors the download to PATH."
+  (let* ((buffer (generate-new-buffer buffer-name)))
+    (with-current-buffer buffer
+      (setf (map-elt h/download-monitor-etc :path) path
+            (map-elt h/download-monitor-etc :total-size) total-size
+            (map-elt h/download-monitor-etc :completed-fn) completed-fn
+            (map-elt h/download-monitor-etc :canceled-fn) canceled-fn)
+      (h/download-monitor-update buffer)
+      (setf (map-elt h/download-monitor-etc 'timer)
+            (run-at-time update-interval t #'h/download-monitor-update buffer))
+      (when setup-fn
+        (funcall setup-fn)))
+    buffer))
+
+(defun h/download-monitor-update (buffer)
+  (with-current-buffer buffer
+    (pcase-let* (((map :path :total-size) h/download-monitor-etc)
+                 (attributes (file-attributes path))
+                 (current-size (file-attribute-size attributes)))
+      ;; TODO: Check download process status to see whether download was 
canceled.
+      (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")))))
+
+(provide 'hyperdrive-download-monitor)
+
+;; Local Variables:
+;; read-symbol-shorthands: (
+;;   ("he//" . "hyperdrive-entry--")
+;;   ("he/"  . "hyperdrive-entry-")
+;;   ("h//"  . "hyperdrive--")
+;;   ("h/"   . "hyperdrive-"))
+;; End:
+;;; hyperdrive-download-monitor.el ends here
diff --git a/hyperdrive.el b/hyperdrive.el
index 7c12dd14af..bf981a16d2 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -1467,6 +1467,12 @@ If FORCEP, don't prompt for confirmation before 
downloading."
                                 (try)))
                              (when (file-exists-p temp-file)
                                (delete-file temp-file)))))
+             (require 'hyperdrive-download-monitor)
+             (pop-to-buffer
+              (h/download-monitor :buffer-name "*hyperdrive-install*"
+                                  :path temp-file
+                                  :total-size size
+                                  :completed-fn #'kill-buffer-and-window))
              (h/message "Downloading %s from %S to %S" size url destination)))
          (check (file-name sha256 url)
            (if (with-temp-buffer



reply via email to

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