Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 6267a91

Browse files
[syncthing] v3
1 parent 2aca84d commit 6267a91

1 file changed

Lines changed: 33 additions & 36 deletions

File tree

syncthing/__init__.py

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from albert import *
1111
from syncthing import Syncthing
1212

13-
md_iid = '2.3'
14-
md_version = "1.1"
13+
md_iid = "3.0"
14+
md_version = "2.0"
1515
md_name = "Syncthing"
1616
md_description = "Trigger basic syncthing actions."
1717
md_license = "MIT"
@@ -26,12 +26,16 @@ class Plugin(PluginInstance, GlobalQueryHandler):
2626

2727
def __init__(self):
2828
PluginInstance.__init__(self)
29-
GlobalQueryHandler.__init__(self, self.id, self.name, self.description, defaultTrigger='st ')
29+
GlobalQueryHandler.__init__(self)
30+
3031
self.iconUrls = ["xdg:syncthing", f"file:{Path(__file__).parent}/syncthing.svg"]
3132
self._api_key = self.readConfig(self.config_key, str)
3233
if self._api_key:
3334
self.st = Syncthing(self._api_key)
3435

36+
def defaultTrigger(self):
37+
return 'st '
38+
3539
@property
3640
def api_key(self) -> str:
3741
return self._api_key
@@ -84,7 +88,7 @@ def handleGlobalQuery(self, query):
8488
matcher = Matcher(query.string)
8589

8690
# create device items
87-
for id, d in devices.items():
91+
for device_id, d in devices.items():
8892
device_name = d['name']
8993

9094
if match := matcher.match(device_name):
@@ -94,50 +98,43 @@ def handleGlobalQuery(self, query):
9498
if d['paused']:
9599
actions.append(
96100
Action("resume", "Resume synchronization",
97-
lambda did=id: self.st.system.resume(did))
101+
lambda did=device_id: self.st.system.resume(did))
98102
)
99103
else:
100104
actions.append(
101105
Action("pause", "Pause synchronization",
102-
lambda did=id: self.st.system.pause(did))
106+
lambda did=device_id: self.st.system.pause(did))
103107
)
104108

105-
results.append(
106-
RankItem(
107-
StandardItem(
108-
id=id,
109-
text=f"{device_name}",
110-
subtext=f"{'Paused ' if d['paused'] else ''}Syncthing device. "
111-
f"Shared: {device_folders if device_folders else 'Nothing'}.",
112-
iconUrls=self.iconUrls,
113-
actions=actions
114-
),
115-
match.score
116-
)
109+
item = StandardItem(
110+
id=device_id,
111+
text=f"{device_name}",
112+
subtext=f"{'Paused ' if d['paused'] else ''}Syncthing device. "
113+
f"Shared: {device_folders if device_folders else 'Nothing'}.",
114+
iconUrls=self.iconUrls,
115+
actions=actions
117116
)
118117

118+
results.append(RankItem(item, match))
119+
119120
# create folder items
120-
for id, f in folders.items():
121+
for folder_id, f in folders.items():
121122
folder_name = f['label']
122123
if match := matcher.match(folder_name):
123124
folders_devices = ", ".join([devices[d['deviceID']]['name'] for d in f['devices']])
124-
results.append(
125-
RankItem(
126-
StandardItem(
127-
id=id,
128-
text=folder_name,
129-
subtext=f"Syncthing folder {f['path']}. "
130-
f"Shared with {folders_devices if folders_devices else 'nobody'}.",
131-
iconUrls=self.iconUrls,
132-
actions=[
133-
Action("scan", "Scan the folder",
134-
lambda fid=id: self.st.database.scan(fid)),
135-
Action("open", "Open this folder in file browser",
136-
lambda p=f['path']: openUrl(f'file://{p}'))
137-
]
138-
),
139-
match.score
140-
)
125+
item = StandardItem(
126+
id=folder_id,
127+
text=folder_name,
128+
subtext=f"Syncthing folder {f['path']}. "
129+
f"Shared with {folders_devices if folders_devices else 'nobody'}.",
130+
iconUrls=self.iconUrls,
131+
actions=[
132+
Action("scan", "Scan the folder",
133+
lambda fid=folder_id: self.st.database.scan(fid)),
134+
Action("open", "Open this folder in file browser",
135+
lambda p=f['path']: openFile(p))
136+
]
141137
)
138+
results.append(RankItem(item, match))
142139

143140
return results

0 commit comments

Comments
 (0)