Skip to content

Commit da0b761

Browse files
[goldendict:1.4] Support flatpaks and goldendict-ng
1 parent faeddaf commit da0b761

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

goldendict/__init__.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) 2017-2024 Manuel Schneider
33

4+
import os
5+
import shutil
6+
47
from albert import *
58

69
md_iid = '2.0'
7-
md_version = '1.3'
10+
md_version = '1.4'
811
md_name = 'GoldenDict'
9-
md_description = 'Searches in GoldenDict'
12+
md_description = 'Quick access to GoldenDict'
1013
md_license = 'MIT'
11-
md_url = 'https://github.com/albertlauncher/python/'
14+
md_url = 'https://github.com/albertlauncher/python/tree/main/goldendict'
1215
md_authors = '@manuelschneid3r'
13-
md_bin_dependencies = ['goldendict']
1416

1517

1618
class Plugin(PluginInstance, TriggerQueryHandler):
@@ -20,22 +22,36 @@ def __init__(self):
2022
id=md_id,
2123
name=md_name,
2224
description=md_description,
23-
synopsis='query',
2425
defaultTrigger='gd ')
2526
PluginInstance.__init__(self, extensions=[self])
26-
self.iconUrls = ["xdg:goldendict"]
2727

28-
def handleTriggerQuery(self, query: TriggerQuery) -> None:
29-
query_str = query.string.strip()
30-
if not query_str:
31-
return
28+
commands = [
29+
'/var/lib/flatpak/exports/bin/org.goldendict.GoldenDict', # flatpak
30+
'/var/lib/flatpak/exports/bin/io.github.xiaoyifang.goldendict_ng', # flatpak ng
31+
'goldendict', # native
32+
'goldendict-ng', # native ng
33+
]
34+
35+
executables = [e for e in [shutil.which(c) for c in commands] if e]
36+
37+
if not executables:
38+
raise RuntimeError(f'None of the GoldenDict distributions found.')
39+
40+
self.executable = executables[0]
41+
self.iconUrls = [f'xdg:{os.path.basename(self.executable)}']
42+
43+
if len(executables) > 1:
44+
warning(f"Multiple GoldenDict commands found: {', '.join(executables)}")
45+
warning(f"Using {self.executable}")
3246

47+
def handleTriggerQuery(self, query: TriggerQuery):
48+
q = query.string.strip()
3349
query.add(
3450
StandardItem(
3551
id=md_name,
3652
text=md_name,
37-
subtext=f'Look up {query_str} using <i>GoldenDict</i>',
53+
subtext=f"Look up '{q}' in GoldenDict",
3854
iconUrls=self.iconUrls,
39-
actions=[Action(md_name, md_name, lambda: runDetachedProcess(['goldendict', query_str]))],
55+
actions=[Action(md_name, md_name, lambda e=self.executable: runDetachedProcess([e, q]))],
4056
)
4157
)

0 commit comments

Comments
 (0)