Skip to content

Commit 11b10d6

Browse files
committed
#462 show message of telemetry
1 parent c78d24c commit 11b10d6

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Diff for: script/provider/provider.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local tm = require 'text-merger'
2121

2222
local function updateConfig()
2323
local diagnostics = require 'provider.diagnostic'
24-
local vm = require 'vm'
24+
local telemetry = require 'service.telemetry'
2525
local configs = proto.awaitRequest('workspace/configuration', {
2626
items = {
2727
{
@@ -94,6 +94,7 @@ local function updateConfig()
9494
else
9595
proto.notify('$/status/hide')
9696
end
97+
telemetry.updateConfig()
9798
end
9899

99100
proto.on('initialize', function (params)

Diff for: script/service/telemetry.lua

+63
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ local client = require 'provider.client'
55
local nonil = require 'without-check-nil'
66
local util = require 'utility'
77
local platform = require 'bee.platform'
8+
local proto = require 'proto.proto'
9+
local lang = require 'language'
10+
local define = require 'proto.define'
811

912
local tokenPath = (ROOT / 'log' / 'token'):string()
1013
local token = util.loadFile(tokenPath)
@@ -85,3 +88,63 @@ timer.wait(5, function ()
8588
net.update()
8689
end)
8790
end)
91+
92+
local m = {}
93+
94+
function m.updateConfig()
95+
if config.config.telemetry.enable ~= nil then
96+
return
97+
end
98+
if m.hasShowedMessage then
99+
return
100+
end
101+
m.hasShowedMessage = true
102+
103+
if client.isVSCode() then
104+
local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE
105+
local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE
106+
local item = proto.awaitRequest('window/showMessageRequest', {
107+
message = lang.script.WINDOW_TELEMETRY_HINT,
108+
type = define.MessageType.Info,
109+
actions = {
110+
{
111+
title = enableTitle,
112+
},
113+
{
114+
title = disableTitle,
115+
},
116+
}
117+
})
118+
if not item then
119+
return
120+
end
121+
if item.title == enableTitle then
122+
proto.notify('$/command', {
123+
command = 'lua.config',
124+
data = {
125+
key = 'Lua.telemetry.enable',
126+
action = 'set',
127+
value = true,
128+
global = true,
129+
}
130+
})
131+
elseif item.title == disableTitle then
132+
proto.notify('$/command', {
133+
command = 'lua.config',
134+
data = {
135+
key = 'Lua.telemetry.enable',
136+
action = 'set',
137+
value = false,
138+
global = true,
139+
}
140+
})
141+
end
142+
else
143+
proto.notify('window/showMessage', {
144+
message = lang.script.WINDOW_TELEMETRY_HINT,
145+
type = define.MessageType.Info,
146+
})
147+
end
148+
end
149+
150+
return m

0 commit comments

Comments
 (0)