@@ -2,6 +2,7 @@ local config = require 'config'
22local  util  =  require  ' utility' 
33local  client  =  require  ' client' 
44local  lang  =  require  ' language' 
5+ local  await  =  require  ' await' 
56
67--- @class  plugin 
78local  m  =  {}
@@ -49,34 +50,60 @@ local function resetFiles()
4950 end 
5051end 
5152
52- function  m .init ()
53-  local  ws  =  require  ' workspace' 
54-  m .interface  =  {}
55- 
56-  local  pluginPath  =  ws .getAbsolutePath (config .get  ' Lua.runtime.plugin' 
57-  log .info (' plugin path:' pluginPath )
58-  if  not  pluginPath  then 
59-  return 
60-  end 
61-  local  pluginLua  =  util .loadFile (pluginPath )
62-  if  not  pluginLua  then 
63-  return 
64-  end 
65-  m .pluginPath  =  pluginPath 
66-  local  env  =  setmetatable (m .interface , { __index  =  _ENV  })
67-  local  f , err  =  load (pluginLua , ' @' .. pluginPath , " t" env )
68-  if  not  f  then 
69-  log .error (err )
70-  m .showError (err )
71-  return 
53+ local  function  checkTrustLoad ()
54+  local  trusted  =  util .loadFile (LOGPATH  /  ' trusted' or  ' ' 
55+  local  lines  =  {}
56+  for  line  in  util .eachLine (trusted ) do 
57+  lines [# lines + 1 ] =  line 
58+  if  line  ==  m .pluginPath  then 
59+  return  true 
60+  end 
7261 end 
73-  local  suc , err  =  xpcall (f , log .error , f )
74-  if  not  suc  then 
75-  m .showError (err )
76-  return 
62+  local  _ , index  =  client .awaitRequestMessage (' Warning' lang .script (' PLUGIN_TRUST_LOAD' m .pluginPath ), {
63+  lang .script (' PLUGIN_TRUST_YES' 
64+  lang .script (' PLUGIN_TRUST_NO' 
65+  })
66+  if  not  index  then 
67+  return  false 
7768 end 
69+  lines [# lines + 1 ] =  m .pluginPath 
70+  util .saveFile (LOGPATH  /  ' trusted' table.concat (trusted , ' \n ' 
71+  return  true 
72+ end 
73+ 
74+ function  m .init ()
75+  await .call (function  ()
76+  local  ws  =  require  ' workspace' 
77+  m .interface  =  {}
78+ 
79+  local  pluginPath  =  ws .getAbsolutePath (config .get  ' Lua.runtime.plugin' 
80+  log .info (' plugin path:' pluginPath )
81+  if  not  pluginPath  then 
82+  return 
83+  end 
84+  local  pluginLua  =  util .loadFile (pluginPath )
85+  if  not  pluginLua  then 
86+  return 
87+  end 
88+  m .pluginPath  =  pluginPath 
89+  local  env  =  setmetatable (m .interface , { __index  =  _ENV  })
90+  local  f , err  =  load (pluginLua , ' @' .. pluginPath , " t" env )
91+  if  not  f  then 
92+  log .error (err )
93+  m .showError (err )
94+  return 
95+  end 
96+  if  not  checkTrustLoad () then 
97+  return 
98+  end 
99+  local  suc , err  =  xpcall (f , log .error , f )
100+  if  not  suc  then 
101+  m .showError (err )
102+  return 
103+  end 
78104
79-  resetFiles ()
105+  resetFiles ()
106+  end )
80107end 
81108
82109return  m 
0 commit comments