Files
magpie/internal/gui/assets/autoresetown.js
T
yetone c0477aa728 providers, settings: a Codex account's resets are used where they are shown, its Providers row and Settings' auto-use rows (roamlog, husky_bobo on X)
roamlog on X (使用重置卡的功能哪去了): the Providers page's Codex editor
showed "↺ 2 张重置卡" on each ChatGPT account, windows at 0% left, and no
way to use one. Nothing was removed: the use (askReset, resetask.js) was
only ever on the Usage card ("Use a reset") and the menu bar panel ("Use
one…"); the Providers row's chip (#813) was words. husky_bobo (X, Windows
10, v0.1.2597, 为什么我没有这个手动用卡按钮呢?) looked for it in Settings ›
Usage, under "Codex: auto-use resets" with both times on, where it never
was either.

- Providers editor: a Codex account's "↺ N resets" is a button (a span
  with role=button, the window meters' aq-set look and hover, no colour of
  its own; Enter and Space too) opening the same confirmation, its
  tooltip saying which reset a use spends. A GLM team's resets, counted
  by window and used on the vendor's page, stay words.
- The confirmation asked from the editor goes back to it on Cancel or
  once spent (ed.back, as Sign out's does): the editor is the modal, and
  closing would have closed it too.
- Settings › Usage › Codex: auto-use resets: each account holding resets
  says "↺ N resets · until … · auto-used before it expires" under its
  name with "Use a reset" beside it, read as the editor reads them
  (loginUsageOf, cached a minute), drawn again once spent. In
  autoresetown.js, loaded with those rows.
- No new strings. The core's scripts are 1,533,441 bytes, 305 under
  their size before, budget 1,533,802 not raised: a span-as-button helper
  (spanBtn) shared with windowCapMeter, and the reset helpers' comments
  cut down.

Run, at base 9d08993c8:
- mote (mote-run): providers-reset-use.test.cjs (new: 40 cases, Chromium
  and WebKit, en/zh/zh-TW/ja/de, 420 and 1000/1100 px; Providers row
  click and keyboard, Cancel spends nothing and keeps the editor, a use
  posts {user} alone and the row reads 1, the GLM chip inert, no page
  move; Settings as the Windows app (navigator.platform Win32, web:false)
  with husky_bobo's settings, both times on), reset-providers,
  codex-auto-reset-settings, codex-reset-lead, codex-auto-reset: 114 of
  114 pass. go test -tags nogui -run 'Budget|I18n|Asset|Script'
  ./internal/gui ok. gofmt -l clean.
- Whole GUI suite: on the Linux box (wsl-run, magpie-desktop), since
  mote had three other sessions' full GUI suites running; started before
  the push, its result follows in the report, reds filed on their own.

Broken by hand (red, then put back), on mote:
- origin/main's assets: the Providers cases red ("the resets are words
  only, nothing uses one"), the Settings cases red (no .ar-own-resets).
- origin/main's resetask.js with the rest of this change: Cancel closes
  the editor (chip gone), and Settings still says 2 resets after a use.

Not tried: a real reset was not spent (fixtures only); not run in the
real Windows app on xiaomi-gpu, only with Windows' navigator.platform.
2026-11-01 20:55:02 +08:00

118 lines
5.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Settings › Usage's Codex auto-use rows: each ChatGPT account's switches
// and, under them, how early a reset about to expire is used. app.js
// imports this when Settings draws them (renderAutoResetOwn), so it weighs
// nothing on the core.
// renderAutoResetOwn lists each ChatGPT account under Settings › Usage's
// "Codex: auto-use resets", with its switch, the same say as on the
// account's card (settings' codexAutoReset, the CLI's quota auto-reset).
// Avalon on Discord, after foobra12 asked where it was: it was only on the
// accounts' cards, and they found it from the menu bar's panel alone,
// nothing for it in the window's Settings. The row shows while a Codex
// account is signed in, or one is still on.
window.autoResetOwnPaint = function (s) {
const head = $("#codexAutoResetRow");
const list = head.parentElement;
list.querySelectorAll(".ar-own").forEach((r) => r.remove());
const on = s.codexAutoReset || [];
const users = [...(s.codexUsers || [])];
for (const u of on) if (!users.some((x) => x.toLowerCase() === u)) users.push(u);
head.hidden = !users.length;
// each account's resets, read as the providers' editor reads them,
// with Use beside them (husky_bobo on X looked for it here)
const held = users.length ? loginUsageOf("codex") : null;
if (users.length && !held) loginUsage.codex?.loading?.then(() => { if (!head.hidden && loginUsage.codex?.data) autoResetOwnPaint(prefs || s); });
let after = head;
for (const user of users) {
const r = el("div", "row pref ar-own");
r.dataset.user = user;
const who = el("div", "who");
const name = el("div", "name", user);
name.title = user;
who.append(name);
const q = held && Object.entries(held).find(([u]) => u.toLowerCase() === user.toLowerCase())?.[1];
if (q?.resets?.count && !q.error && !q.resets.byWindow) {
const qu = { ...q, provider: "codex", user };
const sub = el("div", "sub ar-own-resets");
const use = el("button", "text", t("Use a reset"));
use.title = resetUseTitle(qu);
use.setAttribute("aria-haspopup", "dialog");
use.onclick = (e) => { e.stopPropagation(); askReset(qu); };
sub.append(resetsWords(qu.resets, qu), " ", use);
who.append(sub);
}
// each of the two times its own Off/On (#2078)
const was = on.includes(user.toLowerCase()) ? autoResetWhenOf(s.codexAutoResetOnly?.[user.toLowerCase()]) : { week: false, expiring: false };
const cases = el("div", "ar-own-cases");
for (const c of AUTO_RESET_CASES) {
const line = el("div", "ar-own-case");
line.dataset.case = c.id;
const say = el("span", "ar-own-say", t(c.say));
say.title = t(was[c.id] ? c.on : c.off, resetLeadVars());
const pick = segs([["off", t("Off")], ["on", t("On")]], was[c.id] ? "on" : "off", async (v) => {
try {
prefs = await writingPrefs(api("settings/codex-auto-reset", { user, on: v === "on", when: c.id }));
if (state) state.settings = prefs;
const now = (prefs.codexAutoReset || []).includes(user.toLowerCase()) ? autoResetWhenOf(prefs.codexAutoResetOnly?.[user.toLowerCase()]) : { week: false, expiring: false };
status(autoResetStatus(user, now), "ok");
renderSettings();
if (quotas) renderQuotas(); // the account's card says the same
} catch (e) {
statusTErr(e);
renderSettings();
}
});
pick.setAttribute("aria-label", t("Auto-use resets") + " · " + t(c.say) + " · " + user);
line.append(say, pick);
cases.append(line);
}
r.append(who, cases);
after.after(r);
after = r;
}
renderResetLead(s, head.hidden);
};
// renderResetLead: how long before a reset about to run out unused it is
// used, under the accounts' switches, one for them all; a pick from the
// app's menu (settings/codex-reset-lead). A value set outside the choices
// (the CLI takes any minutes in range) is shown and kept.
function renderResetLead(s, hidden) {
const row = $("#codexResetLeadRow");
if (!row) return;
row.hidden = hidden;
const cur = resetLeadMinutes(s);
const leads = RESET_LEADS.includes(cur) ? RESET_LEADS : [...RESET_LEADS, cur].sort((a, b) => a - b);
const name = (m) => t("{lead} before", { lead: resetLeadWords(m) });
const b = el("button", "sess-pick reset-lead");
b.type = "button";
b.setAttribute("aria-haspopup", "menu");
b.setAttribute("aria-label", t("Codex: how early before one expires") + ": " + name(cur));
// every choice in one cell, the current one seen: the button is as wide
// as the widest, so a pick doesn't rewrap the row and move the page
const say = el("span", "rl-say");
for (const m of leads) {
const w = el("span", m === cur ? "on" : "", name(m));
if (m !== cur) w.setAttribute("aria-hidden", "true");
say.append(w);
}
b.append(say, svg(CHEV, 11, 1.6));
b.onclick = (e) => {
e.stopPropagation();
if (b.classList.contains("open")) return closeProtoMenu();
openProtoMenu(b, leads.map((m) => ({ v: String(m), name: name(m), note: m === 30 ? "Default" : "", literalName: true })), String(cur), async (v) => {
if (Number(v) === cur) return;
try {
prefs = await writingPrefs(api("settings/codex-reset-lead", { minutes: Number(v) }));
if (state) state.settings = prefs;
renderSettings();
if (quotas) renderQuotas(); // the cards' titles say it too
} catch (err) {
statusTErr(err);
renderSettings();
}
}, "Used before it expires", "sess-menu", "right");
};
$("#codexResetLeadPick").replaceChildren(b);
}