branch: elpa/hyperdrive
commit 547ed5ea7993838a6ed0f27fcf824401ec621dad
Author: Adam Porter <[email protected]>
Commit: Joseph Turner <[email protected]>
WIP
---
hyperdrive-lib.el | 45 +++++++++++----------------------------------
hyperdrive-vars.el | 8 +++++++-
hyperdrive.el | 18 +++++++++++++++++-
3 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 38d6723375..ff5eabac58 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -168,11 +168,6 @@ make the request."
;; `h//fill-latest-version' everywhere else.
(declare (indent defun))
;; `h/ensure-gateway' will signal an error if the gateway is not responsive.
- (unless (h/ensure-gateway)
- ;; NOTE: `h/error' displays "hyperdrive error: Installing gateway" in the
- ;; echo area, which might be misinterpreted as an indication that the
- ;; installation failed.
- (error "Installing gateway"))
(pcase method
((and (or 'get 'head)
(guard (string-suffix-p "/" url)))
@@ -203,35 +198,17 @@ make the request."
;; We pass only the `plz-error' struct to the ELSE* function.
(funcall else* (caddr err))))))
-(let (gateway-version-correct-p)
- (defun h/ensure-gateway ()
- "Return non-nil if gateway is responsive at the correct version.
-Otherwise, offer install the gateway. If the user chooses
-to (asynchronously) install the gateway, return nil. If the user
-chooses to proceed without installing the gateway, return non-nil
-and remember the user's choice. Signals an error if the gateway
-is not responsive."
- (declare-function hyperdrive-hyper-gateway-ushin-version "hyperdrive")
- ;; TODO: If possible, reset the value of `gateway-version-correct-p' when
- ;; hyperdrive.el is upgraded, since a new version of hyperdrive.el may
require
- ;; a new version of hyper-gateway-ushin. Alternatively, since upgrading
- ;; hyperdrive.el should change the value of `h/gateway-version-expected',
- ;; could we memoize this function and make it run again when the expected
- ;; version changes?
- (defvar h/gateway-version-expected)
- (or gateway-version-correct-p
- ;; Version unknown: verify it.
- (when (equal h/gateway-version-expected
- ;; This will signal an error if the gateway is not
responsive.
- (hyperdrive-hyper-gateway-ushin-version))
- (setf gateway-version-correct-p t))
- (if (yes-or-no-p "Gateway not installed at expected version; download
correct version (yes) or proceed anyway (no)? ")
- (progn
- (declare-function h/install "hyperdrive")
- (h/install 'force)
- nil)
- ;; Override and use existing version.
- (setf gateway-version-correct-p t)))))
+(defun h//check-gateway-version ()
+ "Check and return whether gateway is at expected version.
+Sets `h/gateway-version-expected' if so. The caller should
+ensure that the gateway is running before calling this function."
+ ;; TODO: Consider moving `hyperdrive-hyper-gateway-ushin-version' into this
file.
+ (declare-function hyperdrive-hyper-gateway-ushin-version "hyperdrive")
+ (unless (equal h/gateway-version-expected
+ ;; This will signal an error if the gateway is not responsive.
+ (hyperdrive-hyper-gateway-ushin-version))
+ (display-warning 'hyperdrive "Gateway version not expected; consider
installing the latest version with \\[hyperdrive-install]" :warning))
+ (setf h/gateway-version-checked-p t))
(defun h/api-default-else (else plz-err)
"Handle common errors, overriding ELSE.
diff --git a/hyperdrive-vars.el b/hyperdrive-vars.el
index 9443a015fa..4808fccba9 100644
--- a/hyperdrive-vars.el
+++ b/hyperdrive-vars.el
@@ -364,6 +364,11 @@ values are alists mapping version range starts to plists
with
(defvar h/gateway-version-expected "3.8.0")
+(defvar h/gateway-version-checked-p nil
+ "Non-nil if the gateway's version has been checked.
+If the version was unexpected,
+`hyperdrive--check-gateway-version' displayed a warning.")
+
(defvar h/gateway-process nil
"Hyper-gateway-ushin process.")
@@ -419,8 +424,9 @@ gateway process."
"Predicate function which returns non-nil if the gateway process is live."
:type 'function)
+;; TODO: Consider having a private hook as well as a public one.
(defcustom h/gateway-ready-hook
- '(h//gateway-after-start-announce)
+ '(h//check-gateway-version h//gateway-after-start-announce)
"Hook called when gateway is ready after starting it.
This hook is called by `hyperdrive--gateway-wait-for-ready' after
`hyperdrive-start'."
diff --git a/hyperdrive.el b/hyperdrive.el
index 563c71a28a..785f5c56c7 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -100,7 +100,23 @@ Calls function set in option
`hyperdrive-gateway-start-function',
which see."
(interactive)
;; TODO: Verify that the expected version, e.g., 3.7.0, is installed. Do
this in an after-start hook?
- (funcall h/gateway-start-function))
+ (cond ((and (h//gateway-ready-p)
+ (or h/gateway-version-correct-p
+ (h//gateway-at-expected-version-p)))
+ ;; Gateway already running and at expected version: call
+ ;; `gateway-wait-for-ready', which will run the run the
+ ;; gateway-ready-hook, because we're not calling the gateway-start
+ ;; function.
+ (h//gateway-wait-for-ready))
+ ((h//gateway-ready-p)
+ ;; Running but wrong version: prompt to upgrade or accept.
+ (if (yes-or-no-p "Gateway not installed at expected version; download
correct version (yes) or proceed anyway (no)? ")
+ (h/install 'force)
+ ;; Override and use existing version.
+ (setf h/gateway-version-correct-p t)))
+ (t
+ ;; Gateway not running: start it, then check its version.
+ (funcall h/gateway-start-function))))
;;;###autoload
(defun hyperdrive-stop ()