summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-15 11:16:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-15 11:16:57 +0800
commit7203c44d10a6bf22e493f0b816fcbd5ebd475449 (patch)
treeb32e3127edec793a8ea503093325063bfcc3056b /script
parent5a9ad795aa7ad952cf6846ea07a05a2b6717f376 (diff)
downloadlua-language-server-7203c44d10a6bf22e493f0b816fcbd5ebd475449.zip
check config and unique token
Diffstat (limited to 'script')
-rw-r--r--script/config.lua3
-rw-r--r--script/service/telemetry.lua22
2 files changed, 20 insertions, 5 deletions
diff --git a/script/config.lua b/script/config.lua
index 298083a4..c9d8e075 100644
--- a/script/config.lua
+++ b/script/config.lua
@@ -150,6 +150,9 @@ local ConfigTemplate = {
intelliSense = {
searchDepth = {0, Integer},
},
+ telemetry = {
+ enable = {true, Boolean},
+ }
}
local OtherTemplate = {
diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua
index 5b9bbd5d..2434cf1a 100644
--- a/script/service/telemetry.lua
+++ b/script/service/telemetry.lua
@@ -3,10 +3,16 @@ local timer = require 'timer'
local config = require 'config'
local client = require 'provider.client'
local nonil = require 'without-check-nil'
+local util = require 'utility'
-local token = ('%016X'):format(math.random(0, math.maxinteger))
-local function push()
- local link = net.connect('tcp', '119.45.194.183', 11577)
+local tokenPath = (ROOT / 'log' / 'token'):string()
+local token = util.loadFile(tokenPath)
+if not token then
+ token = ('%016X'):format(math.random(0, math.maxinteger))
+ util.saveFile(token)
+end
+
+local function pushClient(link)
nonil.enable()
local clientName = client.info.clientInfo.name
local clientVersion = client.info.clientInfo.version
@@ -16,9 +22,15 @@ local function push()
, token
, table.concat({clientName, clientVersion}, ' ')
))
- net.update()
end
timer.wait(5, function ()
- timer.loop(60, push)()
+ timer.loop(60, function ()
+ if not config.config.telemetry.enable then
+ return
+ end
+ local link = net.connect('tcp', '119.45.194.183', 11577)
+ pushClient(link)
+ net.update()
+ end)()
end)