1
- from .dbus import Client , DbusInitializationError
1
+ from .dbus import Client , DbusInitializationError , VersionIncompatibilityError
2
2
import sys
3
3
import traceback
4
4
import gi
@@ -23,12 +23,25 @@ def __init__(self):
23
23
traceback .print_exc ()
24
24
self ._startupFailure (f"Unexpected exception { e .__class__ .__name__ } " , str (e ))
25
25
raise e
26
+ self .dbus .serviceDisconnected .connect (self .dbusDisconnect )
27
+ self .dbus .serviceConnected .connect (self .dbusReconnect )
26
28
27
29
def _startupFailure (self , title , message ):
28
30
dialog = Gtk .MessageDialog (parent = self , message_type = Gtk .MessageType .ERROR , buttons = Gtk .ButtonsType .OK , text = title )
29
31
dialog .format_secondary_text (message )
30
32
dialog .run ()
31
33
34
+ def dbusDisconnect (self ):
35
+ self .setNoDevice ()
36
+
37
+ def dbusReconnect (self ):
38
+ try :
39
+ self .dbus .ensureServiceVersion ()
40
+ except VersionIncompatibilityError as e :
41
+ self ._startupFailure ("Dbus service version incompatibility" , "Restart of this gui application is required" )
42
+ Gtk .main_quit ()
43
+ # Todo: Can we relaunch ourselves?
44
+
32
45
def setDevice (self , dev ):
33
46
if self .dev is not None :
34
47
if self .dev ._path == dev ._path :
@@ -57,6 +70,7 @@ def setDevice(self, dev):
57
70
self .show_all ()
58
71
59
72
def setNoDevice (self ):
73
+ self .dev = None
60
74
if self .grid is not None :
61
75
self .remove (self .grid )
62
76
self .grid = Gtk .Grid ()
@@ -75,7 +89,6 @@ def deviceRemoved(self, path):
75
89
if self .dev ._path != path :
76
90
# Not our device
77
91
return
78
- self .dev = None
79
92
self .setNoDevice ()
80
93
81
94
def addHeading (self , text ):
0 commit comments