Skip to content

Commit 49c9d70

Browse files
authored
various fixes and enhancements for v0.12.2 (#2508)
1 parent b442b91 commit 49c9d70

File tree

11 files changed

+95
-37
lines changed

11 files changed

+95
-37
lines changed

cmd/server/main-server.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"log"
1010
"os"
11-
"strconv"
1211

1312
"runtime"
1413
"sync"
@@ -247,6 +246,21 @@ func startupActivityUpdate(firstLaunch bool) {
247246
shellType = "error"
248247
shellVersion = ""
249248
}
249+
userSetOnce := &telemetrydata.TEventUserProps{
250+
ClientInitialVersion: "v" + WaveVersion,
251+
}
252+
tosTs := telemetry.GetTosAgreedTs()
253+
var cohortTime time.Time
254+
if tosTs > 0 {
255+
cohortTime = time.UnixMilli(tosTs)
256+
} else {
257+
cohortTime = time.Now()
258+
}
259+
cohortMonth := cohortTime.Format("2006-01")
260+
year, week := cohortTime.ISOWeek()
261+
cohortISOWeek := fmt.Sprintf("%04d-W%02d", year, week)
262+
userSetOnce.CohortMonth = cohortMonth
263+
userSetOnce.CohortISOWeek = cohortISOWeek
250264
props := telemetrydata.TEventProps{
251265
UserSet: &telemetrydata.TEventUserProps{
252266
ClientVersion: "v" + WaveVersion,
@@ -259,9 +273,7 @@ func startupActivityUpdate(firstLaunch bool) {
259273
LocalShellType: shellType,
260274
LocalShellVersion: shellVersion,
261275
},
262-
UserSetOnce: &telemetrydata.TEventUserProps{
263-
ClientInitialVersion: "v" + WaveVersion,
264-
},
276+
UserSetOnce: userSetOnce,
265277
}
266278
if firstLaunch {
267279
props.AppFirstLaunch = true
@@ -339,18 +351,19 @@ func clearTempFiles() error {
339351
return nil
340352
}
341353

342-
func maybeStartPprofServer() error {
343-
pprofPortStr := os.Getenv("WAVETERM_PPROFPORT")
344-
if pprofPortStr == "" {
345-
return nil
354+
func maybeStartPprofServer() {
355+
settings := wconfig.GetWatcher().GetFullConfig().Settings
356+
if settings.DebugPprofMemProfileRate != nil {
357+
runtime.MemProfileRate = *settings.DebugPprofMemProfileRate
358+
log.Printf("set runtime.MemProfileRate to %d\n", runtime.MemProfileRate)
346359
}
347-
defer os.Unsetenv("WAVETERM_PPROFPORT")
348-
pprofPort, err := strconv.Atoi(pprofPortStr)
349-
if err != nil {
350-
return fmt.Errorf("invalid WAVETERM_PPROFPORT value '%s': %v", pprofPortStr, err)
360+
if settings.DebugPprofPort == nil {
361+
return
351362
}
363+
pprofPort := *settings.DebugPprofPort
352364
if pprofPort < 1 || pprofPort > 65535 {
353-
return fmt.Errorf("WAVETERM_PPROFPORT must be between 1 and 65535, got %d", pprofPort)
365+
log.Printf("[error] debug:pprofport must be between 1 and 65535, got %d\n", pprofPort)
366+
return
354367
}
355368
go func() {
356369
addr := fmt.Sprintf("localhost:%d", pprofPort)
@@ -359,22 +372,15 @@ func maybeStartPprofServer() error {
359372
log.Printf("[error] pprof server failed: %v\n", err)
360373
}
361374
}()
362-
return nil
363375
}
364376

365377
func main() {
366-
err := maybeStartPprofServer()
367-
if err != nil {
368-
log.Printf("[error] %v\n", err)
369-
return
370-
}
371-
372378
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
373379
log.SetPrefix("[wavesrv] ")
374380
wavebase.WaveVersion = WaveVersion
375381
wavebase.BuildTime = BuildTime
376382

377-
err = grabAndRemoveEnvVars()
383+
err := grabAndRemoveEnvVars()
378384
if err != nil {
379385
log.Printf("[error] %v\n", err)
380386
return
@@ -463,6 +469,7 @@ func main() {
463469
sigutil.InstallShutdownSignalHandlers(doShutdown)
464470
sigutil.InstallSIGUSR1Handler()
465471
startConfigWatcher()
472+
maybeStartPprofServer()
466473
go stdinReadWatch()
467474
go telemetryLoop()
468475
go updateTelemetryCountsLoop()

frontend/app/store/keymodel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@ function uxCloseBlock(blockId: string) {
152152
return;
153153
}
154154
}
155-
155+
156156
const blockAtom = WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", blockId));
157157
const blockData = globalStore.get(blockAtom);
158158
const isAIFileDiff = blockData?.meta?.view === "aifilediff";
159-
159+
160160
const layoutModel = getLayoutModelForStaticTab();
161161
const node = layoutModel.getNodeByBlockId(blockId);
162162
if (node) {
163163
fireAndForget(() => layoutModel.closeNode(node.id));
164-
164+
165165
if (isAIFileDiff && isAIPanelOpen) {
166166
setTimeout(() => WaveAIModel.getInstance().focusInput(), 50);
167167
}
@@ -199,16 +199,16 @@ function genericClose() {
199199
simpleCloseStaticTab();
200200
return;
201201
}
202-
202+
203203
const layoutModel = getLayoutModelForStaticTab();
204204
const focusedNode = globalStore.get(layoutModel.focusedNode);
205205
const blockId = focusedNode?.data?.blockId;
206206
const blockAtom = blockId ? WOS.getWaveObjectAtom<Block>(WOS.makeORef("block", blockId)) : null;
207207
const blockData = blockAtom ? globalStore.get(blockAtom) : null;
208208
const isAIFileDiff = blockData?.meta?.view === "aifilediff";
209-
209+
210210
fireAndForget(layoutModel.closeFocusedNode.bind(layoutModel));
211-
211+
212212
if (isAIFileDiff && isAIPanelOpen) {
213213
setTimeout(() => WaveAIModel.getInstance().focusInput(), 50);
214214
}

frontend/app/view/preview/preview-directory.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function DirectoryTable({
109109
newFile,
110110
newDirectory,
111111
}: DirectoryTableProps) {
112+
const searchActive = useAtomValue(model.directorySearchActive);
112113
const fullConfig = useAtomValue(atoms.fullConfigAtom);
113114
const setErrorMsg = useSetAtom(model.errorMsgAtom);
114115
const getIconFromMimeType = useCallback(
@@ -346,6 +347,7 @@ function TableBody({
346347
setRefreshVersion,
347348
osRef,
348349
}: TableBodyProps) {
350+
const searchActive = useAtomValue(model.directorySearchActive);
349351
const dummyLineRef = useRef<HTMLDivElement>(null);
350352
const warningBoxRef = useRef<HTMLDivElement>(null);
351353
const conn = useAtomValue(model.connection);
@@ -447,12 +449,15 @@ function TableBody({
447449

448450
return (
449451
<div className="dir-table-body" ref={bodyRef}>
450-
{search !== "" && (
451-
<div className="flex rounded-[3px] py-1 px-2 bg-warning" ref={warningBoxRef}>
452-
<span>Searching for "{search}"</span>
452+
{(searchActive || search !== "") && (
453+
<div className="flex rounded-[3px] py-1 px-2 bg-warning text-black" ref={warningBoxRef}>
454+
<span>{search === "" ? "Type to search (Esc to cancel)" : `Searching for "${search}"`}</span>
453455
<div
454456
className="ml-auto bg-transparent flex justify-center items-center flex-col p-0.5 rounded-md hover:bg-hoverbg focus:bg-hoverbg focus-within:bg-hoverbg cursor-pointer"
455-
onClick={() => setSearch("")}
457+
onClick={() => {
458+
setSearch("");
459+
globalStore.set(model.directorySearchActive, false);
460+
}}
456461
>
457462
<i className="fa-solid fa-xmark" />
458463
<input
@@ -549,6 +554,7 @@ const TableRow = React.forwardRef(function ({
549554
const newFileName = row.getValue("path") as string;
550555
model.goHistory(newFileName);
551556
setSearch("");
557+
globalStore.set(model.directorySearchActive, false);
552558
}}
553559
onClick={() => setFocusIndex(idx)}
554560
onContextMenu={(e) => handleFileContextMenu(e, row.original)}
@@ -650,8 +656,13 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
650656

651657
useEffect(() => {
652658
model.directoryKeyDownHandler = (waveEvent: WaveKeyboardEvent): boolean => {
659+
if (checkKeyPressed(waveEvent, "Cmd:f")) {
660+
globalStore.set(model.directorySearchActive, true);
661+
return true;
662+
}
653663
if (checkKeyPressed(waveEvent, "Escape")) {
654664
setSearchText("");
665+
globalStore.set(model.directorySearchActive, false);
655666
return;
656667
}
657668
if (checkKeyPressed(waveEvent, "ArrowUp")) {
@@ -676,6 +687,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
676687
}
677688
model.goHistory(selectedPath);
678689
setSearchText("");
690+
globalStore.set(model.directorySearchActive, false);
679691
return true;
680692
}
681693
if (checkKeyPressed(waveEvent, "Backspace")) {

frontend/app/view/preview/preview-model.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export class PreviewModel implements ViewModel {
160160

161161
showHiddenFiles: PrimitiveAtom<boolean>;
162162
refreshVersion: PrimitiveAtom<number>;
163+
directorySearchActive: PrimitiveAtom<boolean>;
163164
refreshCallback: () => void;
164165
directoryKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean;
165166
codeEditKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean;
@@ -173,6 +174,7 @@ export class PreviewModel implements ViewModel {
173174
let showHiddenFiles = globalStore.get(getSettingsKeyAtom("preview:showhiddenfiles")) ?? true;
174175
this.showHiddenFiles = atom<boolean>(showHiddenFiles);
175176
this.refreshVersion = atom(0);
177+
this.directorySearchActive = atom(false);
176178
this.previewTextRef = createRef();
177179
this.openFileModal = atom(false);
178180
this.openFileModalDelay = atom(false);

frontend/app/view/term/term-model.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
import { BlockNodeModel } from "@/app/block/blocktypes";
6+
import { appHandleKeyDown } from "@/app/store/keymodel";
67
import { waveEventSubscribe } from "@/app/store/wps";
78
import { RpcApi } from "@/app/store/wshclientapi";
89
import { makeFeBlockRouteId } from "@/app/store/wshrouter";
@@ -528,6 +529,12 @@ export class TermViewModel implements ViewModel {
528529
this.forceRestartController();
529530
return false;
530531
}
532+
const appHandled = appHandleKeyDown(waveEvent);
533+
if (appHandled) {
534+
event.preventDefault();
535+
event.stopPropagation();
536+
return false;
537+
}
531538
return true;
532539
}
533540

frontend/types/gotypes.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,9 @@ declare global {
977977
"conn:*"?: boolean;
978978
"conn:askbeforewshinstall"?: boolean;
979979
"conn:wshenabled"?: boolean;
980+
"debug:*"?: boolean;
981+
"debug:pprofport"?: number;
982+
"debug:pprofmemprofilerate"?: number;
980983
};
981984

982985
// waveobj.StickerClickOptsType
@@ -1042,6 +1045,8 @@ declare global {
10421045
"client:buildtime"?: string;
10431046
"client:osrelease"?: string;
10441047
"client:isdev"?: boolean;
1048+
"cohort:month"?: string;
1049+
"cohort:isoweek"?: string;
10451050
"autoupdate:channel"?: string;
10461051
"autoupdate:enabled"?: boolean;
10471052
"localshell:type"?: string;
@@ -1113,6 +1118,8 @@ declare global {
11131118
"client:buildtime"?: string;
11141119
"client:osrelease"?: string;
11151120
"client:isdev"?: boolean;
1121+
"cohort:month"?: string;
1122+
"cohort:isoweek"?: string;
11161123
"autoupdate:channel"?: string;
11171124
"autoupdate:enabled"?: boolean;
11181125
"localshell:type"?: string;

pkg/telemetry/telemetry.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func mergeActivity(curActivity *telemetrydata.TEventProps, newActivity telemetry
153153
curActivity.OpenMinutes += newActivity.OpenMinutes
154154
curActivity.WaveAIActiveMinutes += newActivity.WaveAIActiveMinutes
155155
curActivity.WaveAIFgMinutes += newActivity.WaveAIFgMinutes
156+
if newActivity.AppFirstDay {
157+
curActivity.AppFirstDay = true
158+
}
156159
}
157160

158161
// ignores the timestamp in tevent, and uses the current time

pkg/telemetry/telemetrydata/telemetrydata.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type TEventUserProps struct {
6060
ClientOSRelease string `json:"client:osrelease,omitempty"`
6161
ClientIsDev bool `json:"client:isdev,omitempty"`
6262

63+
CohortMonth string `json:"cohort:month,omitempty"`
64+
CohortISOWeek string `json:"cohort:isoweek,omitempty"`
65+
6366
AutoUpdateChannel string `json:"autoupdate:channel,omitempty"`
6467
AutoUpdateEnabled bool `json:"autoupdate:enabled,omitempty"`
6568

pkg/wconfig/metaconsts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,9 @@ const (
9797
ConfigKey_ConnClear = "conn:*"
9898
ConfigKey_ConnAskBeforeWshInstall = "conn:askbeforewshinstall"
9999
ConfigKey_ConnWshEnabled = "conn:wshenabled"
100+
101+
ConfigKey_DebugClear = "debug:*"
102+
ConfigKey_DebugPprofPort = "debug:pprofport"
103+
ConfigKey_DebugPprofMemProfileRate = "debug:pprofmemprofilerate"
100104
)
101105

pkg/wconfig/settingsconfig.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ type SettingsType struct {
143143
ConnClear bool `json:"conn:*,omitempty"`
144144
ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"`
145145
ConnWshEnabled bool `json:"conn:wshenabled,omitempty"`
146+
147+
DebugClear bool `json:"debug:*,omitempty"`
148+
DebugPprofPort *int `json:"debug:pprofport,omitempty"`
149+
DebugPprofMemProfileRate *int `json:"debug:pprofmemprofilerate,omitempty"`
146150
}
147151

148152
func (s *SettingsType) GetAiSettings() *AiSettingsType {
@@ -333,7 +337,7 @@ func resolveEnvReplacements(m waveobj.MetaMapType) {
333337
if m == nil {
334338
return
335339
}
336-
340+
337341
for key, value := range m {
338342
switch v := value.(type) {
339343
case string:
@@ -367,20 +371,20 @@ func resolveEnvValue(value string) (string, bool) {
367371
if !strings.HasPrefix(value, "$ENV:") {
368372
return "", false
369373
}
370-
374+
371375
envSpec := value[5:] // Remove "$ENV:" prefix
372376
parts := strings.SplitN(envSpec, ":", 2)
373377
envVar := parts[0]
374378
var fallback string
375379
if len(parts) > 1 {
376380
fallback = parts[1]
377381
}
378-
382+
379383
// Get the environment variable value
380384
if envValue, exists := os.LookupEnv(envVar); exists {
381385
return envValue, true
382386
}
383-
387+
384388
// Return fallback if provided, otherwise return empty string
385389
if fallback != "" {
386390
return fallback, true
@@ -414,12 +418,12 @@ func readConfigHelper(fileName string, barr []byte, readErr error) (waveobj.Meta
414418
}
415419
cerrs = append(cerrs, ConfigError{File: fileName, Err: err.Error()})
416420
}
417-
421+
418422
// Resolve environment variable replacements
419423
if rtn != nil {
420424
resolveEnvReplacements(rtn)
421425
}
422-
426+
423427
return rtn, cerrs
424428
}
425429

0 commit comments

Comments
 (0)