mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-21 21:32:13 +01:00
telemetry fix (#365)
This commit is contained in:
parent
c3a02d7e33
commit
df2af04a6e
@ -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)
|
||||
|
@ -54,7 +54,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
label,
|
||||
.toggle-label {
|
||||
cursor: pointer;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
@ -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<HTMLInputElement>(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 (
|
||||
<div className="check-toggle-wrapper">
|
||||
<div className="checkbox-toggle">
|
||||
<input id={inputId} type="checkbox" checked={checked} onChange={handleChange} />
|
||||
<label htmlFor={inputId} className="checkbox-toggle">
|
||||
<input id={inputId} type="checkbox" checked={checked} onChange={handleChange} ref={inputRef} />
|
||||
<span className="slider" />
|
||||
</div>
|
||||
{label && (
|
||||
<label htmlFor={inputId} className="toggle-label">
|
||||
{label}
|
||||
</label>
|
||||
{label && (
|
||||
<span className="toggle-label" onClick={handleLabelClick}>
|
||||
{label}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
@ -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<boolean>(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 (
|
||||
<FlexiModal className="tos-modal">
|
||||
<div className="modal-inner">
|
||||
@ -81,7 +106,7 @@ const TosModal = () => {
|
||||
</a>
|
||||
to help us understand how people are using Wave.
|
||||
</div>
|
||||
<Toggle checked={true} onChange={setTelemetry} label="Telemetry enabled" />
|
||||
<Toggle checked={telemetryEnabled} onChange={setTelemetry} label={label} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user