1
- from albert import *
2
- from collections import namedtuple
3
1
import subprocess
2
+ from collections import namedtuple
3
+
4
+ from albert import *
4
5
5
- md_iid = '1 .0'
6
- md_version = "1.3 "
6
+ md_iid = '2 .0'
7
+ md_version = "1.4 "
7
8
md_id = "vpn"
8
9
md_name = "VPN"
9
10
md_description = "Manage NetworkManager VPN connections"
14
15
md_bin_dependencies = ["nmcli" ]
15
16
16
17
17
- class Plugin (TriggerQueryHandler ):
18
-
19
- iconPath = ['xdg:network-wired' ]
18
+ class Plugin (PluginInstance , TriggerQueryHandler ):
20
19
21
20
VPNConnection = namedtuple ('VPNConnection' , ['name' , 'connected' ])
22
21
23
- def id (self ):
24
- return md_id
25
-
26
- def name (self ):
27
- return md_name
28
-
29
- def description (self ):
30
- return md_description
22
+ def __init__ (self ):
23
+ TriggerQueryHandler .__init__ (self ,
24
+ id = md_id ,
25
+ name = md_name ,
26
+ description = md_description ,
27
+ defaultTrigger = 'vpn ' )
28
+ PluginInstance .__init__ (self , extensions = [self ])
31
29
32
30
def getVPNConnections (self ):
33
31
consStr = subprocess .check_output (
@@ -40,25 +38,24 @@ def getVPNConnections(self):
40
38
if con [2 ] in ['vpn' , 'wireguard' ]:
41
39
yield self .VPNConnection (name = con [0 ], connected = con [3 ] != '' )
42
40
43
-
44
- def buildItem (self , con ):
41
+ @ staticmethod
42
+ def buildItem (con ):
45
43
name = con .name
46
44
command = 'down' if con .connected else 'up'
47
45
text = f'Connect to { name } ' if command == 'up' else f'Disconnect from { name } '
48
46
commandline = ['nmcli' , 'connection' , command , 'id' , name ]
49
- return Item (
47
+ return StandardItem (
50
48
id = f'vpn-{ command } -{ name } ' ,
51
49
text = name ,
52
50
subtext = text ,
53
- icon = self . iconPath ,
54
- completion = name ,
55
- actions = [ Action ("run" ,text = text , callable = lambda : runDetachedProcess (commandline )) ]
51
+ iconUrls = [ 'xdg:network-wired' ] ,
52
+ inputActionText = name ,
53
+ actions = [Action ("run" , text = text , callable = lambda : runDetachedProcess (commandline ))]
56
54
)
57
55
58
-
59
- def handleTriggerQuery (self ,query ):
56
+ def handleTriggerQuery (self , query ):
60
57
if query .isValid :
61
58
connections = self .getVPNConnections ()
62
59
if query .string :
63
- connections = [ con for con in connections if query .string .lower () in con .name .lower () ]
64
- query .add ([ self .buildItem (con ) for con in connections ])
60
+ connections = [con for con in connections if query .string .lower () in con .name .lower ()]
61
+ query .add ([self .buildItem (con ) for con in connections ])
0 commit comments