diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index ee2b4eb2b..bb423c45f 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -190,6 +190,11 @@ func main() { log.Printf("error ensuring wave db dir: %v\n", err) return } + err = wavebase.EnsureWaveConfigDir() + if err != nil { + log.Printf("error ensuring wave config dir: %v\n", err) + return + } waveLock, err := wavebase.AcquireWaveLock() if err != nil { log.Printf("error acquiring wave lock (another instance of Wave is likely running): %v\n", err) diff --git a/frontend/app/element/toggle.less b/frontend/app/element/toggle.less index 33c9766fc..e66dbc43c 100644 --- a/frontend/app/element/toggle.less +++ b/frontend/app/element/toggle.less @@ -54,7 +54,8 @@ } } - label { + label, + .toggle-label { cursor: pointer; padding: 0 5px; } diff --git a/frontend/app/element/toggle.tsx b/frontend/app/element/toggle.tsx index 25d6b31ae..939776a56 100644 --- a/frontend/app/element/toggle.tsx +++ b/frontend/app/element/toggle.tsx @@ -1,6 +1,7 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { useRef } from "react"; import "./toggle.less"; interface ToggleProps { @@ -11,24 +12,32 @@ interface ToggleProps { } const Toggle = ({ checked, onChange, label, id }: ToggleProps) => { + const inputRef = useRef(null); + const handleChange = (e: any) => { if (onChange != null) { onChange(e.target.checked); } }; + const handleLabelClick = () => { + if (inputRef.current) { + inputRef.current.click(); + } + }; + const inputId = id || `toggle-${Math.random().toString(36).substr(2, 9)}`; return (
-
- +
+ {label && ( - + )}
); diff --git a/frontend/app/modals/tos.tsx b/frontend/app/modals/tos.tsx index 16d7889ef..83faa1a03 100644 --- a/frontend/app/modals/tos.tsx +++ b/frontend/app/modals/tos.tsx @@ -4,21 +4,46 @@ import Logo from "@/app/asset/logo.svg"; import { Button } from "@/app/element/button"; import { Toggle } from "@/app/element/toggle"; +import { WshServer } from "@/app/store/wshserver"; import * as services from "@/store/services"; +import { useEffect, useState } from "react"; import { FlexiModal } from "./modal"; -import { WshServer } from "@/app/store/wshserver"; import "./tos.less"; const TosModal = () => { + const [telemetryEnabled, setTelemetryEnabled] = useState(true); + const acceptTos = () => { services.ClientService.AgreeTos(); }; function setTelemetry(value: boolean) { - WshServer.SetConfigCommand({ "telemetry:enabled": value }); + WshServer.SetConfigCommand({ "telemetry:enabled": value }) + .then(() => { + setTelemetryEnabled(value); + }) + .catch((error) => { + console.error("failed to set telemetry:", error); + }); } + useEffect(() => { + services.FileService.GetFullConfig() + .then((data) => { + if ("telemetry:enabled" in data.settings) { + setTelemetryEnabled(true); + } else { + setTelemetryEnabled(false); + } + }) + .catch((error) => { + console.error("failed to get config:", error); + }); + }, []); + + const label = telemetryEnabled ? "Telemetry enabled" : "Telemetry disabled"; + return (
@@ -81,7 +106,7 @@ const TosModal = () => { to help us understand how people are using Wave.
- + diff --git a/pkg/wavebase/wavebase.go b/pkg/wavebase/wavebase.go index 5cb50aaa9..2ae6f1be6 100644 --- a/pkg/wavebase/wavebase.go +++ b/pkg/wavebase/wavebase.go @@ -33,6 +33,7 @@ const WaveLockFile = "wave.lock" const DomainSocketBaseName = "wave.sock" const WaveDBDir = "db" const JwtSecret = "waveterm" // TODO generate and store this +const ConfigDir = "config" var baseLock = &sync.Mutex{} var ensureDirCache = map[string]bool{} @@ -95,6 +96,10 @@ func EnsureWaveDBDir() error { return CacheEnsureDir(filepath.Join(GetWaveHomeDir(), WaveDBDir), "wavedb", 0700, "wave db directory") } +func EnsureWaveConfigDir() error { + return CacheEnsureDir(filepath.Join(GetWaveHomeDir(), ConfigDir), "waveconfig", 0700, "wave config directory") +} + func CacheEnsureDir(dirName string, cacheKey string, perm os.FileMode, dirDesc string) error { baseLock.Lock() ok := ensureDirCache[cacheKey] diff --git a/pkg/wconfig/filewatcher.go b/pkg/wconfig/filewatcher.go index 6694f140f..09034d4dc 100644 --- a/pkg/wconfig/filewatcher.go +++ b/pkg/wconfig/filewatcher.go @@ -14,9 +14,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/wavebase" ) -const configDir = "config" - -var configDirAbsPath = filepath.Join(wavebase.GetWaveHomeDir(), configDir) +var configDirAbsPath = filepath.Join(wavebase.GetWaveHomeDir(), wavebase.ConfigDir) var instance *Watcher var once sync.Once