From 72c580909cdfd6f8d3655cd92ab1a4bfd52717fe Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 30 Sep 2020 03:31:05 +0100 Subject: proton vpn: ugly sit to reconnect --- net/jao-proton-utils.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'net/jao-proton-utils.el') diff --git a/net/jao-proton-utils.el b/net/jao-proton-utils.el index 5c817ac..2d20f5e 100644 --- a/net/jao-proton-utils.el +++ b/net/jao-proton-utils.el @@ -60,15 +60,15 @@ (defvar jao-proton-vpn--buffer "*pvpn*") -(defun jao-proton-vpn--do (things &optional buffer) - (let ((b (or buffer (pop-to-buffer (get-buffer-create jao-proton-vpn--buffer))))) +(defun jao-proton-vpn--do (things) + (let ((b (pop-to-buffer (get-buffer-create jao-proton-vpn--buffer)))) (let ((inhibit-read-only t) (cmd (format "sudo protonvpn %s" things))) (delete-region (point-min) (point-max)) (message "Running: %s ...." cmd) (shell-command cmd b) (message "")) - (when (not buffer) (proton-vpn-mode)))) + (proton-vpn-mode))) ;;;###autoload (defun proton-vpn-status () @@ -79,8 +79,10 @@ (or (when-let ((b (get-buffer jao-proton-vpn--buffer))) (with-current-buffer b (goto-char (point-min)) - (when (re-search-forward "^Status: *\\(.+\\)$" nil t) - (match-string-no-properties 1)))) + (if (re-search-forward "^Status: *\\(.+\\)$" nil t) + (match-string-no-properties 1) + (when (re-search-forward "^Connected!$") + "Connected")))) "Disconnected")) ;;;###autoload @@ -94,13 +96,15 @@ (interactive) (jao-proton-vpn--do "r")) +(setenv "PVPN_WAIT" "300") + ;;;###autoload (defun proton-vpn-maybe-reconnect () (interactive) (when (string= "Connected" (proton-vpn--get-status)) - (message "Reconnecting VPN...") - (proton-vpn-reconnect) - (message "Reconnecting VPN... done"))) + (jao-proton-vpn--do "d") + (sit-for 5) + (jao-proton-vpn--do "r"))) ;;;###autoload (defun proton-vpn-disconnect () -- cgit v1.2.3