mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
refactor(panel): unify settings and bridge contracts, prune dead code, and rename trajectory metrics
- Share settings normalization and window-bridge protocol contracts across frontend and backend - Encapsulate trajectory cache accessors inside config.mjs and validate bundle imports/syntax before writing - Remove dead selectors, unused symbols, duplicate re-export imports, and unmounted account tab instantiation - Rename speed-metrics.mjs to trajectory-metrics.mjs and audit-fixes.test.mjs to cross-module-regressions.test.mjs
This commit is contained in:
+189
-146
@@ -1,6 +1,150 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
// --- shared/settings-normalization.mjs ---
|
||||
/**
|
||||
* @fileoverview 前后端共用的偏好设置归一化规则。
|
||||
*/
|
||||
|
||||
const TOPBAR_SLOT_KEYS = Object.freeze([
|
||||
'context',
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'quota_auto',
|
||||
'gemini_5h',
|
||||
'gemini_weekly',
|
||||
'claude_5h',
|
||||
'claude_weekly',
|
||||
]);
|
||||
|
||||
const DEFAULT_TOPBAR_SLOTS = Object.freeze(['tps', 'ttft', 'context']);
|
||||
const MIN_TOPBAR_SLOTS = 1;
|
||||
const MAX_TOPBAR_SLOTS = 5;
|
||||
|
||||
const OVERVIEW_METRIC_KEYS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'context_usage',
|
||||
'quota_tightest',
|
||||
]);
|
||||
|
||||
const DEFAULT_OVERVIEW_METRICS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
]);
|
||||
|
||||
/**
|
||||
* 归一化面板挂载方式枚举(`'dual'` 顶部栏+侧边栏 | `'composer'` 输入框+侧边栏 | `'sidebar'` 仅侧边栏),
|
||||
* 兼容历史 `enableWindowOverlay` 布尔开关,默认 `'dual'`。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @param {unknown} [legacyEnableOverlay]
|
||||
* @returns {'dual'|'composer'|'sidebar'}
|
||||
*/
|
||||
function normalizeWindowMountMode(mode, legacyEnableOverlay) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'composer' || m === 'input') return 'composer';
|
||||
if (m === 'sidebar' || m === 'sidebar_only' || m === 'off') return 'sidebar';
|
||||
if (m === 'dual' || m === 'topbar') return 'dual';
|
||||
if (legacyEnableOverlay === false) return 'sidebar';
|
||||
return 'dual';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化每周额度统计模式枚举(兼容历史简写 `'tokens'` / `'cost'` 与标准枚举 `'custom_tokens'` / `'custom_cost'`)。
|
||||
*
|
||||
* @param {unknown} mode
|
||||
* @returns {'official'|'custom_tokens'|'custom_cost'}
|
||||
*/
|
||||
function normalizeWeeklyLimitMode(mode) {
|
||||
const m = String(mode || '').trim().toLowerCase();
|
||||
if (m === 'custom_tokens' || m === 'tokens') return 'custom_tokens';
|
||||
if (m === 'custom_cost' || m === 'cost') return 'custom_cost';
|
||||
return 'official';
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化顶栏/输入框胶囊槽位数组(1~5 项动态自添加,默认 3 项,自动清洗历史 `'none'` 与重复项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function normalizeTopbarCapsuleSlots(raw) {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [...DEFAULT_TOPBAR_SLOTS];
|
||||
}
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const item of raw) {
|
||||
const val = String(item ?? '').trim();
|
||||
if (!val || val === 'none') continue;
|
||||
const mapped = val === 'step_cost' ? 'cost' : val;
|
||||
if (!TOPBAR_SLOT_KEYS.includes(mapped) || seen.has(mapped)) continue;
|
||||
seen.add(mapped);
|
||||
out.push(mapped);
|
||||
if (out.length >= MAX_TOPBAR_SLOTS) break;
|
||||
}
|
||||
if (out.length < MIN_TOPBAR_SLOTS) {
|
||||
return ['context'];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化实时监控第一行指标矩阵的槽位与顺序(1~4 项,默认 4 项)。
|
||||
*
|
||||
* @param {unknown} raw
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function normalizeOverviewMetrics(raw) {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [...DEFAULT_OVERVIEW_METRICS];
|
||||
}
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const item of raw) {
|
||||
const rawVal = String(item ?? '').trim();
|
||||
const val = rawVal === 'cost' ? 'step_cost' : rawVal;
|
||||
if (!OVERVIEW_METRIC_KEYS.includes(val) || seen.has(val)) continue;
|
||||
seen.add(val);
|
||||
out.push(val);
|
||||
if (out.length >= 4) break;
|
||||
}
|
||||
return out.length > 0 ? out : ['tps'];
|
||||
}
|
||||
|
||||
// --- shared/window-bridge-protocol.mjs ---
|
||||
const WINDOW_BRIDGE_KEY = '__AGUsageMonitorBridge';
|
||||
const WINDOW_BRIDGE_ROUTE_KEY = 'hostRouteCascadeId';
|
||||
const WINDOW_OVERLAY_KEY = '__AGUsageMonitorOverlay';
|
||||
|
||||
const WINDOW_OVERLAY_METHODS = Object.freeze({
|
||||
ensureAlive: 'ensureAlive',
|
||||
getDockKind: 'getDockKind',
|
||||
getMountMode: 'getMountMode',
|
||||
updateBridge: 'updateBridge',
|
||||
applyMountMode: 'applyMountMode',
|
||||
syncHostRoute: 'syncHostRoute',
|
||||
deliverRpc: 'deliverRpc',
|
||||
dispose: 'dispose',
|
||||
});
|
||||
|
||||
function readInjectedWindowBridge() {
|
||||
return typeof window === 'undefined' ? undefined : window[WINDOW_BRIDGE_KEY];
|
||||
}
|
||||
|
||||
// --- src/icons/svgRegistry.js ---
|
||||
/**
|
||||
* @fileoverview Pure vector SVG icon registry (16x16 grid).
|
||||
@@ -2276,6 +2420,7 @@ function mergeModelsByDisplayName(models = [], settings = {}, options = {}) {
|
||||
* (Sidecar Webview `window.sidecar.fetch` + Main Window Loopback Bridge).
|
||||
*/
|
||||
|
||||
|
||||
const inFlightGets = new Map();
|
||||
const activeControllers = new Map();
|
||||
|
||||
@@ -2285,8 +2430,7 @@ const activeControllers = new Map();
|
||||
* @returns {{ port: number, token: string, bundleVersion?: string, stylesCss?: string } | null}
|
||||
*/
|
||||
function getWindowBridgeConfig() {
|
||||
if (typeof window === 'undefined') return null;
|
||||
const br = window.__AGUsageMonitorBridge;
|
||||
const br = readInjectedWindowBridge();
|
||||
const port = Number(br?.port || 0);
|
||||
if (br && Number.isInteger(port) && port > 0 && typeof br.token === 'string' && br.token) {
|
||||
return br;
|
||||
@@ -2520,13 +2664,6 @@ async function callSidecarApi(path, { method = 'GET', body, abortKey = '', cdpTi
|
||||
*/
|
||||
|
||||
|
||||
const VIEW_TABS = Object.freeze([
|
||||
{ value: 'overview', label: '实时监控', icon: 'pulse' },
|
||||
{ value: 'consumption', label: '用量统计', icon: 'chart-bar' },
|
||||
{ value: 'steps', label: '调用明细', icon: 'table' },
|
||||
{ value: 'settings', label: '偏好设置', icon: 'sliders' },
|
||||
]);
|
||||
|
||||
function getViewTabs() {
|
||||
return [
|
||||
{ value: 'overview', label: t('nav.overview'), icon: 'pulse' },
|
||||
@@ -2574,7 +2711,7 @@ function extractHostRouteCascadeId() {
|
||||
if (m && CASCADE_UUID_RE.test(m[1])) {
|
||||
return m[1];
|
||||
}
|
||||
const extBridgeRouteId = String(window.__AGUsageMonitorBridge?.hostRouteCascadeId || '').trim();
|
||||
const extBridgeRouteId = String(readInjectedWindowBridge()?.[WINDOW_BRIDGE_ROUTE_KEY] || '').trim();
|
||||
if (extBridgeRouteId && CASCADE_UUID_RE.test(extBridgeRouteId)) {
|
||||
return extBridgeRouteId;
|
||||
}
|
||||
@@ -2656,23 +2793,9 @@ let loopActive = false;
|
||||
let loopIntervalMs = 2000;
|
||||
let loopTickFn = null;
|
||||
|
||||
const CLIENT_TOPBAR_SLOT_KEYS = Object.freeze([
|
||||
'context',
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'quota_auto',
|
||||
'gemini_5h',
|
||||
'gemini_weekly',
|
||||
'claude_5h',
|
||||
'claude_weekly',
|
||||
]);
|
||||
const CLIENT_TOPBAR_SLOT_KEYS = TOPBAR_SLOT_KEYS;
|
||||
|
||||
const DEFAULT_CLIENT_TOPBAR_SLOTS = Object.freeze(['tps', 'ttft', 'context']);
|
||||
const DEFAULT_CLIENT_TOPBAR_SLOTS = DEFAULT_TOPBAR_SLOTS;
|
||||
|
||||
const CLIENT_OVERVIEW_MODULE_KEYS = Object.freeze([
|
||||
'metrics',
|
||||
@@ -2690,24 +2813,9 @@ const DEFAULT_CLIENT_OVERVIEW_MODULES = Object.freeze([
|
||||
|
||||
const DEFAULT_CLIENT_HOVER_MODULES = Object.freeze(['metrics', 'context', 'quotas']);
|
||||
|
||||
const CLIENT_OVERVIEW_METRIC_KEYS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'context_usage',
|
||||
'quota_tightest',
|
||||
]);
|
||||
const CLIENT_OVERVIEW_METRIC_KEYS = OVERVIEW_METRIC_KEYS;
|
||||
|
||||
const DEFAULT_CLIENT_OVERVIEW_METRICS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
]);
|
||||
const DEFAULT_CLIENT_OVERVIEW_METRICS = DEFAULT_OVERVIEW_METRICS;
|
||||
|
||||
const CLIENT_STEP_COLUMN_KEYS = Object.freeze([
|
||||
'step',
|
||||
@@ -2857,12 +2965,7 @@ function normalizeClientOrderedList(raw, { allowedKeys, defaultItems, minLen, ma
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function normalizeClientTopbarSlots(raw) {
|
||||
return normalizeClientOrderedList(raw, {
|
||||
allowedKeys: CLIENT_TOPBAR_SLOT_KEYS,
|
||||
defaultItems: DEFAULT_CLIENT_TOPBAR_SLOTS,
|
||||
minLen: 1,
|
||||
maxLen: 5,
|
||||
});
|
||||
return normalizeTopbarCapsuleSlots(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2902,12 +3005,7 @@ function normalizeClientOverviewModules(raw) {
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function normalizeClientOverviewMetrics(raw) {
|
||||
return normalizeClientOrderedList(raw, {
|
||||
allowedKeys: CLIENT_OVERVIEW_METRIC_KEYS,
|
||||
defaultItems: DEFAULT_CLIENT_OVERVIEW_METRICS,
|
||||
minLen: 1,
|
||||
maxLen: 4,
|
||||
});
|
||||
return normalizeOverviewMetrics(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2951,12 +3049,7 @@ function normalizeClientOrchestratorIdMode(mode) {
|
||||
* @returns {'dual'|'composer'|'sidebar'}
|
||||
*/
|
||||
function normalizeClientWindowMountMode(mode, legacyEnableOverlay) {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'composer' || m === 'input') return 'composer';
|
||||
if (m === 'sidebar' || m === 'off') return 'sidebar';
|
||||
if (m === 'dual' || m === 'topbar') return 'dual';
|
||||
if (legacyEnableOverlay === false) return 'sidebar';
|
||||
return 'dual';
|
||||
return normalizeWindowMountMode(mode, legacyEnableOverlay);
|
||||
}
|
||||
|
||||
function isEquivalentTelemetry(prev, next) {
|
||||
@@ -2972,15 +3065,6 @@ function isEquivalentTelemetry(prev, next) {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const normMount = (mode, legacyEnableOverlay) => {
|
||||
const m = String(mode ?? '').trim().toLowerCase();
|
||||
if (m === 'composer' || m === 'input') return 'composer';
|
||||
if (m === 'sidebar' || m === 'off') return 'sidebar';
|
||||
if (m === 'dual' || m === 'topbar') return 'dual';
|
||||
if (legacyEnableOverlay === false) return 'sidebar';
|
||||
return 'dual';
|
||||
};
|
||||
|
||||
// 1. 比对系统设置项(外观语言/主题/字号、模型显示策略、更新策略、挂载与结构布局配置)
|
||||
const pAct = prev.activeConversation;
|
||||
const nAct = next.activeConversation;
|
||||
@@ -3052,8 +3136,8 @@ function isEquivalentTelemetry(prev, next) {
|
||||
if ((pSet?.pluginUpdateMode ?? '') !== (nSet?.pluginUpdateMode ?? '')) return false;
|
||||
if (pSet?.autoUpdatePlugin !== nSet?.autoUpdatePlugin) return false;
|
||||
if (
|
||||
normMount(pSet?.windowMountMode, pSet?.enableWindowOverlay) !==
|
||||
normMount(nSet?.windowMountMode, nSet?.enableWindowOverlay)
|
||||
normalizeClientWindowMountMode(pSet?.windowMountMode, pSet?.enableWindowOverlay) !==
|
||||
normalizeClientWindowMountMode(nSet?.windowMountMode, nSet?.enableWindowOverlay)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -3686,9 +3770,7 @@ async function saveSettingsPatch(patch) {
|
||||
safePatch.fontScale = normalizeClientFontScale(safePatch.fontScale);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(safePatch, 'weeklyLimitMode')) {
|
||||
const mode = safePatch.weeklyLimitMode;
|
||||
safePatch.weeklyLimitMode =
|
||||
mode === 'custom_tokens' || mode === 'custom_cost' ? mode : 'official';
|
||||
safePatch.weeklyLimitMode = normalizeWeeklyLimitMode(safePatch.weeklyLimitMode);
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(safePatch, 'enableCliStatusLine')) {
|
||||
safePatch.enableCliStatusLine = Boolean(safePatch.enableCliStatusLine);
|
||||
@@ -6531,21 +6613,6 @@ function computePublicationFit(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算样本点上的平滑回归拟合值序列(供单元测试与轻量调用直接读取)。
|
||||
*
|
||||
* @param {number[]} ys
|
||||
* @param {{ minVal?: number, maxVal?: number, xs?: number[] }} [bounds]
|
||||
* @returns {number[]}
|
||||
*/
|
||||
function computeLoessFit(ys, { minVal = 0, maxVal = Infinity, xs = null } = {}) {
|
||||
const n = Array.isArray(ys) ? ys.length : 0;
|
||||
if (n === 0) return [];
|
||||
const xArr =
|
||||
Array.isArray(xs) && xs.length === n ? xs : Array.from({ length: n }, (_, idx) => idx);
|
||||
return computePublicationFit(xArr, ys, { minVal, maxVal }).sampleFits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Heckbert 科学坐标轴刻度取整算法,生成科研图表风格的均匀整洁刻度。
|
||||
*/
|
||||
@@ -8370,33 +8437,8 @@ function createModelFitChart() {
|
||||
*/
|
||||
|
||||
|
||||
const CAPSULE_METRIC_KEYS = Object.freeze([
|
||||
'context',
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'quota_auto',
|
||||
'gemini_5h',
|
||||
'gemini_weekly',
|
||||
'claude_5h',
|
||||
'claude_weekly',
|
||||
]);
|
||||
|
||||
const OVERVIEW_METRIC_KEYS = Object.freeze([
|
||||
'tps',
|
||||
'ttft',
|
||||
'avg_tps',
|
||||
'step_cost',
|
||||
'session_cost',
|
||||
'cache_hit',
|
||||
'session_tokens',
|
||||
'context_usage',
|
||||
'quota_tightest',
|
||||
]);
|
||||
const CAPSULE_METRIC_KEYS = TOPBAR_SLOT_KEYS;
|
||||
|
||||
const THIRD_PARTY_FAMILY_RE = /claude|gpt|anthropic|openai|3p|sonnet|opus|haiku/i;
|
||||
|
||||
@@ -17741,7 +17783,7 @@ const SettingsView = defineComponent({
|
||||
|
||||
const generalTab = SettingsGeneralTab({ onLayoutChange: refreshScroll });
|
||||
const structureTab = SettingsStructureTab({ onLayoutChange: refreshScroll });
|
||||
const accountTab = SettingsAccountTab({ onLayoutChange: refreshScroll });
|
||||
const accountTab = SHOW_ACCOUNT_TAB ? SettingsAccountTab({ onLayoutChange: refreshScroll }) : null;
|
||||
const otherTab = SettingsOtherTab({ onLayoutChange: refreshScroll });
|
||||
|
||||
let showingAccount = false;
|
||||
@@ -17749,25 +17791,27 @@ const SettingsView = defineComponent({
|
||||
const target =
|
||||
subTab === 'structure' ||
|
||||
subTab === 'other' ||
|
||||
(SHOW_ACCOUNT_TAB && subTab === 'account')
|
||||
(accountTab && subTab === 'account')
|
||||
? subTab
|
||||
: 'general';
|
||||
subNavSwitch.setValue(target);
|
||||
patchAttr(generalTab.el, 'hidden', target !== 'general');
|
||||
patchAttr(structureTab.el, 'hidden', target !== 'structure');
|
||||
patchAttr(structureTab.refs.thirdNavBar, 'hidden', target !== 'structure');
|
||||
patchAttr(accountTab.el, 'hidden', !SHOW_ACCOUNT_TAB || target !== 'account');
|
||||
patchAttr(otherTab.el, 'hidden', target !== 'other');
|
||||
const nextShowingAccount = SHOW_ACCOUNT_TAB && target === 'account' && activeView === 'settings';
|
||||
if (nextShowingAccount && !showingAccount) void accountTab.refs.load();
|
||||
showingAccount = nextShowingAccount;
|
||||
if (accountTab) {
|
||||
patchAttr(accountTab.el, 'hidden', target !== 'account');
|
||||
const nextShowingAccount = target === 'account' && activeView === 'settings';
|
||||
if (nextShowingAccount && !showingAccount) void accountTab.refs.load();
|
||||
showingAccount = nextShowingAccount;
|
||||
}
|
||||
refreshScroll();
|
||||
}
|
||||
|
||||
const contentContainer = h(
|
||||
'div',
|
||||
{},
|
||||
SHOW_ACCOUNT_TAB
|
||||
accountTab
|
||||
? [generalTab.el, structureTab.el, accountTab.el, otherTab.el]
|
||||
: [generalTab.el, structureTab.el, otherTab.el]
|
||||
);
|
||||
@@ -17794,7 +17838,7 @@ const SettingsView = defineComponent({
|
||||
if (settings) structureTab.refs.renderSettings(settings);
|
||||
} else if (settingsSubTab === 'other') {
|
||||
if (settings) otherTab.refs.renderSettings(settings, telemetry.contextWindowModels || []);
|
||||
} else if (SHOW_ACCOUNT_TAB && settingsSubTab === 'account') {
|
||||
} else if (accountTab && settingsSubTab === 'account') {
|
||||
accountTab.refs.renderAccount(telemetry?.account, telemetry?.quotas);
|
||||
} else {
|
||||
if (settings) generalTab.refs.renderSettings(settings);
|
||||
@@ -17834,7 +17878,7 @@ const SettingsView = defineComponent({
|
||||
});
|
||||
generalTab.refs.refreshLabels();
|
||||
structureTab.refs.refreshLabels();
|
||||
accountTab.refs.refreshLabels();
|
||||
accountTab?.refs.refreshLabels();
|
||||
otherTab.refs.refreshLabels();
|
||||
refreshScroll();
|
||||
}
|
||||
@@ -17847,7 +17891,7 @@ const SettingsView = defineComponent({
|
||||
subNavSwitch.destroy();
|
||||
generalTab.destroy();
|
||||
structureTab.destroy();
|
||||
accountTab.destroy();
|
||||
accountTab?.destroy();
|
||||
otherTab.destroy();
|
||||
viewScrollbar.destroy();
|
||||
});
|
||||
@@ -18779,7 +18823,7 @@ function isImmediatelyBeforeNode(node, refNode) {
|
||||
function isIdeExtensionChatFrame() {
|
||||
try {
|
||||
if (typeof window === 'undefined') return false;
|
||||
if (window.__AGUsageMonitorBridge?.isIdeChatFrame === true) return true;
|
||||
if (readInjectedWindowBridge()?.isIdeChatFrame === true) return true;
|
||||
return /[?&]extension(?:View|Variant)=/i.test(String(window.location?.search || ''));
|
||||
} catch {
|
||||
return false;
|
||||
@@ -18790,7 +18834,7 @@ function resolveActiveDockTarget(options = undefined) {
|
||||
const settings = telemetryStore.getState().telemetry?.settings;
|
||||
const rawMode =
|
||||
settings?.windowMountMode ??
|
||||
(typeof window !== 'undefined' ? window.__AGUsageMonitorBridge?.mountMode : undefined);
|
||||
readInjectedWindowBridge()?.mountMode;
|
||||
const mountMode =
|
||||
options?.mountMode ||
|
||||
normalizeClientWindowMountMode(rawMode, settings?.enableWindowOverlay);
|
||||
@@ -18891,14 +18935,14 @@ function mountWindowOverlay() {
|
||||
let carryOverMultiPinnedOpen = false;
|
||||
let carryOverPointer = null;
|
||||
try {
|
||||
const prevOv = window.__AGUsageMonitorOverlay;
|
||||
const prevOv = window[WINDOW_OVERLAY_KEY];
|
||||
carryOverTelemetry = prevOv?.getTelemetrySnapshot?.() || null;
|
||||
carryOverTooltipOpen = Boolean(prevOv?.isHoverOpen?.());
|
||||
carryOverPopoverOpen = Boolean(prevOv?.isOpen?.());
|
||||
carryOverMultiHoverOpen = Boolean(prevOv?.isMultiHoverOpen?.());
|
||||
carryOverMultiPinnedOpen = Boolean(prevOv?.isMultiPinnedOpen?.());
|
||||
carryOverPointer = prevOv?.getLastPointer?.() || null;
|
||||
prevOv?.dispose?.();
|
||||
prevOv?.[WINDOW_OVERLAY_METHODS.dispose]?.();
|
||||
} catch {
|
||||
// 忽略旧实例卸载异常
|
||||
}
|
||||
@@ -21036,28 +21080,28 @@ function mountWindowOverlay() {
|
||||
|
||||
const handle = {
|
||||
bundleVersion,
|
||||
ensureAlive() {
|
||||
[WINDOW_OVERLAY_METHODS.ensureAlive]() {
|
||||
if (disposed) return false;
|
||||
return ensureCapsuleDocked();
|
||||
},
|
||||
syncHostRoute() {
|
||||
[WINDOW_OVERLAY_METHODS.syncHostRoute]() {
|
||||
if (disposed) return false;
|
||||
syncHostRouteIfChanged();
|
||||
return true;
|
||||
},
|
||||
updateBridge(nextBridge) {
|
||||
[WINDOW_OVERLAY_METHODS.updateBridge](nextBridge) {
|
||||
if (disposed || !nextBridge || typeof nextBridge !== 'object') return false;
|
||||
const port = Number(nextBridge.port || 0);
|
||||
const token = String(nextBridge.token || '');
|
||||
if (!Number.isInteger(port) || port <= 0 || !token) return false;
|
||||
const cur = window.__AGUsageMonitorBridge || {};
|
||||
const cur = readInjectedWindowBridge() || {};
|
||||
const portChanged = Number(cur.port || 0) !== port || String(cur.token || '') !== token;
|
||||
cur.port = port;
|
||||
cur.token = token;
|
||||
if (portChanged) {
|
||||
cur.transportMode = 'http';
|
||||
}
|
||||
window.__AGUsageMonitorBridge = cur;
|
||||
window[WINDOW_BRIDGE_KEY] = cur;
|
||||
void fetchTelemetry({ force: false });
|
||||
return true;
|
||||
},
|
||||
@@ -21067,7 +21111,7 @@ function mountWindowOverlay() {
|
||||
getLastPointer() {
|
||||
return hasPointerCoords ? { x: lastPointerX, y: lastPointerY } : null;
|
||||
},
|
||||
deliverRpc(responses) {
|
||||
[WINDOW_OVERLAY_METHODS.deliverRpc](responses) {
|
||||
if (disposed) return 0;
|
||||
return deliverCdpBridgeResponses(responses);
|
||||
},
|
||||
@@ -21092,14 +21136,13 @@ function mountWindowOverlay() {
|
||||
isMultiHoverOpen: () => Boolean(multiOpen && !multiPinned),
|
||||
isMultiPinnedOpen: () => Boolean(multiOpen && multiPinned),
|
||||
getLayoutMode: () => layoutMode,
|
||||
getDockKind: () => String(capsuleHost.getAttribute('data-dock') || ''),
|
||||
getMountMode: () => lastAppliedMountMode,
|
||||
applyMountMode(nextMode) {
|
||||
[WINDOW_OVERLAY_METHODS.getDockKind]: () => String(capsuleHost.getAttribute('data-dock') || ''),
|
||||
[WINDOW_OVERLAY_METHODS.getMountMode]: () => lastAppliedMountMode,
|
||||
[WINDOW_OVERLAY_METHODS.applyMountMode](nextMode) {
|
||||
if (disposed) return false;
|
||||
const normalized = normalizeClientWindowMountMode(nextMode, nextMode !== 'sidebar');
|
||||
if (typeof window !== 'undefined' && window.__AGUsageMonitorBridge) {
|
||||
window.__AGUsageMonitorBridge.mountMode = normalized;
|
||||
}
|
||||
const bridgeConfig = readInjectedWindowBridge();
|
||||
if (bridgeConfig) bridgeConfig.mountMode = normalized;
|
||||
const curTel = telemetryStore.getState().telemetry;
|
||||
if (curTel?.settings) {
|
||||
telemetryStore.setState({
|
||||
@@ -21116,7 +21159,7 @@ function mountWindowOverlay() {
|
||||
lastAppliedMountMode = normalized;
|
||||
return ensureCapsuleDocked();
|
||||
},
|
||||
dispose() {
|
||||
[WINDOW_OVERLAY_METHODS.dispose]() {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
clearInterval(watchdogTimer);
|
||||
@@ -21169,13 +21212,13 @@ function mountWindowOverlay() {
|
||||
try {
|
||||
portalHost.remove();
|
||||
} catch {}
|
||||
if (window.__AGUsageMonitorOverlay === handle) {
|
||||
delete window.__AGUsageMonitorOverlay;
|
||||
if (window[WINDOW_OVERLAY_KEY] === handle) {
|
||||
delete window[WINDOW_OVERLAY_KEY];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
window.__AGUsageMonitorOverlay = handle;
|
||||
window[WINDOW_OVERLAY_KEY] = handle;
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user