From 716d7dfde6e13d3192745a75fbc814f644e593e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 27 Mar 2021 17:43:49 +0800 Subject: fix telemetry window blocks initializing --- script/service/telemetry.lua | 85 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 41 deletions(-) (limited to 'script/service') diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua index 7248a9d9..30b26586 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -8,6 +8,7 @@ local platform = require 'bee.platform' local proto = require 'proto.proto' local lang = require 'language' local define = require 'proto.define' +local await = require 'await' local tokenPath = (ROOT / 'log' / 'token'):string() local token = util.loadFile(tokenPath) @@ -100,51 +101,53 @@ function m.updateConfig() end m.hasShowedMessage = true - if client.isVSCode() then - local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE - local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE - local item = proto.awaitRequest('window/showMessageRequest', { - message = lang.script.WINDOW_TELEMETRY_HINT, - type = define.MessageType.Info, - actions = { - { - title = enableTitle, - }, - { - title = disableTitle, - }, - } - }) - if not item then - return - end - if item.title == enableTitle then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.telemetry.enable', - action = 'set', - value = true, - global = true, + await.call(function () + if client.isVSCode() then + local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE + local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE + local item = proto.awaitRequest('window/showMessageRequest', { + message = lang.script.WINDOW_TELEMETRY_HINT, + type = define.MessageType.Info, + actions = { + { + title = enableTitle, + }, + { + title = disableTitle, + }, } }) - elseif item.title == disableTitle then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.telemetry.enable', - action = 'set', - value = false, - global = true, - } + if not item then + return + end + if item.title == enableTitle then + proto.notify('$/command', { + command = 'lua.config', + data = { + key = 'Lua.telemetry.enable', + action = 'set', + value = true, + global = true, + } + }) + elseif item.title == disableTitle then + proto.notify('$/command', { + command = 'lua.config', + data = { + key = 'Lua.telemetry.enable', + action = 'set', + value = false, + global = true, + } + }) + end + else + proto.notify('window/showMessage', { + message = lang.script.WINDOW_TELEMETRY_HINT, + type = define.MessageType.Info, }) end - else - proto.notify('window/showMessage', { - message = lang.script.WINDOW_TELEMETRY_HINT, - type = define.MessageType.Info, - }) - end + end) end return m -- cgit v1.2.3