Skip to content
Snippets Groups Projects
Unverified Commit d0703ec2 authored by meskio's avatar meskio :tent:
Browse files

[feat] Add -start-vpn flag

The -start-vpn flag can be set to on or off to turn the vpn on or off
just after launching bitmask-vpn. So it doesn't depend on the status of
the vpn of the last run.

- Resolves: #114
parent b9ef49b5
No related branches found
No related tags found
1 merge request!61disable autostart and start-vpn flag
...@@ -51,12 +51,20 @@ func main() { ...@@ -51,12 +51,20 @@ func main() {
selectGateway := flag.Bool("select-gateway", false, "Enable gateway selection") selectGateway := flag.Bool("select-gateway", false, "Enable gateway selection")
disableAutostart := flag.Bool("disable-autostart", false, "Disable the autostart for the next run") disableAutostart := flag.Bool("disable-autostart", false, "Disable the autostart for the next run")
startVPN := flag.String("start-vpn", "", "Start the vpn in turned 'on' or 'off'")
versionFlag := flag.Bool("version", false, "Version of the bitmask-systray") versionFlag := flag.Bool("version", false, "Version of the bitmask-systray")
flag.Parse() flag.Parse()
if *versionFlag { if *versionFlag {
fmt.Println(version) fmt.Println(version)
os.Exit(0) os.Exit(0)
} }
if *startVPN != "" {
if *startVPN != "on" && *startVPN != "off" {
fmt.Println("-start-vpn should be 'on' or 'off'")
os.Exit(1)
}
conf.StartVPN = *startVPN == "on"
}
if *selectGateway { if *selectGateway {
conf.SelectGateway = *selectGateway conf.SelectGateway = *selectGateway
} }
......
...@@ -45,6 +45,7 @@ type Config struct { ...@@ -45,6 +45,7 @@ type Config struct {
} }
SelectGateway bool SelectGateway bool
DisableAustostart bool DisableAustostart bool
StartVPN bool
Version string Version string
Printer *message.Printer Printer *message.Printer
} }
...@@ -65,6 +66,7 @@ func ParseConfig() *Config { ...@@ -65,6 +66,7 @@ func ParseConfig() *Config {
conf.SelectGateway = conf.file.SelectGateway conf.SelectGateway = conf.file.SelectGateway
conf.DisableAustostart = conf.file.DisableAustostart conf.DisableAustostart = conf.file.DisableAustostart
conf.StartVPN = !conf.file.UserStoppedVPN
return &conf return &conf
} }
...@@ -73,10 +75,6 @@ func (c *Config) setUserStoppedVPN(vpnStopped bool) error { ...@@ -73,10 +75,6 @@ func (c *Config) setUserStoppedVPN(vpnStopped bool) error {
return c.save() return c.save()
} }
func (c *Config) wasUserStopped() bool {
return c.file.UserStoppedVPN
}
func (c *Config) hasDonated() bool { func (c *Config) hasDonated() bool {
return c.file.Donated.Add(oneMonth).After(time.Now()) return c.file.Donated.Add(oneMonth).After(time.Now())
} }
......
...@@ -98,7 +98,7 @@ func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error { ...@@ -98,7 +98,7 @@ func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error {
} }
func maybeStartVPN(b bitmask.Bitmask, conf *Config) error { func maybeStartVPN(b bitmask.Bitmask, conf *Config) error {
if conf.wasUserStopped() { if !conf.StartVPN {
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment