summaryrefslogtreecommitdiffhomepage
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-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"))