Skip to content

Commit add1ab2

Browse files
committed
ask for loading plugin
1 parent 81bb05d commit add1ab2

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

locale/en-us/script.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,14 @@ An error occurred in the plugin, please report it to the plugin author.
254254
Please check the details in the output or log.
255255
Plugin path: {}
256256
]]
257+
PLUGIN_TRUST_LOAD = [[
258+
The current settings try to load the plugin at this location:{}
259+
260+
Note that malicious plugin may harm your computer
261+
]]
262+
PLUGIN_TRUST_YES = [[
263+
Trust and load this plugin
264+
]]
265+
PLUGIN_TRUST_NO = [[
266+
Don't load this plugin
267+
]]

locale/zh-cn/script.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,14 @@ PLUGIN_RUNTIME_ERROR = [[
253253
请在输出或日志中查看详细信息。
254254
插件路径:{}
255255
]]
256+
PLUGIN_TRUST_LOAD = [[
257+
当前设置试图加载位于此位置的插件:{}
258+
259+
注意,恶意的插件可能会危害您的电脑
260+
]]
261+
PLUGIN_TRUST_YES = [[
262+
信任并加载插件
263+
]]
264+
PLUGIN_TRUST_NO = [[
265+
不要加载此插件
266+
]]

script/plugin.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ end
5252

5353
local function checkTrustLoad()
5454
local filePath = LOGPATH .. '/trusted'
55-
local trusted = util.loadFile(filePath) or ''
55+
local trusted = util.loadFile(filePath)
5656
local lines = {}
57-
for line in util.eachLine(trusted) do
58-
lines[#lines+1] = line
59-
if line == m.pluginPath then
60-
return true
57+
if trusted then
58+
for line in util.eachLine(trusted) do
59+
lines[#lines+1] = line
60+
if line == m.pluginPath then
61+
return true
62+
end
6163
end
6264
end
6365
local _, index = client.awaitRequestMessage('Warning', lang.script('PLUGIN_TRUST_LOAD', m.pluginPath), {
@@ -73,6 +75,10 @@ local function checkTrustLoad()
7375
end
7476

7577
function m.init()
78+
if m.hasInited then
79+
return
80+
end
81+
m.hasInited = true
7682
await.call(function ()
7783
local ws = require 'workspace'
7884
m.interface = {}

0 commit comments

Comments
 (0)