codex额度查看工具开发完成1.0版本

This commit is contained in:
wxf
2026-07-16 14:45:15 +08:00
commit 7ab290fffa
27 changed files with 7100 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import { onMounted, onUnmounted, readonly, shallowRef } from 'vue'
function demoSnapshot() {
const now = Date.now()
return {
shortWindow: null,
weekWindow: {
remainingPercent: 21,
usedPercent: 79,
resetsAt: now + 3 * 24 * 60 * 60 * 1000 + 8 * 60 * 60 * 1000,
},
status: '浏览器预览数据',
updatedAt: now,
}
}
export function useUsage() {
const snapshot = shallowRef(null)
const isRefreshing = shallowRef(false)
let unsubscribe
async function refresh() {
if (!window.codexHalo) {
snapshot.value = demoSnapshot()
return
}
isRefreshing.value = true
try {
snapshot.value = await window.codexHalo.refreshUsage()
} finally {
isRefreshing.value = false
}
}
onMounted(async () => {
if (!window.codexHalo) {
snapshot.value = demoSnapshot()
return
}
unsubscribe = window.codexHalo.onUsage((nextSnapshot) => {
snapshot.value = nextSnapshot
isRefreshing.value = false
})
snapshot.value = await window.codexHalo.getUsage()
})
onUnmounted(() => unsubscribe?.())
return {
snapshot: readonly(snapshot),
isRefreshing: readonly(isRefreshing),
refresh,
}
}