dsh-plugin-subscriptions 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +36 -1
  2. package/README.zh.md +36 -1
  3. package/lib/auth/rpc.d.ts +29 -12
  4. package/lib/auth/rpc.js +29 -6
  5. package/lib/auth/store.d.ts +75 -17
  6. package/lib/auth/store.js +148 -27
  7. package/lib/client/SubscriptionsSection.d.ts +9 -3
  8. package/lib/client/SubscriptionsSection.js +93 -65
  9. package/lib/client/locales.d.ts +18 -10
  10. package/lib/client/locales.js +18 -10
  11. package/lib/client.js +250 -127
  12. package/lib/client.js.map +1 -1
  13. package/lib/index.d.ts +21 -0
  14. package/lib/index.js +1482 -168
  15. package/lib/providers/accounts.d.ts +102 -0
  16. package/lib/providers/accounts.js +123 -0
  17. package/lib/providers/claude.d.ts +22 -4
  18. package/lib/providers/claude.js +91 -11
  19. package/lib/providers/codex.d.ts +24 -3
  20. package/lib/providers/codex.js +116 -17
  21. package/lib/providers/common.d.ts +17 -0
  22. package/lib/providers/common.js +67 -3
  23. package/lib/providers/copilot.d.ts +22 -3
  24. package/lib/providers/copilot.js +91 -12
  25. package/lib/providers/grok.d.ts +24 -4
  26. package/lib/providers/grok.js +100 -14
  27. package/lib/providers/pool-family.d.ts +56 -0
  28. package/lib/providers/pool-family.js +45 -0
  29. package/lib/providers/pool-health.d.ts +74 -0
  30. package/lib/providers/pool-health.js +148 -0
  31. package/lib/providers/pool-usage.d.ts +57 -0
  32. package/lib/providers/pool-usage.js +130 -0
  33. package/lib/providers/pool.d.ts +107 -0
  34. package/lib/providers/pool.js +371 -0
  35. package/lib/tools/image-generate.d.ts +3 -3
  36. package/lib/tools/image-generate.js +2 -1
  37. package/lib/tools/video-generate.d.ts +2 -2
  38. package/lib/tools/video-generate.js +2 -1
  39. package/lib/tools/x-search.d.ts +2 -2
  40. package/lib/tools/x-search.js +2 -1
  41. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -39,15 +39,19 @@ const en = {
39
39
  unavailable: "Connection unavailable; subscription status cannot be loaded.",
40
40
  checking: "Checking…",
41
41
  loginInProgress: "Login in progress…",
42
- loggedIn: "Logged in",
43
- loggedInAccount: "Logged in as {account}",
44
- loggedInExpires: "Logged in · expires {date}",
45
- loggedInAccountExpires: "Logged in as {account} · expires {date}",
46
42
  notLoggedIn: "Not logged in",
43
+ loggedInCount: "{count} account(s) connected",
44
+ accountExpires: "expires {date}",
45
+ defaultBadge: "Default",
46
+ setDefault: "Set as default",
47
+ addAccount: "Add account",
48
+ addAccountOAuth: "Browser authorization",
49
+ addAccountKeychain: "Import Claude Code",
50
+ addAccountHint: "Browser authorization signs in whichever account the browser currently uses — switch accounts there first (or use an incognito window with the manual code below) to add a different one.",
47
51
  login: "Log in",
48
52
  cancel: "Cancel",
49
53
  logout: "Log out",
50
- logoutConfirm: "Log out of {provider}?",
54
+ logoutAccountConfirm: "Log out {account} of {provider}?",
51
55
  manualSummary: "Browser flow not working? Paste the callback URL or code",
52
56
  manualPlaceholder: "Paste the callback URL or code",
53
57
  submit: "Submit",
@@ -124,15 +128,19 @@ const zh = {
124
128
  unavailable: "连接不可用,无法加载订阅状态。",
125
129
  checking: "查询中…",
126
130
  loginInProgress: "登录中…",
127
- loggedIn: "已登录",
128
- loggedInAccount: "已登录:{account}",
129
- loggedInExpires: "已登录 · 过期时间 {date}",
130
- loggedInAccountExpires: "已登录:{account} · 过期时间 {date}",
131
131
  notLoggedIn: "未登录",
132
+ loggedInCount: "已连接 {count} 个账号",
133
+ accountExpires: "过期时间 {date}",
134
+ defaultBadge: "默认",
135
+ setDefault: "设为默认",
136
+ addAccount: "添加账号",
137
+ addAccountOAuth: "浏览器授权",
138
+ addAccountKeychain: "导入 Claude Code",
139
+ addAccountHint: "浏览器授权以浏览器当前登录的账号为准;要添加不同账号,请先在浏览器里切换账号,或用无痕窗口走下方手动授权码。",
132
140
  login: "登录",
133
141
  cancel: "取消",
134
142
  logout: "退出登录",
135
- logoutConfirm: "确定退出 {provider} 的登录吗?",
143
+ logoutAccountConfirm: "确定退出 {provider} 的账号 {account} 吗?",
136
144
  manualSummary: "浏览器流程无法完成?粘贴回调 URL 或授权码",
137
145
  manualPlaceholder: "粘贴回调 URL 或授权码",
138
146
  submit: "提交",
@@ -252,6 +260,14 @@ async function callSubscriptionsAuth(rpc, endpoint, payload) {
252
260
  function messageOf(error) {
253
261
  return error instanceof Error ? error.message : String(error);
254
262
  }
263
+ /** Copy a keyed map without the entries whose key is not in `live`. */
264
+ function dropStale(map, live) {
265
+ const stale = Object.keys(map).filter((key) => !live.has(key));
266
+ if (stale.length === 0) return map;
267
+ const next = { ...map };
268
+ for (const key of stale) delete next[key];
269
+ return next;
270
+ }
255
271
  /**
256
272
  * English-dictionary fallback for a missing inject `t` (standalone renders);
257
273
  * the slot inject always supplies the locale-bound one.
@@ -399,6 +415,36 @@ const styles$4 = {
399
415
  lineHeight: "18px",
400
416
  color: "var(--dsw-alias-label-tertiary)"
401
417
  },
418
+ accountRow: {
419
+ display: "flex",
420
+ flexDirection: "column",
421
+ gap: 6,
422
+ border: "1px solid var(--dsw-alias-border-l2)",
423
+ borderRadius: 8,
424
+ padding: "8px 10px",
425
+ marginTop: 4
426
+ },
427
+ accountHeader: {
428
+ display: "flex",
429
+ alignItems: "center",
430
+ gap: 8
431
+ },
432
+ accountName: {
433
+ fontSize: 13,
434
+ lineHeight: "20px",
435
+ color: "var(--dsw-alias-label-primary)",
436
+ userSelect: "all"
437
+ },
438
+ starButton: {
439
+ border: "none",
440
+ background: "transparent",
441
+ padding: 0,
442
+ font: "inherit",
443
+ fontSize: 14,
444
+ lineHeight: "20px",
445
+ cursor: "pointer",
446
+ color: "var(--dsw-alias-state-warn-label)"
447
+ },
402
448
  usageTrack: {
403
449
  height: 6,
404
450
  borderRadius: 3,
@@ -541,7 +587,7 @@ const styles$4 = {
541
587
  /** Status dot color for one provider state. */
542
588
  function dotColor(status) {
543
589
  if (status?.busy === true) return "var(--dsw-alias-state-warn-label)";
544
- if (status?.loggedIn === true) return "var(--dsw-alias-state-success-primary)";
590
+ if ((status?.accounts.length ?? 0) > 0) return "var(--dsw-alias-state-success-primary)";
545
591
  return "var(--dsw-alias-label-dimmed)";
546
592
  }
547
593
  /**
@@ -553,15 +599,7 @@ function dotColor(status) {
553
599
  function statusText(t, status) {
554
600
  if (status === void 0) return t("checking");
555
601
  if (status.busy) return t("loginInProgress");
556
- if (status.loggedIn) {
557
- const params = {};
558
- if (status.account !== void 0) params.account = status.account;
559
- if (status.expiresAt !== void 0) params.date = new Date(status.expiresAt).toLocaleString();
560
- if (params.account !== void 0 && params.date !== void 0) return t("loggedInAccountExpires", params);
561
- if (params.account !== void 0) return t("loggedInAccount", params);
562
- if (params.date !== void 0) return t("loggedInExpires", params);
563
- return t("loggedIn");
564
- }
602
+ if (status.accounts.length > 0) return t("loggedInCount", { count: status.accounts.length });
565
603
  return t("notLoggedIn");
566
604
  }
567
605
  /**
@@ -611,12 +649,13 @@ function SubscriptionsSection(props) {
611
649
  /** Pending device-flow codes (copilot), shown while the attempt polls. */
612
650
  const [deviceCodes, setDeviceCodes] = (0, react.useState)({});
613
651
  const [copiedCode, setCopiedCode] = (0, react.useState)(void 0);
652
+ /** Usage snapshots keyed `${provider}:${accountKey}` — every account tracks its own windows. */
614
653
  const [usages, setUsages] = (0, react.useState)({});
615
654
  const [usageErrors, setUsageErrors] = (0, react.useState)({});
616
655
  const [usageLoading, setUsageLoading] = (0, react.useState)({});
617
656
  const mountedRef = (0, react.useRef)(true);
618
657
  const pollersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
619
- /** Providers with a `usage` call in flight; guards the auto-fetch effect against re-entry. */
658
+ /** Accounts with a `usage` call in flight; guards the auto-fetch effect against re-entry. */
620
659
  const usageInflightRef = (0, react.useRef)(/* @__PURE__ */ new Set());
621
660
  /** Proxy config as last answered by `proxyGet`/`proxySet`. */
622
661
  const [proxy, setProxy] = (0, react.useState)(void 0);
@@ -662,7 +701,7 @@ function SubscriptionsSection(props) {
662
701
  setStatuses(response.providers);
663
702
  for (const { id } of PROVIDERS) {
664
703
  const status = response.providers[id];
665
- if (status.loggedIn || !status.busy) {
704
+ if (status.accounts.length > 0 || !status.busy) {
666
705
  stopPolling(id);
667
706
  setDeviceCodes((prev) => {
668
707
  if (prev[id] === void 0) return prev;
@@ -694,68 +733,65 @@ function SubscriptionsSection(props) {
694
733
  pollersRef.current.clear();
695
734
  };
696
735
  }, [refresh, startPolling]);
697
- const loadUsage = (0, react.useCallback)(async (provider) => {
698
- if (rpc === void 0 || usageInflightRef.current.has(provider)) return;
699
- usageInflightRef.current.add(provider);
736
+ const loadUsage = (0, react.useCallback)(async (provider, account) => {
737
+ const key = `${provider}:${account}`;
738
+ if (rpc === void 0 || usageInflightRef.current.has(key)) return;
739
+ usageInflightRef.current.add(key);
700
740
  setUsageLoading((prev) => ({
701
741
  ...prev,
702
- [provider]: true
742
+ [key]: true
703
743
  }));
704
744
  try {
705
- const usage = await callSubscriptionsAuth(rpc, "usage", { provider });
745
+ const usage = await callSubscriptionsAuth(rpc, "usage", {
746
+ provider,
747
+ account
748
+ });
706
749
  if (!mountedRef.current) return;
707
750
  setUsages((prev) => ({
708
751
  ...prev,
709
- [provider]: usage
752
+ [key]: usage
710
753
  }));
711
754
  setUsageErrors((prev) => {
712
755
  const next = { ...prev };
713
- delete next[provider];
756
+ delete next[key];
714
757
  return next;
715
758
  });
716
759
  } catch (error) {
717
760
  if (mountedRef.current) setUsageErrors((prev) => ({
718
761
  ...prev,
719
- [provider]: messageOf(error)
762
+ [key]: messageOf(error)
720
763
  }));
721
764
  } finally {
722
- usageInflightRef.current.delete(provider);
765
+ usageInflightRef.current.delete(key);
723
766
  if (mountedRef.current) setUsageLoading((prev) => ({
724
767
  ...prev,
725
- [provider]: false
768
+ [key]: false
726
769
  }));
727
770
  }
728
771
  }, [rpc]);
729
772
  (0, react.useEffect)(() => {
730
- for (const { id } of PROVIDERS) {
731
- const status = statuses[id];
732
- if (status === void 0) continue;
733
- if (status.loggedIn) {
734
- if (usages[id] === void 0 && usageErrors[id] === void 0) loadUsage(id);
735
- } else if (usages[id] !== void 0 || usageErrors[id] !== void 0) {
736
- setUsages((prev) => {
737
- const next = { ...prev };
738
- delete next[id];
739
- return next;
740
- });
741
- setUsageErrors((prev) => {
742
- const next = { ...prev };
743
- delete next[id];
744
- return next;
745
- });
746
- }
773
+ const live = /* @__PURE__ */ new Set();
774
+ for (const { id } of PROVIDERS) for (const account of statuses[id]?.accounts ?? []) {
775
+ const key = `${id}:${account.key}`;
776
+ live.add(key);
777
+ if (usages[key] === void 0 && usageErrors[key] === void 0) loadUsage(id, account.key);
747
778
  }
779
+ setUsages((prev) => dropStale(prev, live));
780
+ setUsageErrors((prev) => dropStale(prev, live));
748
781
  }, [
749
782
  statuses,
750
783
  usages,
751
784
  usageErrors,
752
785
  loadUsage
753
786
  ]);
754
- const login = (0, react.useCallback)(async (provider) => {
787
+ const login = (0, react.useCallback)(async (provider, method) => {
755
788
  if (rpc === void 0) return;
756
789
  setProviderError(provider, void 0);
757
790
  try {
758
- const response = await callSubscriptionsAuth(rpc, "login", { provider });
791
+ const response = await callSubscriptionsAuth(rpc, "login", {
792
+ provider,
793
+ ...method === void 0 ? {} : { method }
794
+ });
759
795
  if (typeof response.authorizeUrl === "string" && response.authorizeUrl === "") {
760
796
  await refresh();
761
797
  return;
@@ -765,9 +801,9 @@ function SubscriptionsSection(props) {
765
801
  setStatuses((prev) => ({
766
802
  ...prev,
767
803
  [provider]: {
804
+ accounts: prev[provider]?.accounts ?? [],
768
805
  ...prev[provider],
769
- busy: true,
770
- loggedIn: false
806
+ busy: true
771
807
  }
772
808
  }));
773
809
  if (typeof response.userCode === "string" && response.userCode.length > 0) setDeviceCodes((prev) => ({
@@ -827,12 +863,18 @@ function SubscriptionsSection(props) {
827
863
  setProviderError,
828
864
  refresh
829
865
  ]);
830
- const logout = (0, react.useCallback)(async (provider, name) => {
866
+ const logout = (0, react.useCallback)(async (provider, account, display, name) => {
831
867
  if (rpc === void 0) return;
832
- if (!window.confirm(t("logoutConfirm", { provider: name }))) return;
868
+ if (!window.confirm(t("logoutAccountConfirm", {
869
+ provider: name,
870
+ account: display
871
+ }))) return;
833
872
  setProviderError(provider, void 0);
834
873
  try {
835
- await callSubscriptionsAuth(rpc, "logout", { provider });
874
+ await callSubscriptionsAuth(rpc, "logout", {
875
+ provider,
876
+ account
877
+ });
836
878
  } catch (error) {
837
879
  setProviderError(provider, messageOf(error));
838
880
  }
@@ -843,6 +885,23 @@ function SubscriptionsSection(props) {
843
885
  setProviderError,
844
886
  refresh
845
887
  ]);
888
+ const setDefault = (0, react.useCallback)(async (provider, account) => {
889
+ if (rpc === void 0) return;
890
+ setProviderError(provider, void 0);
891
+ try {
892
+ await callSubscriptionsAuth(rpc, "setDefault", {
893
+ provider,
894
+ account
895
+ });
896
+ } catch (error) {
897
+ setProviderError(provider, messageOf(error));
898
+ }
899
+ await refresh();
900
+ }, [
901
+ rpc,
902
+ setProviderError,
903
+ refresh
904
+ ]);
846
905
  const copyDeviceCode = (0, react.useCallback)((provider, userCode) => {
847
906
  navigator.clipboard?.writeText(userCode).then(() => {
848
907
  if (!mountedRef.current) return;
@@ -993,9 +1052,7 @@ function SubscriptionsSection(props) {
993
1052
  const status = statuses[id];
994
1053
  const busy = status?.busy === true;
995
1054
  const deviceCode = deviceCodes[id];
996
- const usage = usages[id];
997
- const usageError = usageErrors[id];
998
- const showUsage = status?.loggedIn === true && usage?.supported !== false && (usage !== void 0 || usageError !== void 0 || usageLoading[id] === true);
1055
+ const accounts = status?.accounts ?? [];
999
1056
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1000
1057
  style: styles$4.card,
1001
1058
  children: [
@@ -1021,10 +1078,119 @@ function SubscriptionsSection(props) {
1021
1078
  style: styles$4.errorLine,
1022
1079
  children: errors[id]
1023
1080
  }),
1081
+ accounts.map((account) => {
1082
+ const usageKey = `${id}:${account.key}`;
1083
+ const usage = usages[usageKey];
1084
+ const usageError = usageErrors[usageKey];
1085
+ const display = account.account ?? account.key;
1086
+ const showUsage = usage?.supported !== false && (usage !== void 0 || usageError !== void 0 || usageLoading[usageKey] === true);
1087
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1088
+ style: styles$4.accountRow,
1089
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1090
+ style: styles$4.accountHeader,
1091
+ children: [
1092
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1093
+ type: "button",
1094
+ style: styles$4.starButton,
1095
+ title: account.isDefault ? t("defaultBadge") : t("setDefault"),
1096
+ onClick: () => {
1097
+ if (!account.isDefault) setDefault(id, account.key);
1098
+ },
1099
+ children: account.isDefault ? "★" : "☆"
1100
+ }),
1101
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1102
+ style: styles$4.accountName,
1103
+ children: display
1104
+ }),
1105
+ account.plan !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1106
+ style: styles$4.usagePlan,
1107
+ children: account.plan
1108
+ }),
1109
+ account.expiresAt !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1110
+ style: styles$4.statusLine,
1111
+ children: t("accountExpires", { date: new Date(account.expiresAt).toLocaleString() })
1112
+ }),
1113
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1114
+ type: "button",
1115
+ style: {
1116
+ ...styles$4.button,
1117
+ marginLeft: "auto",
1118
+ flexShrink: 0
1119
+ },
1120
+ onClick: () => {
1121
+ logout(id, account.key, display, name);
1122
+ },
1123
+ children: t("logout")
1124
+ })
1125
+ ]
1126
+ }), showUsage && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1127
+ style: styles$4.usage,
1128
+ children: [
1129
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1130
+ style: styles$4.usageHeader,
1131
+ children: [
1132
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1133
+ style: styles$4.usageTitle,
1134
+ children: t("usageTitle")
1135
+ }),
1136
+ usage?.plan !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1137
+ style: styles$4.usagePlan,
1138
+ children: t("usagePlan", { plan: usage.plan })
1139
+ }),
1140
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1141
+ type: "button",
1142
+ style: {
1143
+ ...styles$4.usageRefresh,
1144
+ ...usageLoading[usageKey] === true ? {
1145
+ opacity: .5,
1146
+ cursor: "default"
1147
+ } : {}
1148
+ },
1149
+ disabled: usageLoading[usageKey] === true,
1150
+ onClick: () => {
1151
+ loadUsage(id, account.key);
1152
+ },
1153
+ children: t("usageRefresh")
1154
+ })
1155
+ ]
1156
+ }),
1157
+ usage === void 0 && usageError === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1158
+ style: styles$4.statusLine,
1159
+ children: t("usageLoading")
1160
+ }),
1161
+ usageError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1162
+ style: styles$4.errorLine,
1163
+ children: t("usageError", { message: usageError })
1164
+ }),
1165
+ usage?.windows !== void 0 && usage.windows.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1166
+ style: styles$4.statusLine,
1167
+ children: t("usageEmpty")
1168
+ }),
1169
+ (usage?.windows ?? []).map((window$1, index) => {
1170
+ const percent = Math.min(100, Math.max(0, window$1.usedPercent));
1171
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1172
+ style: styles$4.usageRow,
1173
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1174
+ style: styles$4.usageMeta,
1175
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: usageWindowLabel(t, window$1) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [`${String(Math.round(percent))}%`, window$1.resetsAt !== void 0 && ` · ${t("usageResets", { date: new Date(window$1.resetsAt).toLocaleString() })}`] })]
1176
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1177
+ style: styles$4.usageTrack,
1178
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
1179
+ ...styles$4.usageFill,
1180
+ width: `${String(percent)}%`,
1181
+ background: usageBarColor(percent)
1182
+ } })
1183
+ })]
1184
+ }, index);
1185
+ })
1186
+ ]
1187
+ })]
1188
+ }, account.key);
1189
+ }),
1024
1190
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1025
1191
  style: styles$4.actions,
1026
1192
  children: [
1027
- !busy && status?.loggedIn !== true && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1193
+ !busy && accounts.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1028
1194
  type: "button",
1029
1195
  style: styles$4.button,
1030
1196
  onClick: () => {
@@ -1032,85 +1198,42 @@ function SubscriptionsSection(props) {
1032
1198
  },
1033
1199
  children: t("login")
1034
1200
  }),
1035
- busy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1201
+ !busy && accounts.length > 0 && id === "claude" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1036
1202
  type: "button",
1037
1203
  style: styles$4.button,
1038
1204
  onClick: () => {
1039
- cancel(id);
1205
+ login(id, "oauth");
1040
1206
  },
1041
- children: t("cancel")
1207
+ children: t("addAccountOAuth")
1208
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1209
+ type: "button",
1210
+ style: styles$4.button,
1211
+ onClick: () => {
1212
+ login(id, "keychain");
1213
+ },
1214
+ children: t("addAccountKeychain")
1215
+ })] }),
1216
+ !busy && accounts.length > 0 && id !== "claude" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1217
+ type: "button",
1218
+ style: styles$4.button,
1219
+ onClick: () => {
1220
+ login(id);
1221
+ },
1222
+ children: t("addAccount")
1042
1223
  }),
1043
- status?.loggedIn === true && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1224
+ busy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1044
1225
  type: "button",
1045
1226
  style: styles$4.button,
1046
1227
  onClick: () => {
1047
- logout(id, name);
1228
+ cancel(id);
1048
1229
  },
1049
- children: t("logout")
1230
+ children: t("cancel")
1050
1231
  })
1051
1232
  ]
1052
1233
  }),
1053
- showUsage && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1054
- style: styles$4.usage,
1055
- children: [
1056
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1057
- style: styles$4.usageHeader,
1058
- children: [
1059
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1060
- style: styles$4.usageTitle,
1061
- children: t("usageTitle")
1062
- }),
1063
- usage?.plan !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1064
- style: styles$4.usagePlan,
1065
- children: t("usagePlan", { plan: usage.plan })
1066
- }),
1067
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1068
- type: "button",
1069
- style: {
1070
- ...styles$4.usageRefresh,
1071
- ...usageLoading[id] === true ? {
1072
- opacity: .5,
1073
- cursor: "default"
1074
- } : {}
1075
- },
1076
- disabled: usageLoading[id] === true,
1077
- onClick: () => {
1078
- loadUsage(id);
1079
- },
1080
- children: t("usageRefresh")
1081
- })
1082
- ]
1083
- }),
1084
- usage === void 0 && usageError === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1085
- style: styles$4.statusLine,
1086
- children: t("usageLoading")
1087
- }),
1088
- usageError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1089
- style: styles$4.errorLine,
1090
- children: t("usageError", { message: usageError })
1091
- }),
1092
- usage?.windows !== void 0 && usage.windows.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1093
- style: styles$4.statusLine,
1094
- children: t("usageEmpty")
1095
- }),
1096
- (usage?.windows ?? []).map((window$1, index) => {
1097
- const percent = Math.min(100, Math.max(0, window$1.usedPercent));
1098
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1099
- style: styles$4.usageRow,
1100
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1101
- style: styles$4.usageMeta,
1102
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: usageWindowLabel(t, window$1) }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [`${String(Math.round(percent))}%`, window$1.resetsAt !== void 0 && ` · ${t("usageResets", { date: new Date(window$1.resetsAt).toLocaleString() })}`] })]
1103
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1104
- style: styles$4.usageTrack,
1105
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
1106
- ...styles$4.usageFill,
1107
- width: `${String(percent)}%`,
1108
- background: usageBarColor(percent)
1109
- } })
1110
- })]
1111
- }, index);
1112
- })
1113
- ]
1234
+ !busy && accounts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1235
+ style: styles$4.statusLine,
1236
+ children: t("addAccountHint")
1114
1237
  }),
1115
1238
  busy && deviceCode !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1116
1239
  style: styles$4.deviceCode,