[jhbuild] Don't crash when the notification service is not available



commit 77c053ccb950d283ca912ffc6362ef53add9a929
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat May 2 17:16:48 2015 +0800

    Don't crash when the notification service is not available
    
    It is possible that the notification service become unavailable during the
    build, typically caused by the gnome-shell crash. It is better to lose the
    notification than to crash jhbuild.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748440

 jhbuild/utils/notify.py |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/jhbuild/utils/notify.py b/jhbuild/utils/notify.py
index 67c2958..3ead4a6 100644
--- a/jhbuild/utils/notify.py
+++ b/jhbuild/utils/notify.py
@@ -43,18 +43,28 @@ class Notify:
         except dbus.exceptions.DBusException:
             return None
 
+    def reset(self):
+        self.notif_id = 0
+        self.iface = self.get_iface()
+
     def notify(self, summary, body, icon = "", expire = 0):
         '''emit a notification'''
         if self.disabled:
             return
 
-        self.notif_id = self.iface.Notify("jhbuild", self.notif_id, icon,
-                                          summary, body, [], {}, 1000*expire)
+        try:
+            self.notif_id = self.iface.Notify("jhbuild", self.notif_id, icon,
+                                              summary, body, [], {}, 1000*expire)
+        except dbus.exceptions.DBusException:
+            self.reset()
 
     def clear(self):
         if self.notif_id != 0:
-            self.iface.CloseNotification(self.notif_id)
-            self.notif_id = 0
+            try:
+                self.iface.CloseNotification(self.notif_id)
+                self.notif_id = 0
+            except dbus.exceptions.DBusException:
+                self.reset()
 
 if __name__ == "__main__":
     n = Notify()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]