[modules/github] Use xdg-open by default

Use xdg-open to open the URL, and fall back to x-www-browser, if
xdg-open is not available.

fixes #600
This commit is contained in:
tobi-wan-kenobi 2020-04-23 07:48:23 +02:00
parent 833dc5dc4c
commit c3d2ef5f0b

View file

@ -14,6 +14,8 @@ import bumblebee.input
import bumblebee.output import bumblebee.output
import bumblebee.engine import bumblebee.engine
import bumblebee.util
try: try:
import requests import requests
except ImportError: except ImportError:
@ -28,9 +30,13 @@ class Module(bumblebee.engine.Module):
self.interval_factor(60) self.interval_factor(60)
self.interval(5) self.interval(5)
self._requests = requests.Session() self._requests = requests.Session()
cmd = "xdg-open"
if not bumblebee.util.which(cmd):
cmd = "x-www-browser"
self._requests.headers.update({"Authorization":"token {}".format(self.parameter("token", ""))}) self._requests.headers.update({"Authorization":"token {}".format(self.parameter("token", ""))})
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd="x-www-browser https://github.com/notifications") cmd="{} https://github.com/notifications".format(cmd))
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.update) engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.update)
def github(self, _): def github(self, _):