Skip to content
Snippets Groups Projects
Unverified Commit 43b06b2e authored by meskio's avatar meskio :tent:
Browse files

[bug] launch the systray ASAP so notifications work

The linux version of the notifications library we are using doesn't
handle the gtk.main loop. It requires the systray to be running to be
able to display a notification.

Spliting the start of the systray and the loop we can start the systray
pretty early and later on launch the main loop once we have bitmask and
other stuff ready.

- Related: #88
parent 5600fdb4
No related branches found
No related tags found
No related merge requests found
......@@ -60,11 +60,17 @@ func main() {
os.Exit(0)
}
bt := bmTray{conf: conf}
go initialize(conf, &bt)
bt.start()
}
func initialize(conf *systrayConfig, bt *bmTray) {
if _, err := os.Stat(bitmask.ConfigPath); os.IsNotExist(err) {
os.MkdirAll(bitmask.ConfigPath, os.ModePerm)
}
err = acquirePID()
err := acquirePID()
if err != nil {
log.Fatal(err)
}
......@@ -85,7 +91,7 @@ func main() {
if err != nil {
log.Printf("Error enabling autostart: %v", err)
}
run(b, conf, notify, as)
bt.loop(b, notify, as)
}
func checkAndStartBitmask(b bitmask.Bitmask, notify *notificator, conf *systrayConfig) {
......
......@@ -36,7 +36,10 @@ type bmTray struct {
mStatus *systray.MenuItem
mTurnOn *systray.MenuItem
mTurnOff *systray.MenuItem
mHelp *systray.MenuItem
mDonate *systray.MenuItem
mAbout *systray.MenuItem
mQuit *systray.MenuItem
activeGateway *gatewayTray
autostart autostart
}
......@@ -46,26 +49,18 @@ type gatewayTray struct {
name string
}
func run(bm bitmask.Bitmask, conf *systrayConfig, notify *notificator, as autostart) {
func (bt *bmTray) start() {
// XXX this removes the snap error message, but produces an invisible icon.
// https://0xacab.org/leap/riseup_vpn/issues/44
// os.Setenv("TMPDIR", "/var/tmp")
bt := bmTray{bm: bm, conf: conf, notify: notify, autostart: as}
systray.Run(bt.onReady, bt.onExit)
}
func (bt bmTray) onExit() {
status, _ := bt.bm.GetStatus()
if status != "off" {
bt.bm.StopVPN()
}
func (bt *bmTray) onExit() {
log.Println("Closing systray")
}
func (bt *bmTray) onReady() {
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt)
systray.SetIcon(icon.Off)
bt.mStatus = systray.AddMenuItem(printer.Sprintf("Checking status..."), "")
......@@ -80,14 +75,22 @@ func (bt *bmTray) onReady() {
bt.addGateways()
}
mHelp := systray.AddMenuItem(printer.Sprintf("Help..."), "")
bt.mHelp = systray.AddMenuItem(printer.Sprintf("Help..."), "")
bt.mDonate = systray.AddMenuItem(printer.Sprintf("Donate..."), "")
mAbout := systray.AddMenuItem(printer.Sprintf("About..."), "")
bt.mAbout = systray.AddMenuItem(printer.Sprintf("About..."), "")
systray.AddSeparator()
mQuit := systray.AddMenuItem(printer.Sprintf("Quit"), "")
bt.mQuit = systray.AddMenuItem(printer.Sprintf("Quit"), "")
}
func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as autostart) {
bt.bm = bm
bt.notify = notify
bt.autostart = as
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt)
go func() {
ch := bt.bm.GetStatusCh()
if status, err := bt.bm.GetStatus(); err != nil {
log.Printf("Error getting status: %v", err)
......@@ -112,12 +115,12 @@ func (bt *bmTray) onReady() {
bt.bm.StopVPN()
bt.conf.setUserStoppedVPN(true)
case <-mHelp.ClickedCh:
case <-bt.mHelp.ClickedCh:
open.Run("https://riseup.net/vpn/support")
case <-bt.mDonate.ClickedCh:
bt.conf.setDonated()
open.Run("https://riseup.net/vpn/donate")
case <-mAbout.ClickedCh:
case <-bt.mAbout.ClickedCh:
bitmaskVersion, err := bt.bm.Version()
versionStr := version
if err != nil {
......@@ -127,14 +130,16 @@ func (bt *bmTray) onReady() {
}
bt.notify.about(versionStr)
case <-mQuit.ClickedCh:
case <-bt.mQuit.ClickedCh:
err := bt.autostart.Disable()
if err != nil {
log.Printf("Error disabling autostart: %v", err)
}
systray.Quit()
return
case <-signalCh:
systray.Quit()
return
case <-time.After(5 * time.Second):
if status, err := bt.bm.GetStatus(); err != nil {
......@@ -144,7 +149,6 @@ func (bt *bmTray) onReady() {
}
}
}
}()
}
func (bt *bmTray) addGateways() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment