summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
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)