@@ -41,6 +41,34 @@ local function getLinkOpener()
4141 return enabled , tool
4242end
4343
44+ -- differentiate between urls and commands
45+ local function isUrl (s )
46+ if type (s ) == " string" and s :match (" *?://" ) then
47+ return true
48+ end
49+ return false
50+ end
51+
52+ local EXTERNAL_DICTS_AVAILABILITY_CHECKED = false
53+ local EXTERNAL_DICTS = require (" device/sdl/dictionaries" )
54+ local external_dict_when_back_callback = nil
55+
56+ local function getExternalDicts ()
57+ if not EXTERNAL_DICTS_AVAILABILITY_CHECKED then
58+ EXTERNAL_DICTS_AVAILABILITY_CHECKED = true
59+ for i , v in ipairs (EXTERNAL_DICTS ) do
60+ local tool = v [4 ]
61+ if not tool then return end
62+ if isUrl (tool ) and getLinkOpener ()
63+ or os.execute (" which " .. tool ) == 0 then
64+ v [3 ] = true
65+ end
66+ end
67+ end
68+ return EXTERNAL_DICTS
69+ end
70+
71+
4472local Device = Generic :new {
4573 model = " SDL" ,
4674 isSDL = yes ,
@@ -56,7 +84,28 @@ local Device = Generic:new{
5684 openLink = function (self , link )
5785 local enabled , tool = getLinkOpener ()
5886 if not enabled or not tool or not link or type (link ) ~= " string" then return end
59- return os.execute (' LD_LIBRARY_PATH="" ' .. tool .. " '" .. link .. " '" ) == 0
87+ return os.execute (' env -u LD_LIBRARY_PATH ' .. tool .. " '" .. link .. " '" ) == 0
88+ end ,
89+ canExternalDictLookup = yes ,
90+ getExternalDictLookupList = getExternalDicts ,
91+ doExternalDictLookup = function (self , text , method , callback )
92+ external_dict_when_back_callback = callback
93+ local tool , ok = nil
94+ for i , v in ipairs (getExternalDicts ()) do
95+ if v [1 ] == method then
96+ tool = v [4 ]
97+ break
98+ end
99+ end
100+ if isUrl (tool ) and getLinkOpener () then
101+ ok = self :openLink (tool .. text )
102+ else
103+ ok = os.execute (' env -u LD_LIBRARY_PATH ' .. tool .. " " .. text .. " &" ) == 0
104+ end
105+ if ok and external_dict_when_back_callback then
106+ external_dict_when_back_callback ()
107+ external_dict_when_back_callback = nil
108+ end
60109 end ,
61110}
62111
0 commit comments