From fa08af4697c14c5a365ed7ec2b2dce3f67386d49 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 9 Jul 2018 23:34:14 +0200 Subject: [feat] autostart the standalone systray if the vpn was on - Resolves: #8 --- notificator.go | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'notificator.go') diff --git a/notificator.go b/notificator.go index 1e9e405..d57e931 100644 --- a/notificator.go +++ b/notificator.go @@ -18,6 +18,7 @@ package main import ( "os" "path" + "runtime" "time" "0xacab.org/leap/go-dialog" @@ -58,7 +59,7 @@ func (n *notificator) donations() { if n.conf.needsNotification() { letsDonate := dialog.Message(printer.Sprintf(donationText, applicationName)). Title(printer.Sprintf("Donate")). - Icon(getSVGPath()). + Icon(getIconPath()). YesNo() n.conf.setNotification() if letsDonate { @@ -72,32 +73,61 @@ func (n *notificator) donations() { func (n *notificator) about(version string) { dialog.Message(printer.Sprintf(aboutText, applicationName, version)). Title(printer.Sprintf("About")). - Icon(getSVGPath()). + Icon(getIconPath()). Info() } func (n *notificator) bitmaskNotRunning() { dialog.Message(printer.Sprintf(notRunning)). Title(printer.Sprintf("Can't contact bitmask")). - Icon(getSVGPath()). + Icon(getIconPath()). Error() } func (n *notificator) authAgent() { dialog.Message(printer.Sprintf(missingAuthAgent)). Title(printer.Sprintf("Missing authentication agent")). - Icon(getSVGPath()). + Icon(getIconPath()). Error() } func (n *notificator) errorStartingVPN(err error) { dialog.Message(printer.Sprintf(errorStartingVPN, applicationName, err)). Title(printer.Sprintf("Error starting VPN")). - Icon(getSVGPath()). + Icon(getIconPath()). Error() } -func getSVGPath() string { +func getIconPath() string { + gopath := os.Getenv("GOPATH") + if gopath == "" { + gopath = path.Join(os.Getenv("HOME"), "go") + } + + if runtime.GOOS == "windows" { + icoPath := `C:\Program Files\RiseupVPN\riseupvpn.ico` + if fileExist(icoPath) { + return icoPath + } + icoPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.ico") + if fileExist(icoPath) { + return icoPath + } + return "" + } + + if runtime.GOOS == "darwin" { + icnsPath := "/Applications/RiseupVPN.app/Contents/Resources/app.icns" + if fileExist(icnsPath) { + return icnsPath + } + icnsPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.icns") + if fileExist(icnsPath) { + return icnsPath + } + return "" + } + snapPath := os.Getenv("SNAP") if snapPath != "" { return snapPath + "/snap/gui/riseupvpn.svg" @@ -114,10 +144,6 @@ func getSVGPath() string { 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 -- cgit v1.2.3