@@ -18,25 +18,48 @@ gi.require_version('AppIndicator3', '0.1') # noqa
18
18
gi .require_version ('Notify' , '0.7' ) # noqa
19
19
from gi .repository import Gtk , AppIndicator3 , Notify
20
20
21
- from node_tools .helper_funcs import get_runtimedir
21
+ try :
22
+ from node_tools .helper_funcs import get_runtimedir
23
+ state_file = Path (get_runtimedir ()).joinpath ('fpnd.state' )
24
+ except ImportError :
25
+ import os
26
+ state_file = Path (os .path .join ('/run/fpnd' , 'fpnd.state' ))
22
27
23
28
24
29
APPINDICATOR_ID = 'fpndindicator'
25
- state_file = Path ( get_runtimedir ()). joinpath ( 'fpnd.state' )
30
+ APP_VERSION = '0.0.4'
26
31
27
32
28
33
def get_state_icon (state ):
29
34
"""
30
35
Look up the state msg and return the icon name.
31
36
"""
32
- state_dict = {
37
+ install_path = '/usr/share/icons/hicolor/scalable/status'
38
+ icon_name = 'network-freepn-connected-symbolic.svg'
39
+
40
+ fallback_dict = {
33
41
'CONNECTED' : 'network-vpn-symbolic' ,
34
- 'WAITING' : 'network-vpn-acquiring -symbolic' ,
35
- 'CONFIG' : 'network-vpn-no-route -symbolic' ,
42
+ 'WAITING' : 'network-vpn-no-route -symbolic' ,
43
+ 'CONFIG' : 'network-vpn-acquiring -symbolic' ,
36
44
'ERROR' : 'network-error-symbolic' ,
37
- 'STARTING' : 'network-idle -symbolic' ,
45
+ 'STARTING' : 'network-vpn-acquiring -symbolic' ,
38
46
'NONE' : 'network-offline-symbolic'
39
47
}
48
+
49
+ freepn_dict = {
50
+ 'CONNECTED' : 'network-freepn-connected-symbolic' ,
51
+ 'WAITING' : 'network-freepn-no-route-symbolic' ,
52
+ 'CONFIG' : 'network-freepn-acquiring-symbolic' ,
53
+ 'ERROR' : 'network-freepn-error-symbolic' ,
54
+ 'STARTING' : 'network-freepn-acquiring-symbolic' ,
55
+ 'NONE' : 'network-freepn-offline-symbolic'
56
+ }
57
+
58
+ state_dict = freepn_dict
59
+ connected_icon = Path (install_path ).joinpath (icon_name )
60
+ if not connected_icon .exists ():
61
+ state_dict = fallback_dict
62
+
40
63
return state_dict .get (state , state_dict ['NONE' ])
41
64
42
65
@@ -143,6 +166,7 @@ class Indicator():
143
166
Check for new state msg and update icon if new.
144
167
"""
145
168
old_state = 'NONE'
169
+ new_state = 'NONE'
146
170
guide = '999999999'
147
171
148
172
while True :
@@ -152,8 +176,7 @@ class Indicator():
152
176
new_state = msg_queue .pop ().strip ()
153
177
# if there is a change in state, update the icon
154
178
if old_state != new_state :
155
- icon_name = get_state_icon (new_state )
156
- self .indicator .set_icon_full (icon_name , new_state )
179
+ self .indicator .set_icon_full (get_state_icon (new_state ), new_state )
157
180
# Notify.Notification.new(new_state, None, None).show()
158
181
# note the second label arg should be the longest possible label str
159
182
self .indicator .set_label (new_state .format ().center (9 ), guide )
@@ -184,13 +207,34 @@ class Indicator():
184
207
item_separator = Gtk .SeparatorMenuItem ()
185
208
menu .append (item_separator )
186
209
210
+ item_about = Gtk .MenuItem (label = 'About' )
211
+ item_about .connect ('activate' , self .about )
212
+ menu .append (item_about )
213
+
187
214
item_quit = Gtk .MenuItem (label = 'Quit' )
188
215
item_quit .connect ('activate' , self .stop )
189
216
menu .append (item_quit )
190
217
191
218
menu .show_all ()
192
219
return menu
193
220
221
+ def about (self , source ):
222
+ dlg = Gtk .AboutDialog ()
223
+ dlg .set_name ('About...' )
224
+ dlg .set_program_name ('freepn-gtk3-indicator' )
225
+ dlg .set_version (APP_VERSION )
226
+ dlg .set_copyright ('© 2019-2020 The FreePN Team' )
227
+ dlg .set_license_type (Gtk .License .AGPL_3_0 )
228
+ dlg .set_logo_icon_name ('freepn' )
229
+ dlg .set_website ('https://github.com/freepn' )
230
+ dlg .set_comments ("""
231
+ FreePN network daemon control and status tool.
232
+ """ )
233
+ dlg .
set_authors ([
'Stephen L Arnold <[email protected] >' ])
234
+ dlg .
set_artists ([
'Marianne Cruzat <[email protected] >' ])
235
+ dlg .run ()
236
+ dlg .hide ()
237
+
194
238
def stop (self , source ):
195
239
Notify .uninit ()
196
240
Gtk .main_quit ()
@@ -215,6 +259,7 @@ class Indicator():
215
259
svc_msg = run_service_cmd (action = 'stop' )
216
260
if not svc_msg :
217
261
svc_msg = 'Stopping...'
262
+ self .indicator .set_icon_full (get_state_icon ('NONE' ), 'NONE' )
218
263
Notify .Notification .new ("Daemon status" , svc_msg , None ).show ()
219
264
220
265
0 commit comments