[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
- [nongnu] elpa/hyperdrive updated (52297ba0bd -> 4c5fc6ca76), ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 472e01a805 01/19: Fix: (h/install) Use temp file in temporary-file-directory, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 95f814ddb7 09/19: Tidy, improve, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 481df10760 05/19: Fix: Timer, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 4af29a6156 06/19: Fix: Completing download, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive a2120e57e9 03/19: Fix: Size, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 53ce1cf3f4 04/19: Fix: Wait for download to start, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 84b59e1f8f 02/19: WIP: hyperdrive-download-monitor,
ELPA Syncer <=
- [nongnu] elpa/hyperdrive c35423cdd4 12/19: Use special-mode, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 015917ecd3 14/19: Fix: (h//download-monitor) Cancel timer if buffer killed, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 4742b430fa 07/19: Fix: Killing monitor buffer, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 95323b4bf6 08/19: Refactoring, fixes, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 35d04e8cc5 18/19: Fix: Close monitor from ready hook; ensure buffer is live, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 4c5fc6ca76 19/19: Merge: Download monitor fixes/improvements, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 9156b1a7ac 16/19: Fix: Ensure timer before canceling, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 34e27bca27 10/19: Show elapsed time, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 36744a367d 15/19: Add: Restart gateway button in monitor buffer, ELPA Syncer, 2024/08/01
- [nongnu] elpa/hyperdrive 5434098b4a 11/19: Show speed, ELPA Syncer, 2024/08/01