diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index cbe4b974a..40b730ad5 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -42,8 +42,8 @@ import ( var WaveVersion = "0.0.0" var BuildTime = "0" -const InitialTelemetryWait = 30 * time.Second -const TelemetryTick = 10 * time.Minute +const InitialTelemetryWait = 10 * time.Second +const TelemetryTick = 2 * time.Minute const TelemetryInterval = 4 * time.Hour const ReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID" diff --git a/frontend/app/modals/tos.tsx b/frontend/app/modals/tos.tsx index c7233f7c0..6bf238176 100644 --- a/frontend/app/modals/tos.tsx +++ b/frontend/app/modals/tos.tsx @@ -12,8 +12,6 @@ import { FlexiModal } from "./modal"; import { QuickTips } from "@/app/element/quicktips"; import { atoms } from "@/app/store/global"; import { modalsModel } from "@/app/store/modalmodel"; -import { RpcApi } from "@/app/store/wshclientapi"; -import { WindowRpcClient } from "@/app/store/wshrpcutil"; import { atom, PrimitiveAtom, useAtom, useAtomValue, useSetAtom } from "jotai"; import "./tos.less"; @@ -34,7 +32,7 @@ const ModalPage1 = () => { }; const setTelemetry = (value: boolean) => { - RpcApi.SetConfigCommand(WindowRpcClient, { "telemetry:enabled": value }) + services.ClientService.TelemetryUpdate(value) .then(() => { setTelemetryEnabled(value); }) diff --git a/frontend/app/store/services.ts b/frontend/app/store/services.ts index 549ea73c2..b158c858b 100644 --- a/frontend/app/store/services.ts +++ b/frontend/app/store/services.ts @@ -47,6 +47,9 @@ class ClientServiceType { MakeWindow(): Promise { return WOS.callBackendService("client", "MakeWindow", Array.from(arguments)) } + TelemetryUpdate(arg2: boolean): Promise { + return WOS.callBackendService("client", "TelemetryUpdate", Array.from(arguments)) + } } export const ClientService = new ClientServiceType(); diff --git a/pkg/service/clientservice/clientservice.go b/pkg/service/clientservice/clientservice.go index 757c0d00a..44638852a 100644 --- a/pkg/service/clientservice/clientservice.go +++ b/pkg/service/clientservice/clientservice.go @@ -6,11 +6,14 @@ package clientservice import ( "context" "fmt" + "log" "time" "github.com/wavetermdev/waveterm/pkg/remote/conncontroller" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wcloud" + "github.com/wavetermdev/waveterm/pkg/wconfig" "github.com/wavetermdev/waveterm/pkg/wcore" "github.com/wavetermdev/waveterm/pkg/wlayout" "github.com/wavetermdev/waveterm/pkg/wshrpc" @@ -106,3 +109,26 @@ func (cs *ClientService) AgreeTos(ctx context.Context) (waveobj.UpdatesRtnType, wlayout.BootstrapStarterLayout(ctx) return waveobj.ContextGetUpdatesRtn(ctx), nil } + +func (cs *ClientService) TelemetryUpdate(ctx context.Context, telemetryEnabled bool) error { + meta := waveobj.MetaMapType{ + wconfig.ConfigKey_TelemetryEnabled: telemetryEnabled, + } + err := wconfig.SetBaseConfigValue(meta) + if err != nil { + return fmt.Errorf("error setting telemetry value: %w", err) + } + clientData, err := wstore.DBGetSingleton[*waveobj.Client](ctx) + if err != nil { + return fmt.Errorf("error getting client data: %w", err) + } + if clientData == nil { + return fmt.Errorf("client data is nil") + } + telemetryErr := wcloud.SendNoTelemetryUpdate(ctx, clientData.OID, !telemetryEnabled) + if telemetryErr != nil { + // don't return error here, just log + log.Printf("[error] sending telemetry update: %v\n", telemetryErr) + } + return nil +} diff --git a/pkg/wcore/wcore.go b/pkg/wcore/wcore.go index 030724199..ee8d3ae30 100644 --- a/pkg/wcore/wcore.go +++ b/pkg/wcore/wcore.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/wavetermdev/waveterm/pkg/blockcontroller" + "github.com/wavetermdev/waveterm/pkg/telemetry" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wps" "github.com/wavetermdev/waveterm/pkg/wstore" @@ -172,9 +173,26 @@ func CreateClient(ctx context.Context) (*waveobj.Client, error) { } func CreateBlock(ctx context.Context, tabId string, blockDef *waveobj.BlockDef, rtOpts *waveobj.RuntimeOpts) (*waveobj.Block, error) { + if blockDef == nil { + return nil, fmt.Errorf("blockDef is nil") + } + if blockDef.Meta == nil || blockDef.Meta.GetString(waveobj.MetaKey_View, "") == "" { + return nil, fmt.Errorf("no view provided for new block") + } blockData, err := wstore.CreateBlock(ctx, tabId, blockDef, rtOpts) if err != nil { return nil, fmt.Errorf("error creating block: %w", err) } + go func() { + blockView := blockDef.Meta.GetString(waveobj.MetaKey_View, "") + if blockView == "" { + return + } + tctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) + defer cancelFn() + telemetry.UpdateActivity(tctx, telemetry.ActivityUpdate{ + Renderers: map[string]int{blockView: 1}, + }) + }() return blockData, nil }