Skip to content

Commit 445e2a9

Browse files
committed
feat: add anonymous launch counting
1 parent 6fb3349 commit 445e2a9

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.2.4
4+
5+
- Add privacy-friendly anonymous launch counting via Hits.
6+
- Document the opt-out environment variable for launch counting.
7+
38
## 0.2.3
49

510
- Clarify that browser-only ChatGPT login is not enough; the widget needs local Codex auth files.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ A lightweight **Windows desktop floating widget** for monitoring Codex usage.
55

66
## 本次更新 / What's New
77

8+
- **匿名启动统计**:启动时后台请求一次公开 Hits 计数端点,帮助估算实际使用量;不发送 token、账号或用量数据,可用环境变量关闭。
9+
Anonymous launch counting pings a public Hits counter once on startup to estimate real usage; it sends no tokens, account data, or usage data and can be disabled by environment variable.
810
- **更清晰的日间/夜间界面**:根据背景亮度自动切换文字、状态和圆环底轨颜色,浅色背景也能读清楚。
911
Better day/night readability with adaptive text and ring colors.
1012
- **后台刷新**:网络请求放到后台 Job,不会因为接口慢或网络波动卡住悬浮窗。
@@ -53,6 +55,8 @@ The previews use sample data and are for UI demonstration only.
5355
Stores generated config/cache under the user's AppData folder.
5456
- token 刷新写回前会备份并原子写入认证文件
5557
Backs up and atomically writes auth files when refreshing tokens.
58+
- 启动时会后台请求一次 `https://hits.sh/github.com/WeikangLin93/codex-usage-widget/app-launch.svg` 做匿名启动计数;不会发送 token、账号、用量百分比或本机路径。若要关闭,启动前设置环境变量 `CODEX_USAGE_WIDGET_DISABLE_TELEMETRY=1`
59+
On startup, the widget requests `https://hits.sh/github.com/WeikangLin93/codex-usage-widget/app-launch.svg` once for anonymous launch counting; it does not send tokens, account data, usage percentages, or local paths. To opt out, set `CODEX_USAGE_WIDGET_DISABLE_TELEMETRY=1` before launching.
5660

5761
---
5862

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.3
1+
0.2.4

codex_usage_widget.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Add-Type -AssemblyName System.Windows.Forms
1+
Add-Type -AssemblyName System.Windows.Forms
22
Add-Type -AssemblyName System.Drawing
33

44
# 修复 WinForms 事件线程偶发“无可用 Runspace”异常
@@ -111,6 +111,20 @@ $script:pendingRestoreAt = $null
111111
$script:refreshJob = $null
112112
$script:nextRefreshAt = Get-Date
113113
$script:isRefreshing = $false
114+
$script:telemetryJob = $null
115+
116+
function Start-LaunchTelemetry {
117+
if ($env:CODEX_USAGE_WIDGET_DISABLE_TELEMETRY -eq "1") { return }
118+
if ($script:telemetryJob -and $script:telemetryJob.State -eq "Running") { return }
119+
120+
$telemetryUrl = "https://hits.sh/github.com/WeikangLin93/codex-usage-widget/app-launch.svg?label=launches"
121+
$script:telemetryJob = Start-Job -ArgumentList $telemetryUrl -ScriptBlock {
122+
param($url)
123+
try {
124+
Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 5 | Out-Null
125+
} catch {}
126+
}
127+
}
114128

115129
function Format-Remaining([int]$seconds) {
116130
if ($seconds -lt 0) { $seconds = 0 }
@@ -487,10 +501,16 @@ $form.Add_FormClosing({
487501
try { Remove-Job -Job $script:refreshJob -Force -ErrorAction SilentlyContinue } catch {}
488502
$script:refreshJob = $null
489503
}
504+
if ($script:telemetryJob) {
505+
try { Remove-Job -Job $script:telemetryJob -Force -ErrorAction SilentlyContinue } catch {}
506+
$script:telemetryJob = $null
507+
}
490508
$notify.Visible = $false
491509
$notify.Dispose()
492510
})
493511

512+
Start-LaunchTelemetry
494513
Start-UsageRefresh
495514
Apply-VisibilityPolicy
496515
[System.Windows.Forms.Application]::Run($form)
516+

0 commit comments

Comments
 (0)