summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2019-02-04 23:23:16 +0100
committerRuben Pollan <meskio@sindominio.net>2019-02-04 23:23:16 +0100
commitb9ef49b51c6e2570ef3aae824ab44374997b6b25 (patch)
tree5fcfcc4931d35b72b1853dff005f0eaca25d00d4 /pkg
parent51a4d191669aaf5e23ec4e1f61aab71419603003 (diff)
[feat] add -disable-autostart flag and config
Make possible to disable the autostart configuration for the next run. I can be done by configuring "DisableAustostart" to true in the systra.json or by passing the '-disable-autostart' flag to the binary. To make that possible I have rework how the Config struct work separating the file configuration with the runtime configuration. - Resolves: #100
Diffstat (limited to 'pkg')
-rw-r--r--pkg/bitmask/autostart.go6
-rw-r--r--pkg/bitmask/bitmaskd.go2
-rw-r--r--pkg/systray/config.go39
-rw-r--r--pkg/systray/run.go9
4 files changed, 37 insertions, 19 deletions
diff --git a/pkg/bitmask/autostart.go b/pkg/bitmask/autostart.go
index ebab428..32b931a 100644
--- a/pkg/bitmask/autostart.go
+++ b/pkg/bitmask/autostart.go
@@ -21,12 +21,12 @@ type Autostart interface {
Enable() error
}
-type dummyAutostart struct{}
+type DummyAutostart struct{}
-func (a *dummyAutostart) Disable() error {
+func (a *DummyAutostart) Disable() error {
return nil
}
-func (a *dummyAutostart) Enable() error {
+func (a *DummyAutostart) Enable() error {
return nil
}
diff --git a/pkg/bitmask/bitmaskd.go b/pkg/bitmask/bitmaskd.go
index 04b965c..a8c4e5d 100644
--- a/pkg/bitmask/bitmaskd.go
+++ b/pkg/bitmask/bitmaskd.go
@@ -40,5 +40,5 @@ func Init(printer *message.Printer) (Bitmask, error) {
// NewAutostart creates a handler for the autostart of your platform
func NewAutostart(appName string, iconPath string) Autostart {
- return &dummyAutostart{}
+ return &DummyAutostart{}
}
diff --git a/pkg/systray/config.go b/pkg/systray/config.go
index c40a279..2755851 100644
--- a/pkg/systray/config.go
+++ b/pkg/systray/config.go
@@ -36,12 +36,17 @@ var (
// Config holds the configuration of the systray
type Config struct {
- LastNotification time.Time
- Donated time.Time
- SelectGateway bool
- UserStoppedVPN bool
- Version string `json:"-"`
- Printer *message.Printer `json:"-"`
+ file struct {
+ LastNotification time.Time
+ Donated time.Time
+ SelectGateway bool
+ UserStoppedVPN bool
+ DisableAustostart bool
+ }
+ SelectGateway bool
+ DisableAustostart bool
+ Version string
+ Printer *message.Printer
}
// ParseConfig reads the configuration from the configuration file
@@ -56,30 +61,37 @@ func ParseConfig() *Config {
defer f.Close()
dec := json.NewDecoder(f)
- err = dec.Decode(&conf)
+ err = dec.Decode(&conf.file)
+
+ conf.SelectGateway = conf.file.SelectGateway
+ conf.DisableAustostart = conf.file.DisableAustostart
return &conf
}
func (c *Config) setUserStoppedVPN(vpnStopped bool) error {
- c.UserStoppedVPN = vpnStopped
+ c.file.UserStoppedVPN = vpnStopped
return c.save()
}
+func (c *Config) wasUserStopped() bool {
+ return c.file.UserStoppedVPN
+}
+
func (c *Config) hasDonated() bool {
- return c.Donated.Add(oneMonth).After(time.Now())
+ return c.file.Donated.Add(oneMonth).After(time.Now())
}
func (c *Config) needsNotification() bool {
- return !c.hasDonated() && c.LastNotification.Add(oneDay).Before(time.Now())
+ return !c.hasDonated() && c.file.LastNotification.Add(oneDay).Before(time.Now())
}
func (c *Config) setNotification() error {
- c.LastNotification = time.Now()
+ c.file.LastNotification = time.Now()
return c.save()
}
func (c *Config) setDonated() error {
- c.Donated = time.Now()
+ c.file.Donated = time.Now()
return c.save()
}
@@ -91,5 +103,6 @@ func (c *Config) save() error {
defer f.Close()
enc := json.NewEncoder(f)
- return enc.Encode(c)
+ enc.SetIndent("", " ")
+ return enc.Encode(c.file)
}
diff --git a/pkg/systray/run.go b/pkg/systray/run.go
index 2a513d8..2878928 100644
--- a/pkg/systray/run.go
+++ b/pkg/systray/run.go
@@ -51,7 +51,12 @@ func initialize(conf *Config, bt *bmTray) {
go checkAndStartBitmask(b, notify, conf)
go listenSignals(b)
- as := bitmask.NewAutostart(config.ApplicationName, getIconPath())
+ var as bitmask.Autostart
+ if conf.DisableAustostart {
+ as = &bitmask.DummyAutostart{}
+ } else {
+ as = bitmask.NewAutostart(config.ApplicationName, getIconPath())
+ }
err = as.Enable()
if err != nil {
log.Printf("Error enabling autostart: %v", err)
@@ -93,7 +98,7 @@ func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error {
}
func maybeStartVPN(b bitmask.Bitmask, conf *Config) error {
- if conf.UserStoppedVPN {
+ if conf.wasUserStopped() {
return nil
}