summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go7
-rw-r--r--main.go13
-rw-r--r--systray.go3
3 files changed, 23 insertions, 0 deletions
diff --git a/config.go b/config.go
index cf3ae1e..e8b25ab 100644
--- a/config.go
+++ b/config.go
@@ -38,6 +38,7 @@ type systrayConfig struct {
LastNotification time.Time
Donated time.Time
SelectWateway bool
+ UserStoppedVPN bool
}
func parseConfig() *systrayConfig {
@@ -45,6 +46,7 @@ func parseConfig() *systrayConfig {
f, err := os.Open(configPath)
if err != nil {
+ conf.save()
return &conf
}
defer f.Close()
@@ -55,6 +57,11 @@ func parseConfig() *systrayConfig {
return &conf
}
+func (c *systrayConfig) setUserStoppedVPN(vpnStopped bool) error {
+ c.UserStoppedVPN = vpnStopped
+ return c.save()
+}
+
func (c *systrayConfig) parseFlags() {
flag.BoolVar(&c.SelectWateway, "select-gateway", false, "Enable gateway selection")
flag.Parse()
diff --git a/main.go b/main.go
index 23e75b1..e8fa740 100644
--- a/main.go
+++ b/main.go
@@ -54,6 +54,7 @@ func main() {
log.Printf("Is bitmask running? %v", err)
return
}
+ maybeStartVPN(b, conf)
run(b, conf)
}
@@ -77,6 +78,18 @@ func checkAndInstallHelpers(b *bitmask.Bitmask, notify *notificator) error {
return nil
}
+func maybeStartVPN(b *bitmask.Bitmask, conf *systrayConfig) {
+ if conf.UserStoppedVPN {
+ return
+ }
+
+ err := b.StartVPN(provider)
+ if err != nil {
+ log.Println("Error starting VPN: ", err)
+ }
+ conf.setUserStoppedVPN(false)
+}
+
func initPrinter() {
locale, err := go_locale.DetectLocale()
if err != nil {
diff --git a/systray.go b/systray.go
index c61ca5d..b3c020d 100644
--- a/systray.go
+++ b/systray.go
@@ -97,12 +97,15 @@ func (bt *bmTray) onReady() {
case <-bt.mTurnOn.ClickedCh:
log.Println("on")
bt.bm.StartVPN(provider)
+ bt.conf.setUserStoppedVPN(false)
case <-bt.mTurnOff.ClickedCh:
log.Println("off")
bt.bm.StopVPN()
+ bt.conf.setUserStoppedVPN(true)
case <-bt.mCancel.ClickedCh:
log.Println("cancel")
bt.bm.StopVPN()
+ bt.conf.setUserStoppedVPN(true)
case <-mHelp.ClickedCh:
open.Run("https://riseup.net/vpn")