summaryrefslogtreecommitdiffhomepage
path: root/net/jao-proton-utils.el
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-09-30 02:16:42 +0100
committerjao <jao@gnu.org>2020-09-30 02:16:42 +0100
commit51d7d7665240aaa4cd33b9302a36247df6cbb075 (patch)
tree2af203a9b4a155c28cdf1289ab3324b7cd841042 /net/jao-proton-utils.el
parent4fe77f6179d5ff58f3350f37d4497ad2f13e61b3 (diff)
downloadelibs-51d7d7665240aaa4cd33b9302a36247df6cbb075.tar.gz
elibs-51d7d7665240aaa4cd33b9302a36247df6cbb075.tar.bz2
proton vpn status and reconnect
Diffstat (limited to 'net/jao-proton-utils.el')
-rw-r--r--net/jao-proton-utils.el26
1 files changed, 22 insertions, 4 deletions
diff --git a/net/jao-proton-utils.el b/net/jao-proton-utils.el
index 980a317..f6d7f3b 100644
--- a/net/jao-proton-utils.el
+++ b/net/jao-proton-utils.el
@@ -1,6 +1,6 @@
;; jao-proton-utils.el -- simple interaction with Proton mail and vpn
-;; Copyright (c) 2018, 2019 Jose Antonio Ortega Ruiz
+;; Copyright (c) 2018, 2019, 2020 Jose Antonio Ortega Ruiz
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@
(setq comint-prompt-read-only t)
(setq comint-prompt-regexp "^>>> "))
+;;;###autoload
(defun run-proton-bridge ()
"Run or switch to an existing bridge process, using its CLI"
(interactive)
@@ -43,6 +44,7 @@
(defvar jao-proton-vpn-font-lock-keywords '("\\[.+\\]"))
+;;;###autoload
(defun proton-vpn-mode ()
"A very simple mode to show the output of ProtonVPN commands"
(interactive)
@@ -56,26 +58,42 @@
(setq mode-name "proton-vpn")
(read-only-mode 1))
-(defun jao-proton-vpn--do (things)
- (let ((b (pop-to-buffer (get-buffer-create "*pvpn*"))))
+(defun jao-proton-vpn--do (things &optional buffer)
+ (let ((b (or buffer (pop-to-buffer (get-buffer-create "*pvpn*")))))
(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 ""))
- (proton-vpn-mode)))
+ (when (not buffer) (proton-vpn-mode))))
+;;;###autoload
(defun proton-vpn-status ()
(interactive)
(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))))
+
+;;;###autoload
(defun proton-vpn-connect (cc)
(interactive "P")
(let ((cc (when cc (read-string "Country code: "))))
(jao-proton-vpn--do (if cc (format "c --cc %s" cc) "c --sc"))
(proton-vpn-status)))
+;;;###autoload
+(defun proton-vpn-maybe-reconnect ()
+ (when (string= "Connected" (proton-vpn--get-status))
+ (with-temp-buffer
+ (jao-proton-vpn--do "r" (current-buffer)))))
+
+;;;###autoload
(defun proton-vpn-disconnect ()
(interactive)
(jao-proton-vpn--do "d"))