summaryrefslogtreecommitdiff
path: root/notificator.go
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-04-12 12:46:47 +0200
committerRuben Pollan <meskio@sindominio.net>2018-04-19 22:58:45 +0200
commit32f589c45d9b25a52877875f05fa4f59509458a2 (patch)
tree9d94469603914a01861975f4b3548bafabd1ca1f /notificator.go
parenta45d99f2dd4d3694160580184f0573a15c06708f (diff)
[feat] Ask for donations
- Resolves: #24
Diffstat (limited to 'notificator.go')
-rw-r--r--notificator.go60
1 files changed, 15 insertions, 45 deletions
diff --git a/notificator.go b/notificator.go
index 9ce224f..ea5fb42 100644
--- a/notificator.go
+++ b/notificator.go
@@ -16,32 +16,27 @@
package main
import (
- "os"
- "path"
"time"
- notif "github.com/0xAX/notificator"
+ "0xacab.org/leap/go-dialog"
+ "github.com/skratchdot/open-golang/open"
)
const (
- donationText = `The RiseupVPN 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 at https://riseup.net/donate-vpn`
+ 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?`
missingAuthAgent = `Could not find a polkit authentication agent. Please run one and try again.`
notRunning = `Is bitmaskd running? Start bitmask and try again.`
- svgFileName = "riseupvpn.svg"
)
type notificator struct {
- notify *notif.Notificator
- conf *systrayConfig
+ conf *systrayConfig
}
func newNotificator(conf *systrayConfig) *notificator {
- notify := notif.New(notif.Options{
- DefaultIcon: getSVGPath(),
- AppName: "RiseupVPN",
- })
- n := notificator{notify, conf}
- //go n.donations()
+ n := notificator{conf}
+ go n.donations()
return &n
}
@@ -49,46 +44,21 @@ func (n *notificator) donations() {
time.Sleep(time.Minute * 5)
for {
if n.conf.needsNotification() {
- n.notify.Push(printer.Sprintf("Donate to RiseupVPN"), printer.Sprintf(donationText), "", notif.UR_NORMAL)
+ letsDonate := dialog.Message(printer.Sprintf(donationText, applicationName)).Title(printer.Sprintf("Donate")).YesNo()
n.conf.setNotification()
+ if letsDonate {
+ open.Run("https://riseup.net/donate-vpn")
+ n.conf.setDonated()
+ }
}
time.Sleep(time.Hour)
}
}
func (n *notificator) bitmaskNotRunning() {
- n.notify.Push(printer.Sprintf("Can't contact bitmask"), printer.Sprintf(notRunning), "", notif.UR_CRITICAL)
+ dialog.Message(printer.Sprintf(notRunning)).Title(printer.Sprintf("Can't contact bitmask")).Error()
}
func (n *notificator) authAgent() {
- n.notify.Push(printer.Sprintf("Missing authentication agent"), printer.Sprintf(missingAuthAgent), "", notif.UR_CRITICAL)
-}
-
-func getSVGPath() string {
- wd, _ := os.Getwd()
- svgPath := path.Join(wd, svgFileName)
- if fileExist(svgPath) {
- return svgPath
- }
-
- svgPath = "/usr/share/riseupvpn/riseupvpn.svg"
- if fileExist(svgPath) {
- return svgPath
- }
-
- gopath := os.Getenv("GOPATH")
- if gopath == "" {
- gopath = path.Join(os.Getenv("HOME"), "go")
- }
- svgPath = path.Join(gopath, "src", "0xacab.org", "leap", "bitmask-systray", svgFileName)
- if fileExist(svgPath) {
- return svgPath
- }
-
- return ""
-}
-
-func fileExist(filePath string) bool {
- _, err := os.Stat(filePath)
- return err == nil
+ dialog.Message(printer.Sprintf(missingAuthAgent)).Title(printer.Sprintf("Missing authentication agent")).Error()
}