@@ -5,6 +5,9 @@ local client = require 'provider.client'
5
5
local nonil = require ' without-check-nil'
6
6
local util = require ' utility'
7
7
local platform = require ' bee.platform'
8
+ local proto = require ' proto.proto'
9
+ local lang = require ' language'
10
+ local define = require ' proto.define'
8
11
9
12
local tokenPath = (ROOT / ' log' / ' token' ):string ()
10
13
local token = util .loadFile (tokenPath )
@@ -85,3 +88,63 @@ timer.wait(5, function ()
85
88
net .update ()
86
89
end )
87
90
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