config: Allow notifications to be disabled in the config.

This commit is contained in:
Damir Jelić 2019-05-23 12:00:39 +02:00
parent bfcfdd61ea
commit a25ab95f62
4 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,7 @@
[Default]
LogLevel = Debug
SSL = True
Notifications = On
[local-matrix]
Homeserver = https://localhost:8448

View File

@ -32,6 +32,7 @@ class PanConfigParser(configparser.ConfigParser):
"ListenAddress": "localhost",
"ListenPort": "8009",
"LogLevel": "warnig",
"Notifications": "on",
},
converters={
"address": parse_address,
@ -124,6 +125,7 @@ class PanConfig:
config_file = attr.ib()
log_level = attr.ib(default=None)
notifications = attr.ib(default=None)
servers = attr.ib(init=False, default=attr.Factory(dict))
def read(self):
@ -141,6 +143,9 @@ class PanConfig:
if self.log_level is None:
self.log_level = config["Default"].getloglevel("LogLevel")
if self.notifications is None:
self.notifications = config["Default"].getboolean("Notifications")
listen_set = set()
try:

View File

@ -176,7 +176,7 @@ def main(
proxies.append(proxy)
glib_thread = GlibT(pan_queue.sync_q, ui_queue.sync_q, data_dir,
pan_conf.servers.values())
pan_conf.servers.values(), pan_conf)
glib_fut = loop.run_in_executor(
None,

View File

@ -402,6 +402,7 @@ class GlibT:
send_queue = attr.ib()
data_dir = attr.ib()
server_list = attr.ib()
config = attr.ib()
loop = attr.ib(init=False)
store = attr.ib(init=False)
@ -633,11 +634,14 @@ class GlibT:
def run(self):
self.loop = GLib.MainLoop()
try:
notify2.init("pantalaimon", mainloop=self.loop)
self.notifications = True
except dbus.DBusException:
self.notifications = False
if self.config.notifications:
try:
notify2.init("pantalaimon", mainloop=self.loop)
self.notifications = True
except dbus.DBusException:
logger.error("Notifications are enabled but no notification "
"server could be found, disabling notifications.")
self.notifications = False
GLib.timeout_add(100, self.message_callback)
self.loop.run()