1
1
# -*- coding: utf-8 -*-
2
2
# Copyright (c) 2017-2024 Manuel Schneider
3
3
4
+ import os
5
+ import shutil
6
+
4
7
from albert import *
5
8
6
9
md_iid = '2.0'
7
- md_version = '1.3 '
10
+ md_version = '1.4 '
8
11
md_name = 'GoldenDict'
9
- md_description = 'Searches in GoldenDict'
12
+ md_description = 'Quick access to GoldenDict'
10
13
md_license = 'MIT'
11
- md_url = 'https://github.com/albertlauncher/python/'
14
+ md_url = 'https://github.com/albertlauncher/python/tree/main/goldendict '
12
15
md_authors = '@manuelschneid3r'
13
- md_bin_dependencies = ['goldendict' ]
14
16
15
17
16
18
class Plugin (PluginInstance , TriggerQueryHandler ):
@@ -20,22 +22,36 @@ def __init__(self):
20
22
id = md_id ,
21
23
name = md_name ,
22
24
description = md_description ,
23
- synopsis = 'query' ,
24
25
defaultTrigger = 'gd ' )
25
26
PluginInstance .__init__ (self , extensions = [self ])
26
- self .iconUrls = ["xdg:goldendict" ]
27
27
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 } " )
32
46
47
+ def handleTriggerQuery (self , query : TriggerQuery ):
48
+ q = query .string .strip ()
33
49
query .add (
34
50
StandardItem (
35
51
id = md_name ,
36
52
text = md_name ,
37
- subtext = f' Look up { query_str } using <i> GoldenDict</i>' ,
53
+ subtext = f" Look up ' { q } ' in GoldenDict" ,
38
54
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 ]))],
40
56
)
41
57
)
0 commit comments