From fb99b4344411e62fdd5aee9c26c90a2da1761056 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 21 Feb 2018 20:49:29 +0100 Subject: [feat] discover the path of the svg for the notifications Try different known paths for the svg file. - Resolves: #10 --- notificator.go | 33 +++++++++++++++++++++++++++++++-- 1 file 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 +} -- cgit v1.2.3