diff options
author | jao <jao@gnu.org> | 2020-09-30 02:38:49 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-09-30 02:38:49 +0100 |
commit | d91bc785a7d2669014dd6509bcf6e4816756806c (patch) | |
tree | f23067dca874b09063ca26281f358364f0352381 /net | |
parent | 51d7d7665240aaa4cd33b9302a36247df6cbb075 (diff) | |
download | elibs-d91bc785a7d2669014dd6509bcf6e4816756806c.tar.gz elibs-d91bc785a7d2669014dd6509bcf6e4816756806c.tar.bz2 |
improvements on the above
Diffstat (limited to 'net')
-rw-r--r-- | net/jao-proton-utils.el | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/net/jao-proton-utils.el b/net/jao-proton-utils.el index f6d7f3b..5c817ac 100644 --- a/net/jao-proton-utils.el +++ b/net/jao-proton-utils.el @@ -58,8 +58,10 @@ (setq mode-name "proton-vpn") (read-only-mode 1)) +(defvar jao-proton-vpn--buffer "*pvpn*") + (defun jao-proton-vpn--do (things &optional buffer) - (let ((b (or buffer (pop-to-buffer (get-buffer-create "*pvpn*"))))) + (let ((b (or buffer (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)) @@ -74,11 +76,12 @@ (jao-proton-vpn--do "s")) (defun proton-vpn--get-status () - (with-temp-buffer - (jao-proton-vpn--do "s" (current-buffer)) - (goto-char (point-min)) - (when (re-search-forward "^Status: *\\(.+\\)$" nil t) - (match-string 1)))) + (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)))) + "Disconnected")) ;;;###autoload (defun proton-vpn-connect (cc) @@ -87,11 +90,17 @@ (jao-proton-vpn--do (if cc (format "c --cc %s" cc) "c --sc")) (proton-vpn-status))) +(defun proton-vpn-reconnect () + (interactive) + (jao-proton-vpn--do "r")) + ;;;###autoload (defun proton-vpn-maybe-reconnect () + (interactive) (when (string= "Connected" (proton-vpn--get-status)) - (with-temp-buffer - (jao-proton-vpn--do "r" (current-buffer))))) + (message "Reconnecting VPN...") + (proton-vpn-reconnect) + (message "Reconnecting VPN... done"))) ;;;###autoload (defun proton-vpn-disconnect () @@ -105,6 +114,7 @@ (define-key map [?n] 'next-line) (define-key map [?p] 'previous-line) (define-key map [?g] 'proton-vpn-status) + (define-key map [?r] 'proton-vpn-reconnect) (define-key map [?d] (lambda () (interactive) (when (y-or-n-p "Disconnect?") |