summaryrefslogtreecommitdiff
path: root/script/service
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/service
parent5a9ad795aa7ad952cf6846ea07a05a2b6717f376 (diff)
downloadlua-language-server-7203c44d10a6bf22e493f0b816fcbd5ebd475449.zip
check config and unique token
Diffstat (limited to 'script/service')
-rw-r--r--script/service/telemetry.lua22
1 files changed, 17 insertions, 5 deletions
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)