summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-02-21 20:49:29 +0100
committerRuben Pollan <meskio@sindominio.net>2018-02-23 00:14:30 +0100
commitfb99b4344411e62fdd5aee9c26c90a2da1761056 (patch)
tree582d5812c15d80a5387f10384ca48cf25c9dc3c1
parent218af6e0d0b282ebae37c6324c9598e4a9a26931 (diff)
[feat] discover the path of the svg for the notifications
Try different known paths for the svg file. - Resolves: #10
-rw-r--r--notificator.go33
1 files changed, 31 insertions, 2 deletions
diff --git a/notificator.go b/notificator.go
index cf24797..7c53d18 100644
--- a/notificator.go
+++ b/notificator.go
@@ -27,6 +27,7 @@ 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`
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 {
@@ -35,9 +36,8 @@ type notificator struct {
}
func newNotificator(conf *systrayConfig) *notificator {
- wd, _ := os.Getwd()
notify := notif.New(notif.Options{
- DefaultIcon: path.Join(wd, "riseupvpn.svg"),
+ DefaultIcon: getSVGPath(),
AppName: "RiseupVPN",
})
n := notificator{notify, conf}
@@ -63,3 +63,32 @@ func (n *notificator) bitmaskNotRunning() {
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
+}