Files
magpie/internal/gui/assets/resetask.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

102 lines
5.0 KiB
JavaScript

// A Codex reset's confirmation (askReset in app.js): spending a reset
// can't be taken back, so it asks first, names the account and which of
// its resets is used, and lets the user pick another (01huadalang on
// Discord). app.js imports this when a reset's Use is pressed, so it
// weighs nothing on the core.
window.askResetSheet = function (q) {
const ed = el("div", "editor reset-ask");
const head = el("div", "ehead");
head.append(icon(q.icon || "codex"), el("b", "", t("Use a Codex reset?")));
ed.append(head);
const who = q.alias || q.user || q.name;
ed.append(el("p", "lib-confirm", t(q.resets.count === 1
? "{who} has 1 reset. Using it starts its windows again at once, as if none of them had been used. It can't be undone."
: "{who} has {n} resets. Using one starts its windows again at once, as if none of them had been used. It can't be undone.", { who, n: q.resets.count })));
// which of them is used: the one that runs out first unless the user
// picks another of those listed one by one (01huadalang on Discord),
// and the dialog names the one it spends
const cards = q.resets.each?.length > 1 && q.resets.each.every((c) => c.id) ? q.resets.each : null;
let chosen = 0;
const which = el("p", "lib-confirm reset-which");
const sooner = el("p", "lib-confirm reset-sooner");
const cardName = (i, at = resetClock) => {
const c = cards[i];
return c.until ? t("Reset {n} runs out {when}", { n: i + 1, when: at(new Date(c.until)) }) : t("Reset {n} never runs out", { n: i + 1 });
};
const sayWhich = () => {
const full = (d) => d.toLocaleString(intlLang());
if (!chosen) {
which.textContent = q.resets.until ? t("The one used is the one that runs out first, {when}.", { when: full(new Date(q.resets.until)) }) : "";
which.hidden = !q.resets.until;
sooner.hidden = true;
return;
}
const c = cards[chosen];
which.textContent = c.until ? t("The one used is {who}'s reset that runs out {when}.", { who, when: full(new Date(c.until)) })
: t("The one used is {who}'s reset that never runs out.", { who });
which.hidden = false;
// one that runs out sooner is left, and lost if it isn't used in time
sooner.textContent = cards[0].until ? t("The one that runs out first, {when}, is kept, and is lost if it isn't used by then.", { when: full(new Date(cards[0].until)) }) : "";
sooner.hidden = !cards[0].until || cards[0].until === c.until;
};
if (cards) {
const row = el("div", "reset-pick");
const pick = el("button", "sess-pick reset-card");
pick.type = "button";
pick.setAttribute("aria-haspopup", "menu");
pick.setAttribute("aria-expanded", "false");
pick.append(el("span", "", cardName(0)), svg(CHEV, 11, 1.6));
pick.title = cardName(0, (d) => d.toLocaleString(intlLang()));
pick.onclick = (e) => {
e.stopPropagation();
if (pick.classList.contains("open")) return closeProtoMenu();
openProtoMenu(pick, cards.map((c, i) => ({ v: String(i), name: cardName(i), note: i ? "" : t("Used unless you pick another"), literalName: true })), String(chosen), (v) => {
chosen = Number(v);
pick.firstChild.textContent = cardName(chosen);
pick.title = cardName(chosen, (d) => d.toLocaleString(intlLang()));
pick.classList.toggle("set", chosen > 0);
sayWhich();
}, "Reset to use", "sess-menu");
};
row.append(el("span", "reset-pick-label", t("Reset to use")), pick);
ed.append(row);
}
sayWhich();
ed.append(which, sooner);
// nothing used yet: a reset would start nothing again
if (!q.windows?.some((w) => w.used > 0)) ed.append(el("p", "lib-confirm reset-idle", t("None of its windows has been used yet, so there is nothing to start again.")));
const bar = el("div", "bar");
const go = el("button", "text primary", t("Use a reset"));
go.onclick = async (e) => {
e.stopPropagation();
go.disabled = true;
go.classList.add("busy");
try {
const out = await api("usage/codex-reset", chosen ? { user: q.user || "", credit: cards[chosen].id } : { user: q.user || "" });
// the providers' editor and Settings read the account's windows
// and resets on their own, kept a minute: read again, as Usage is
// (#1491); asked from the editor, closing goes back to it
delete loginUsage.codex;
closeConfirmAsk();
status(who + ": " + resetOutcome(out), out.code === "reset" ? "ok" : "err");
if (editing && view === "providers") renderProviders();
if (window.autoResetOwnPaint && $("#codexAutoResetRow")) autoResetOwnPaint(prefs);
loadQuotas();
} catch (err) {
go.disabled = false;
go.classList.remove("busy");
statusErr(err);
}
};
const cancel = el("button", "text", t("Cancel"));
cancel.onclick = cancelAsk;
bar.append(el("span", "grow"), cancel, go);
ed.append(bar);
// asked from a provider's editor (roamlog on X): Cancel goes back to it
if (editing && view === "providers") ed.back = renderProviders;
confirmAsk = ed;
openModal(ed);
$("#modal").classList.add("lib");
go.focus();
};