Skip to content

Commit c8725d8

Browse files
committedAug 5, 2023
[vpn] Interface v2.0
1 parent 4bebd79 commit c8725d8

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed
 

‎vpn/__init__.py

+22-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from albert import *
2-
from collections import namedtuple
31
import subprocess
2+
from collections import namedtuple
3+
4+
from albert import *
45

5-
md_iid = '1.0'
6-
md_version = "1.3"
6+
md_iid = '2.0'
7+
md_version = "1.4"
78
md_id = "vpn"
89
md_name = "VPN"
910
md_description = "Manage NetworkManager VPN connections"
@@ -14,20 +15,17 @@
1415
md_bin_dependencies = ["nmcli"]
1516

1617

17-
class Plugin(TriggerQueryHandler):
18-
19-
iconPath = ['xdg:network-wired']
18+
class Plugin(PluginInstance, TriggerQueryHandler):
2019

2120
VPNConnection = namedtuple('VPNConnection', ['name', 'connected'])
2221

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])
3129

3230
def getVPNConnections(self):
3331
consStr = subprocess.check_output(
@@ -40,25 +38,24 @@ def getVPNConnections(self):
4038
if con[2] in ['vpn', 'wireguard']:
4139
yield self.VPNConnection(name=con[0], connected=con[3] != '')
4240

43-
44-
def buildItem(self,con):
41+
@staticmethod
42+
def buildItem(con):
4543
name = con.name
4644
command = 'down' if con.connected else 'up'
4745
text = f'Connect to {name}' if command == 'up' else f'Disconnect from {name}'
4846
commandline = ['nmcli', 'connection', command, 'id', name]
49-
return Item(
47+
return StandardItem(
5048
id=f'vpn-{command}-{name}',
5149
text=name,
5250
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))]
5654
)
5755

58-
59-
def handleTriggerQuery(self,query):
56+
def handleTriggerQuery(self, query):
6057
if query.isValid:
6158
connections = self.getVPNConnections()
6259
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

Comments
 (0)
Please sign in to comment.