1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// Copyright (C) 2018 LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"os"
"path"
"time"
"0xacab.org/leap/go-dialog"
"github.com/skratchdot/open-golang/open"
)
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?`
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 {
conf *systrayConfig
}
func newNotificator(conf *systrayConfig) *notificator {
n := notificator{conf}
go n.donations()
return &n
}
func (n *notificator) donations() {
time.Sleep(time.Minute * 5)
for {
if n.conf.needsNotification() {
letsDonate := dialog.Message(printer.Sprintf(donationText, applicationName)).
Title(printer.Sprintf("Donate")).
Icon(getSVGPath()).
YesNo()
n.conf.setNotification()
if letsDonate {
open.Run("https://riseup.net/donate-vpn")
n.conf.setDonated()
}
}
time.Sleep(time.Hour)
}
}
func (n *notificator) bitmaskNotRunning() {
dialog.Message(printer.Sprintf(notRunning)).
Title(printer.Sprintf("Can't contact bitmask")).
Icon(getSVGPath()).
Error()
}
func (n *notificator) authAgent() {
dialog.Message(printer.Sprintf(missingAuthAgent)).
Title(printer.Sprintf("Missing authentication agent")).
Icon(getSVGPath()).
Error()
}
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
}
|