summaryrefslogtreecommitdiff
path: root/pkg/systray
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2019-01-15 17:19:19 +0100
committerRuben Pollan <meskio@sindominio.net>2019-01-15 17:26:06 +0100
commit52d7fa7c91dd5bad49f07e33956681b5e341c6fa (patch)
tree0cd14b39203ef5652ee2c76ac27320db4abb4ef8 /pkg/systray
parent80b6aef1206fb63f1a2985f003f6b484a23bb949 (diff)
[feat] move provider configuration into a set of constants
Diffstat (limited to 'pkg/systray')
-rw-r--r--pkg/systray/config.go22
-rw-r--r--pkg/systray/notificator.go25
-rw-r--r--pkg/systray/run.go12
-rw-r--r--pkg/systray/systray.go23
4 files changed, 41 insertions, 41 deletions
diff --git a/pkg/systray/config.go b/pkg/systray/config.go
index 75a7a8a..1bacb1b 100644
--- a/pkg/systray/config.go
+++ b/pkg/systray/config.go
@@ -34,21 +34,19 @@ var (
configPath = path.Join(config.Path, "systray.json")
)
-// SystrayConfig holds the configuration of the systray
-type SystrayConfig struct {
+// Config holds the configuration of the systray
+type Config struct {
LastNotification time.Time
Donated time.Time
SelectGateway bool
UserStoppedVPN bool
- Provider string `json:"-"`
- ApplicationName string `json:"-"`
Version string `json:"-"`
Printer *message.Printer `json:"-"`
}
// ParseConfig reads the configuration from the configuration file
-func ParseConfig() *SystrayConfig {
- var conf SystrayConfig
+func ParseConfig() *Config {
+ var conf Config
f, err := os.Open(configPath)
if err != nil {
@@ -62,30 +60,30 @@ func ParseConfig() *SystrayConfig {
return &conf
}
-func (c *SystrayConfig) setUserStoppedVPN(vpnStopped bool) error {
+func (c *Config) setUserStoppedVPN(vpnStopped bool) error {
c.UserStoppedVPN = vpnStopped
return c.save()
}
-func (c *SystrayConfig) hasDonated() bool {
+func (c *Config) hasDonated() bool {
return c.Donated.Add(oneMonth).After(time.Now())
}
-func (c *SystrayConfig) needsNotification() bool {
+func (c *Config) needsNotification() bool {
return !c.hasDonated() && c.LastNotification.Add(oneDay).Before(time.Now())
}
-func (c *SystrayConfig) setNotification() error {
+func (c *Config) setNotification() error {
c.LastNotification = time.Now()
return c.save()
}
-func (c *SystrayConfig) setDonated() error {
+func (c *Config) setDonated() error {
c.Donated = time.Now()
return c.save()
}
-func (c *SystrayConfig) save() error {
+func (c *Config) save() error {
f, err := os.Create(configPath)
if err != nil {
return err
diff --git a/pkg/systray/notificator.go b/pkg/systray/notificator.go
index e23b9d1..754a2e8 100644
--- a/pkg/systray/notificator.go
+++ b/pkg/systray/notificator.go
@@ -22,6 +22,7 @@ import (
"runtime"
"time"
+ "0xacab.org/leap/bitmask-systray/pkg/config"
"0xacab.org/leap/go-dialog"
"github.com/skratchdot/open-golang/open"
)
@@ -30,24 +31,24 @@ const (
donationText = `The %s service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.
Do you want to donate now?`
- aboutText = `%[1]s is an easy, fast, and secure VPN service from riseup.net. %[1]s does not require a user account, keep logs, or track you in any way.
+ aboutText = `%[1]s is an easy, fast, and secure VPN service from %[2]s. %[1]s does not require a user account, keep logs, or track you in any way.
-This service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.
+This service is paid for entirely by donations from users like you. Please donate at %[3]s.
-By using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.
+By using this application, you agree to the Terms of Service available at %[4]s. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.
-%[1]v version: %[2]s`
+%[1]v version: %[5]s`
missingAuthAgent = `Could not find a polkit authentication agent. Please run one and try again.`
errorStartingVPN = `Can't connect to %s: %v`
svgFileName = "riseupvpn.svg"
)
type notificator struct {
- conf *SystrayConfig
+ conf *Config
}
-func newNotificator(conf *SystrayConfig) *notificator {
+func newNotificator(conf *Config) *notificator {
n := notificator{conf}
go n.donations()
return &n
@@ -57,7 +58,7 @@ func (n *notificator) donations() {
for {
time.Sleep(time.Hour)
if n.conf.needsNotification() {
- letsDonate := dialog.Message(n.conf.Printer.Sprintf(donationText, n.conf.ApplicationName)).
+ letsDonate := dialog.Message(n.conf.Printer.Sprintf(donationText, config.ApplicationName)).
Title(n.conf.Printer.Sprintf("Donate")).
Icon(getIconPath()).
YesNo()
@@ -77,7 +78,7 @@ func (n *notificator) about(version string) {
version = string(_version)
}
}
- dialog.Message(n.conf.Printer.Sprintf(aboutText, n.conf.ApplicationName, version)).
+ dialog.Message(n.conf.Printer.Sprintf(aboutText, config.ApplicationName, config.Provider, config.DonateURL, config.TosURL, version)).
Title(n.conf.Printer.Sprintf("About")).
Icon(getIconPath()).
Info()
@@ -98,7 +99,7 @@ func (n *notificator) authAgent() {
}
func (n *notificator) errorStartingVPN(err error) {
- dialog.Message(n.conf.Printer.Sprintf(errorStartingVPN, n.conf.ApplicationName, err)).
+ dialog.Message(n.conf.Printer.Sprintf(errorStartingVPN, config.ApplicationName, err)).
Title(n.conf.Printer.Sprintf("Error starting VPN")).
Icon(getIconPath()).
Error()
@@ -111,7 +112,7 @@ func getIconPath() string {
}
if runtime.GOOS == "windows" {
- icoPath := `C:\Program Files\RiseupVPN\riseupvpn.ico`
+ icoPath := `C:\Program Files\` + config.ApplicationName + `\riseupvpn.ico`
if fileExist(icoPath) {
return icoPath
}
@@ -123,7 +124,7 @@ func getIconPath() string {
}
if runtime.GOOS == "darwin" {
- icnsPath := "/Applications/RiseupVPN.app/Contents/Resources/app.icns"
+ icnsPath := "/Applications/" + config.ApplicationName + ".app/Contents/Resources/app.icns"
if fileExist(icnsPath) {
return icnsPath
}
@@ -145,7 +146,7 @@ func getIconPath() string {
return svgPath
}
- svgPath = "/usr/share/riseupvpn/riseupvpn.svg"
+ svgPath = "/usr/share/" + config.BinaryName + "/riseupvpn.svg"
if fileExist(svgPath) {
return svgPath
}
diff --git a/pkg/systray/run.go b/pkg/systray/run.go
index 0457ed4..73dc853 100644
--- a/pkg/systray/run.go
+++ b/pkg/systray/run.go
@@ -23,13 +23,13 @@ import (
"0xacab.org/leap/bitmask-systray/pkg/config"
)
-func Run(conf *SystrayConfig) {
+func Run(conf *Config) {
bt := bmTray{conf: conf}
go initialize(conf, &bt)
bt.start()
}
-func initialize(conf *SystrayConfig, bt *bmTray) {
+func initialize(conf *Config, bt *bmTray) {
if _, err := os.Stat(config.Path); os.IsNotExist(err) {
os.MkdirAll(config.Path, os.ModePerm)
}
@@ -51,7 +51,7 @@ func initialize(conf *SystrayConfig, bt *bmTray) {
go checkAndStartBitmask(b, notify, conf)
go listenSignals(b)
- as := bitmask.NewAutostart(conf.ApplicationName, getIconPath())
+ as := bitmask.NewAutostart(config.ApplicationName, getIconPath())
err = as.Enable()
if err != nil {
log.Printf("Error enabling autostart: %v", err)
@@ -59,7 +59,7 @@ func initialize(conf *SystrayConfig, bt *bmTray) {
bt.loop(b, notify, as)
}
-func checkAndStartBitmask(b bitmask.Bitmask, notify *notificator, conf *SystrayConfig) {
+func checkAndStartBitmask(b bitmask.Bitmask, notify *notificator, conf *Config) {
err := checkAndInstallHelpers(b, notify)
if err != nil {
log.Printf("Is bitmask running? %v", err)
@@ -92,12 +92,12 @@ func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error {
return nil
}
-func maybeStartVPN(b bitmask.Bitmask, conf *SystrayConfig) error {
+func maybeStartVPN(b bitmask.Bitmask, conf *Config) error {
if conf.UserStoppedVPN {
return nil
}
- err := b.StartVPN(conf.Provider)
+ err := b.StartVPN(config.Provider)
conf.setUserStoppedVPN(false)
return err
}
diff --git a/pkg/systray/systray.go b/pkg/systray/systray.go
index 3505958..29e798d 100644
--- a/pkg/systray/systray.go
+++ b/pkg/systray/systray.go
@@ -24,13 +24,14 @@ import (
"0xacab.org/leap/bitmask-systray/icon"
"0xacab.org/leap/bitmask-systray/pkg/bitmask"
+ "0xacab.org/leap/bitmask-systray/pkg/config"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
)
type bmTray struct {
bm bitmask.Bitmask
- conf *SystrayConfig
+ conf *Config
notify *notificator
waitCh chan bool
mStatus *systray.MenuItem
@@ -108,7 +109,7 @@ func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as bitmask.Autos
case <-bt.mTurnOn.ClickedCh:
log.Println("on")
bt.changeStatus("starting")
- bt.bm.StartVPN(bt.conf.Provider)
+ bt.bm.StartVPN(config.Provider)
bt.conf.setUserStoppedVPN(false)
case <-bt.mTurnOff.ClickedCh:
log.Println("off")
@@ -117,10 +118,10 @@ func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as bitmask.Autos
bt.conf.setUserStoppedVPN(true)
case <-bt.mHelp.ClickedCh:
- open.Run("https://riseup.net/vpn/support")
+ open.Run(config.HelpURL)
case <-bt.mDonate.ClickedCh:
bt.conf.setDonated()
- open.Run("https://riseup.net/vpn/donate")
+ open.Run(config.DonateURL)
case <-bt.mAbout.ClickedCh:
bitmaskVersion, err := bt.bm.Version()
versionStr := bt.conf.Version
@@ -153,7 +154,7 @@ func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as bitmask.Autos
}
func (bt *bmTray) addGateways() {
- gatewayList, err := bt.bm.ListGateways(bt.conf.Provider)
+ gatewayList, err := bt.bm.ListGateways(config.Provider)
if err != nil {
log.Printf("Gateway initialization error: %v", err)
return
@@ -162,7 +163,7 @@ func (bt *bmTray) addGateways() {
mGateway := systray.AddMenuItem(bt.conf.Printer.Sprintf("Route traffic through"), "")
mGateway.Disable()
for i, city := range gatewayList {
- menuItem := systray.AddMenuItem(city, bt.conf.Printer.Sprintf("Use %s %v gateway", bt.conf.ApplicationName, city))
+ menuItem := systray.AddMenuItem(city, bt.conf.Printer.Sprintf("Use %s %v gateway", config.ApplicationName, city))
gateway := gatewayTray{menuItem, city}
if i == 0 {
@@ -203,14 +204,14 @@ func (bt *bmTray) changeStatus(status string) {
case "on":
systray.SetIcon(icon.On)
bt.mTurnOff.SetTitle(printer.Sprintf("Turn off"))
- statusStr = printer.Sprintf("%s on", bt.conf.ApplicationName)
+ statusStr = printer.Sprintf("%s on", config.ApplicationName)
bt.mTurnOn.Hide()
bt.mTurnOff.Show()
case "off":
systray.SetIcon(icon.Off)
bt.mTurnOn.SetTitle(printer.Sprintf("Turn on"))
- statusStr = printer.Sprintf("%s off", bt.conf.ApplicationName)
+ statusStr = printer.Sprintf("%s off", config.ApplicationName)
bt.mTurnOn.Show()
bt.mTurnOff.Hide()
@@ -218,14 +219,14 @@ func (bt *bmTray) changeStatus(status string) {
bt.waitCh = make(chan bool)
go bt.waitIcon()
bt.mTurnOff.SetTitle(printer.Sprintf("Cancel"))
- statusStr = printer.Sprintf("Connecting to %s", bt.conf.ApplicationName)
+ statusStr = printer.Sprintf("Connecting to %s", config.ApplicationName)
bt.mTurnOn.Hide()
bt.mTurnOff.Show()
case "stopping":
bt.waitCh = make(chan bool)
go bt.waitIcon()
- statusStr = printer.Sprintf("Stopping %s", bt.conf.ApplicationName)
+ statusStr = printer.Sprintf("Stopping %s", config.ApplicationName)
bt.mTurnOn.Hide()
bt.mTurnOff.Hide()
@@ -233,7 +234,7 @@ func (bt *bmTray) changeStatus(status string) {
systray.SetIcon(icon.Blocked)
bt.mTurnOn.SetTitle(printer.Sprintf("Retry"))
bt.mTurnOff.SetTitle(printer.Sprintf("Turn off"))
- statusStr = printer.Sprintf("%s blocking internet", bt.conf.ApplicationName)
+ statusStr = printer.Sprintf("%s blocking internet", config.ApplicationName)
bt.mTurnOn.Show()
bt.mTurnOff.Show()
}