Skip to content

Commit d82672c

Browse files
authored
track number of terminal commands run (#2519)
1 parent 5edb6f3 commit d82672c

File tree

10 files changed

+35
-2
lines changed

10 files changed

+35
-2
lines changed

emain/emain-activity.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let globalIsQuitting = false;
88
let globalIsStarting = true;
99
let globalIsRelaunching = false;
1010
let forceQuit = false;
11+
let termCommandsRun = 0;
1112

1213
export function setWasActive(val: boolean) {
1314
wasActive = val;
@@ -52,3 +53,13 @@ export function setForceQuit(val: boolean) {
5253
export function getForceQuit(): boolean {
5354
return forceQuit;
5455
}
56+
57+
export function incrementTermCommandsRun() {
58+
termCommandsRun++;
59+
}
60+
61+
export function getAndClearTermCommandsRun(): number {
62+
const count = termCommandsRun;
63+
termCommandsRun = 0;
64+
return count;
65+
}

emain/emain-ipc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { getWaveTabViewByWebContentsId } from "./emain-tabview";
1818
import { handleCtrlShiftState } from "./emain-util";
1919
import { getWaveVersion } from "./emain-wavesrv";
2020
import { createNewWaveWindow, focusedWaveWindow, getWaveWindowByWebContentsId } from "./emain-window";
21+
import { incrementTermCommandsRun } from "./emain-activity";
2122
import { ElectronWshClient } from "./emain-wsh";
2223

2324
const electronApp = electron.app;
@@ -395,6 +396,10 @@ export function initIpcHandlers() {
395396
console.log("fe-log", logStr);
396397
});
397398

399+
electron.ipcMain.on("increment-term-commands", () => {
400+
incrementTermCommandsRun();
401+
});
402+
398403
electron.ipcMain.on("open-builder", (event, appId?: string) => {
399404
fireAndForget(() => createBuilderWindow(appId || ""));
400405
});

emain/emain.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { fireAndForget, sleep } from "../frontend/util/util";
1212
import { AuthKey, configureAuthKeyRequestInjection } from "./authkey";
1313
import {
1414
getActivityState,
15+
getAndClearTermCommandsRun,
1516
getForceQuit,
1617
getGlobalIsRelaunching,
1718
setForceQuit,
@@ -173,12 +174,19 @@ function logActiveState() {
173174
}
174175
activity.displays = getActivityDisplays();
175176

177+
const termCmdCount = getAndClearTermCommandsRun();
178+
if (termCmdCount > 0) {
179+
activity.termcommandsrun = termCmdCount;
180+
}
181+
176182
const props: TEventProps = {
177183
"activity:activeminutes": activity.activeminutes,
178184
"activity:fgminutes": activity.fgminutes,
179185
"activity:openminutes": activity.openminutes,
180186
};
181-
187+
if (termCmdCount > 0) {
188+
props["activity:termcommandsrun"] = termCmdCount;
189+
}
182190
if (astate.wasActive && isWaveAIOpen) {
183191
props["activity:waveaiactiveminutes"] = 1;
184192
}

emain/preload.ts

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

44
import { contextBridge, ipcRenderer, Rectangle, WebviewTag } from "electron";
55

6+
// update type in custom.d.ts (ElectronApi type)
67
contextBridge.exposeInMainWorld("api", {
78
getAuthKey: () => ipcRenderer.sendSync("get-auth-key"),
89
getIsDev: () => ipcRenderer.sendSync("get-is-dev"),
@@ -60,6 +61,7 @@ contextBridge.exposeInMainWorld("api", {
6061
clearWebviewStorage: (webContentsId: number) => ipcRenderer.invoke("clear-webview-storage", webContentsId),
6162
setWaveAIOpen: (isOpen: boolean) => ipcRenderer.send("set-waveai-open", isOpen),
6263
closeBuilderWindow: () => ipcRenderer.send("close-builder-window"),
64+
incrementTermCommands: () => ipcRenderer.send("increment-term-commands"),
6365
});
6466

6567
// Custom event for "new-window"

frontend/app/view/term/termwrap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getFileSubject } from "@/app/store/wps";
55
import { sendWSCommand } from "@/app/store/ws";
66
import { RpcApi } from "@/app/store/wshclientapi";
77
import { TabRpcClient } from "@/app/store/wshrpcutil";
8-
import { WOS, atoms, fetchWaveFile, getSettingsKeyAtom, globalStore, openLink } from "@/store/global";
8+
import { WOS, atoms, fetchWaveFile, getApi, getSettingsKeyAtom, globalStore, openLink } from "@/store/global";
99
import * as services from "@/store/services";
1010
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
1111
import { base64ToArray, base64ToString, fireAndForget } from "@/util/util";
@@ -252,6 +252,7 @@ function handleOsc16162Command(data: string, blockId: string, loaded: boolean, t
252252
case "C":
253253
rtInfo["shell:state"] = "running-command";
254254
globalStore.set(termWrap.shellIntegrationStatusAtom, "running-command");
255+
getApi().incrementTermCommands();
255256
if (cmd.data.cmd64) {
256257
const decodedLen = Math.ceil(cmd.data.cmd64.length * 0.75);
257258
if (decodedLen > 8192) {

frontend/types/custom.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ declare global {
122122
clearWebviewStorage: (webContentsId: number) => Promise<void>; // clear-webview-storage
123123
setWaveAIOpen: (isOpen: boolean) => void; // set-waveai-open
124124
closeBuilderWindow: () => void; // close-builder-window
125+
incrementTermCommands: () => void; // increment-term-commands
125126
};
126127

127128
type ElectronContextMenuItem = {

frontend/types/gotypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ declare global {
3737
numsshconn?: number;
3838
numwslconn?: number;
3939
nummagnify?: number;
40+
termcommandsrun?: number;
4041
numpanics?: number;
4142
numaireqs?: number;
4243
startup?: number;
@@ -1061,6 +1062,7 @@ declare global {
10611062
"activity:openminutes"?: number;
10621063
"activity:waveaiactiveminutes"?: number;
10631064
"activity:waveaifgminutes"?: number;
1065+
"activity:termcommandsrun"?: number;
10641066
"app:firstday"?: boolean;
10651067
"app:firstlaunch"?: boolean;
10661068
"action:initiator"?: "keyboard" | "mouse";

pkg/telemetry/telemetry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func mergeActivity(curActivity *telemetrydata.TEventProps, newActivity telemetry
153153
curActivity.OpenMinutes += newActivity.OpenMinutes
154154
curActivity.WaveAIActiveMinutes += newActivity.WaveAIActiveMinutes
155155
curActivity.WaveAIFgMinutes += newActivity.WaveAIFgMinutes
156+
curActivity.TermCommandsRun += newActivity.TermCommandsRun
156157
if newActivity.AppFirstDay {
157158
curActivity.AppFirstDay = true
158159
}

pkg/telemetry/telemetrydata/telemetrydata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type TEventProps struct {
8585
OpenMinutes int `json:"activity:openminutes,omitempty"`
8686
WaveAIActiveMinutes int `json:"activity:waveaiactiveminutes,omitempty"`
8787
WaveAIFgMinutes int `json:"activity:waveaifgminutes,omitempty"`
88+
TermCommandsRun int `json:"activity:termcommandsrun,omitempty"`
8889

8990
AppFirstDay bool `json:"app:firstday,omitempty"`
9091
AppFirstLaunch bool `json:"app:firstlaunch,omitempty"`

pkg/wshrpc/wshrpctypes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ type ActivityUpdate struct {
840840
NumSSHConn int `json:"numsshconn,omitempty"`
841841
NumWSLConn int `json:"numwslconn,omitempty"`
842842
NumMagnify int `json:"nummagnify,omitempty"`
843+
TermCommandsRun int `json:"termcommandsrun,omitempty"`
843844
NumPanics int `json:"numpanics,omitempty"`
844845
NumAIReqs int `json:"numaireqs,omitempty"`
845846
Startup int `json:"startup,omitempty"`

0 commit comments

Comments
 (0)