diff --git a/notificator.go b/notificator.go index cf24797698c25c65bdf8aaa32f10b1207b6ad0b9..7c53d187308c212c88e6fd45c1bbbe5c2280e223 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 +}