Skip to content

Commit

Permalink
Check notification server capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
bebehei committed Jul 30, 2018
1 parent e9c8b4f commit d352ce1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions syncthing_gtk/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
ICON_DEF = "syncthing-gtk"
ICON_ERR = "syncthing-gtk-error"

SERVER_CAPS = []

HAS_DESKTOP_NOTIFY = False
Notifications = None

Expand All @@ -35,6 +37,9 @@ class NotificationsCls(TimerManager):
def __init__(self, app, daemon):
TimerManager.__init__(self)
Notify.init("Syncthing GTK")
# Cache the server capabilities, as get_server_caps() always queries DBus
global SERVER_CAPS
SERVER_CAPS = Notify.get_server_caps()

This comment has been minimized.

Copy link
@kozec

kozec Nov 3, 2018

Owner

Hey @bebehei, I've just found that this call is reason why ST-GTK needs ~30s to start and reload settings, because that's time Notify.get_server_caps() needs to give up before returning empty list.

Why was this needed in 1st place?

This comment has been minimized.

Copy link
@catb0t

catb0t Nov 3, 2018

If you mean why SERVER_CAPS were necessary, it fixed the thing reported in #478

This comment has been minimized.

Copy link
@bebehei

bebehei Nov 4, 2018

Author Contributor

Sorry for the late reply.

Like @catb0t outlined, SERVER_CAPS are necessary to know, if the notification daemon actually can understand html hyperlinks.

If that thing is taking 30s, it's probably hitting a timeout and is either a problem by the notification server, which is not sticking to the spec (or something going on weirdly in DBus). The deepin linux notification server even had a typo in its function.

This comment has been minimized.

Copy link
@kozec

kozec Nov 4, 2018

Owner

@bebehei Yeah, I guessed that 30s (I measured it) is too specific to not be a timeout :) But this makes that call really non-acceptable kind of problem, especially when I'm trying to debug something. I've "fixed" it with this - a3502fd - but if you happen to know how to fix it for real, I'm up for anything.

This comment has been minimized.

Copy link
@bebehei

bebehei Nov 4, 2018

Author Contributor

Ok, @kozec. The more accurate way would be: Tell me which notification server it is and I'll figure out the problem there.

# Prepare stuff
self.app = app
self.daemon = daemon
Expand Down Expand Up @@ -104,9 +109,14 @@ def cb_syncthing_error(self, daemon, message):
def cb_syncthing_folder_rejected(self, daemon, nid, rid, label):
if nid in self.app.devices:
device = self.app.devices[nid].get_title()
markup_dev = device
markup_fol = (label or rid)
if "body-markup" in SERVER_CAPS:
markup_dev = "<b>%s</b>" % device
markup_fol = "<b>%s</b>" % (label or rid)
markup = _('Unexpected folder "%(folder)s" sent from device "%(device)s".') % {
'device' : "<b>%s</b>" % device,
'folder' : "<b>%s</b>" % (label or rid)
'device' : markup_dev,
'folder' : markup_fol
}
self.info(markup)

Expand Down Expand Up @@ -159,9 +169,13 @@ def display(self):
# One updated file
f_path = list(self.updated)[0]
filename = os.path.split(f_path)[-1]
if "body-hyperlinks" in SERVER_CAPS:
link = "<a href='file://%s'>%s</a>" % (f_path.encode('unicode-escape'), filename)
else:
link = f_path
self.info(_("%(hostname)s: Downloaded '%(filename)s' to reflect remote changes.") % {
'hostname' : self.app.get_local_name(),
'filename' : "<a href='file://%s'>%s</a>" % (f_path.encode('unicode-escape'), filename)
'filename' : link
})
elif len(self.updated) == 0 and len(self.deleted) == 1:
# One deleted file
Expand Down

0 comments on commit d352ce1

Please sign in to comment.