mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): refine macOS overlay geometry, port discovery, font tokens, and LF bundling
Co-authored-by: Swei <sweilo@qq.com>
This commit is contained in:
+50
-6
@@ -3084,6 +3084,7 @@ function isEquivalentTelemetry(prev, next) {
|
|||||||
if ((pSet?.language ?? 'zh-CN') !== (nSet?.language ?? 'zh-CN')) return false;
|
if ((pSet?.language ?? 'zh-CN') !== (nSet?.language ?? 'zh-CN')) return false;
|
||||||
if ((pSet?.themeAccent ?? 'host') !== (nSet?.themeAccent ?? 'host')) return false;
|
if ((pSet?.themeAccent ?? 'host') !== (nSet?.themeAccent ?? 'host')) return false;
|
||||||
if ((pSet?.fontScale ?? 'md') !== (nSet?.fontScale ?? 'md')) return false;
|
if ((pSet?.fontScale ?? 'md') !== (nSet?.fontScale ?? 'md')) return false;
|
||||||
|
if ((prev.hostPlatform || '') !== (next.hostPlatform || '')) return false;
|
||||||
if (Boolean(pSet?.contextWindowRiskAccepted) !== Boolean(nSet?.contextWindowRiskAccepted)) {
|
if (Boolean(pSet?.contextWindowRiskAccepted) !== Boolean(nSet?.contextWindowRiskAccepted)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -4176,6 +4177,24 @@ function resolveScopedConversation(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断宿主系统是否为 macOS (`darwin`):优先读取后端遥测或双栖桥接注入的 `platform`,首帧缺省时回退 UA/平台标识。
|
||||||
|
*
|
||||||
|
* @param {Record<string, any>|null|undefined} telemetry
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function isMacHostPlatform(telemetry) {
|
||||||
|
const p = String(telemetry?.hostPlatform || readInjectedWindowBridge()?.platform || '')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
if (p) return p === 'darwin';
|
||||||
|
if (typeof navigator !== 'undefined') {
|
||||||
|
const ua = String(navigator.platform || navigator.userAgent || '');
|
||||||
|
return /\b(?:mac|darwin)\b|macintosh|mac\s*os/i.test(ua);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// --- src/components/ui/TopLongPillNav.js ---
|
// --- src/components/ui/TopLongPillNav.js ---
|
||||||
/**
|
/**
|
||||||
* @fileoverview Top Long-Pill Navigation Bar (顶部唯一长药丸功能分割栏).
|
* @fileoverview Top Long-Pill Navigation Bar (顶部唯一长药丸功能分割栏).
|
||||||
@@ -19888,6 +19907,8 @@ function mountWindowOverlay() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMac = () => isMacHostPlatform(telemetryStore.getState().telemetry);
|
||||||
|
|
||||||
function updateFixedFallbackPosition() {
|
function updateFixedFallbackPosition() {
|
||||||
const dockMode = capsuleHost.getAttribute('data-dock');
|
const dockMode = capsuleHost.getAttribute('data-dock');
|
||||||
if (dockMode === 'flow' || dockMode === 'ide-titlebar' || dockMode === 'composer') {
|
if (dockMode === 'flow' || dockMode === 'ide-titlebar' || dockMode === 'composer') {
|
||||||
@@ -19897,12 +19918,13 @@ function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const vw = Number(window.innerWidth || 1280);
|
const vw = Number(window.innerWidth || 1280);
|
||||||
let rightOffset = 144;
|
const minRight = isMac() ? 12 : 144;
|
||||||
|
let rightOffset = minRight;
|
||||||
const anchor = findNativeTopRightAnchor();
|
const anchor = findNativeTopRightAnchor();
|
||||||
if (anchor?.getBoundingClientRect) {
|
if (anchor?.getBoundingClientRect) {
|
||||||
const r = anchor.getBoundingClientRect();
|
const r = anchor.getBoundingClientRect();
|
||||||
if (r.width > 0 && r.left > 0 && r.left < vw) {
|
if (r.width > 0 && r.left > 0 && r.left < vw) {
|
||||||
rightOffset = Math.max(144, Math.ceil(vw - r.left + 6));
|
rightOffset = Math.max(minRight, Math.ceil(vw - r.left + 6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
capsuleHost.style.top = '7px';
|
capsuleHost.style.top = '7px';
|
||||||
@@ -19912,6 +19934,16 @@ function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncCapsuleOsAttr() {
|
||||||
|
const nextOs = isMac() ? 'mac' : 'default';
|
||||||
|
if (capsuleHost.getAttribute('data-os') !== nextOs) {
|
||||||
|
patchAttr(capsuleHost, 'data-os', nextOs);
|
||||||
|
if (capsuleHost.getAttribute('data-dock') === 'fixed') {
|
||||||
|
updateFixedFallbackPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function measureAvailableTitlebarWidth(dockTarget) {
|
function measureAvailableTitlebarWidth(dockTarget) {
|
||||||
try {
|
try {
|
||||||
const titlebar = dockTarget?.titlebar || null;
|
const titlebar = dockTarget?.titlebar || null;
|
||||||
@@ -19981,11 +20013,20 @@ function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasVisibleWindowControls && navigator?.windowControlsOverlay?.visible) {
|
if (navigator?.windowControlsOverlay?.visible) {
|
||||||
const wcoRect = navigator.windowControlsOverlay.getTitlebarAreaRect?.();
|
const wcoRect = navigator.windowControlsOverlay.getTitlebarAreaRect?.();
|
||||||
if (wcoRect && wcoRect.width > 0 && tbRect.right > wcoRect.right + 4) {
|
if (wcoRect && wcoRect.width > 0) {
|
||||||
|
if (!hasVisibleWindowControls && tbRect.right > wcoRect.right + 4) {
|
||||||
rightSiblingsWidth += tbRect.right - wcoRect.right;
|
rightSiblingsWidth += tbRect.right - wcoRect.right;
|
||||||
}
|
}
|
||||||
|
const leftOverlayInset = wcoRect.left - tbRect.left;
|
||||||
|
if (leftOverlayInset > leftContentWidth) {
|
||||||
|
leftContentWidth = Math.min(
|
||||||
|
Math.round(tbRect.width * 0.45),
|
||||||
|
Math.ceil(leftOverlayInset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tbRect.width - leftContentWidth - minCenterWidth - rightSiblingsWidth - 28;
|
return tbRect.width - leftContentWidth - minCenterWidth - rightSiblingsWidth - 28;
|
||||||
@@ -19997,10 +20038,11 @@ function mountWindowOverlay() {
|
|||||||
if (tbRect.width > 0) {
|
if (tbRect.width > 0) {
|
||||||
const titleEl = titlebar.firstElementChild;
|
const titleEl = titlebar.firstElementChild;
|
||||||
const titleInner = titleEl?.firstElementChild;
|
const titleInner = titleEl?.firstElementChild;
|
||||||
|
const macTrafficReserve = isMac() ? 80 : 168;
|
||||||
const contentStart = titleInner?.getBoundingClientRect
|
const contentStart = titleInner?.getBoundingClientRect
|
||||||
? Math.max(8, titleInner.getBoundingClientRect().left - tbRect.left)
|
? Math.max(8, titleInner.getBoundingClientRect().left - tbRect.left)
|
||||||
: tbRect.left < 168
|
: tbRect.left < macTrafficReserve
|
||||||
? 168 - tbRect.left
|
? macTrafficReserve - tbRect.left
|
||||||
: 12;
|
: 12;
|
||||||
const minTitleWidth = 180;
|
const minTitleWidth = 180;
|
||||||
let siblingButtonsWidth = 64;
|
let siblingButtonsWidth = 64;
|
||||||
@@ -20278,6 +20320,7 @@ function mountWindowOverlay() {
|
|||||||
if (bodyOrDoc && !portalHost.isConnected) {
|
if (bodyOrDoc && !portalHost.isConnected) {
|
||||||
bodyOrDoc.appendChild(portalHost);
|
bodyOrDoc.appendChild(portalHost);
|
||||||
}
|
}
|
||||||
|
syncCapsuleOsAttr();
|
||||||
ensureWorkbenchThemeObserved();
|
ensureWorkbenchThemeObserved();
|
||||||
|
|
||||||
const dockTarget = resolveRuntimeDockTarget();
|
const dockTarget = resolveRuntimeDockTarget();
|
||||||
@@ -20762,6 +20805,7 @@ function mountWindowOverlay() {
|
|||||||
|
|
||||||
setI18nLanguage(telemetry?.settings?.language);
|
setI18nLanguage(telemetry?.settings?.language);
|
||||||
syncPortalAppearance(telemetry?.settings);
|
syncPortalAppearance(telemetry?.settings);
|
||||||
|
syncCapsuleOsAttr();
|
||||||
|
|
||||||
const showMulti = telemetry?.settings?.showTopbarMultiSession !== false;
|
const showMulti = telemetry?.settings?.showTopbarMultiSession !== false;
|
||||||
patchAttr(multiBtn, 'hidden', !showMulti);
|
patchAttr(multiBtn, 'hidden', !showMulti);
|
||||||
|
|||||||
@@ -1488,6 +1488,7 @@ export async function buildTelemetryPayloadInternal(
|
|||||||
|
|
||||||
const finalPayload = {
|
const finalPayload = {
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
|
hostPlatform: process.platform || 'unknown',
|
||||||
uiBundleVersion,
|
uiBundleVersion,
|
||||||
settings,
|
settings,
|
||||||
contextWindowModels: getContextWindowGroups(getContextWindowModels(clientConfigs, contextModelCatalog)).map((group) => {
|
contextWindowModels: getContextWindowGroups(getContextWindowModels(clientConfigs, contextModelCatalog)).map((group) => {
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ export function resolveDevToolsPortCandidates(
|
|||||||
return [
|
return [
|
||||||
join(homeDir, 'Library', 'Application Support', 'Antigravity', 'DevToolsActivePort'),
|
join(homeDir, 'Library', 'Application Support', 'Antigravity', 'DevToolsActivePort'),
|
||||||
join(homeDir, 'Library', 'Application Support', 'Antigravity IDE', 'DevToolsActivePort'),
|
join(homeDir, 'Library', 'Application Support', 'Antigravity IDE', 'DevToolsActivePort'),
|
||||||
|
join(homeDir, 'Library', 'Application Support', 'antigravity', 'DevToolsActivePort'),
|
||||||
|
join(homeDir, 'Library', 'Application Support', 'antigravity-ide', 'DevToolsActivePort'),
|
||||||
|
join(homeDir, '.config', 'Antigravity', 'DevToolsActivePort'),
|
||||||
|
join(homeDir, '.config', 'Antigravity IDE', 'DevToolsActivePort'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
const configHome = env?.XDG_CONFIG_HOME || join(homeDir, '.config');
|
const configHome = env?.XDG_CONFIG_HOME || join(homeDir, '.config');
|
||||||
@@ -1408,6 +1412,7 @@ export function createWindowBridgeController(options) {
|
|||||||
port,
|
port,
|
||||||
token,
|
token,
|
||||||
bundleVersion,
|
bundleVersion,
|
||||||
|
platform: String(platform || ''),
|
||||||
mountMode,
|
mountMode,
|
||||||
[WINDOW_BRIDGE_ROUTE_KEY]: ideRouteId || '',
|
[WINDOW_BRIDGE_ROUTE_KEY]: ideRouteId || '',
|
||||||
isIdeChatFrame: Boolean(isIdeChatFrame),
|
isIdeChatFrame: Boolean(isIdeChatFrame),
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>用量监控</title>
|
<title>用量监控</title>
|
||||||
<link rel="stylesheet" href="/styles.css?v=1794918424113">
|
<link rel="stylesheet" href="/styles.css?v=1794921701656">
|
||||||
<script src="/preload.js"></script>
|
<script src="/preload.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app-root"></div>
|
<div id="app-root"></div>
|
||||||
<script src="/app.js?v=1794918424113"></script>
|
<script src="/app.js?v=1794921701656"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -459,7 +459,10 @@ export function buildBundle(panelDir = PANEL_DIR) {
|
|||||||
|
|
||||||
const cssBundle =
|
const cssBundle =
|
||||||
cssOrder
|
cssOrder
|
||||||
.map((rel) => `/* --- ${rel} --- */\n${readFileSync(join(panelDir, rel), 'utf8').trim()}`)
|
.map(
|
||||||
|
(rel) =>
|
||||||
|
`/* --- ${rel} --- */\n${readFileSync(join(panelDir, rel), 'utf8').replace(/\r\n/g, '\n').trim()}`
|
||||||
|
)
|
||||||
.join('\n\n') + '\n';
|
.join('\n\n') + '\n';
|
||||||
|
|
||||||
const jsOrder = [
|
const jsOrder = [
|
||||||
@@ -520,7 +523,7 @@ export function buildBundle(panelDir = PANEL_DIR) {
|
|||||||
.map((rel) => {
|
.map((rel) => {
|
||||||
const path = resolve(panelDir, rel);
|
const path = resolve(panelDir, rel);
|
||||||
if (bundledPaths.has(path)) throw new Error(`${rel}: duplicate entry in jsOrder`);
|
if (bundledPaths.has(path)) throw new Error(`${rel}: duplicate entry in jsOrder`);
|
||||||
const raw = readFileSync(path, 'utf8');
|
const raw = readFileSync(path, 'utf8').replace(/\r\n/g, '\n');
|
||||||
const stripped = stripModuleSyntax(raw, (specifier, clause) =>
|
const stripped = stripModuleSyntax(raw, (specifier, clause) =>
|
||||||
validateBundleImport(path, specifier, clause, bundledPaths)
|
validateBundleImport(path, specifier, clause, bundledPaths)
|
||||||
);
|
);
|
||||||
@@ -536,6 +539,7 @@ export function buildBundle(panelDir = PANEL_DIR) {
|
|||||||
const indexHtmlPath = join(panelDir, 'index.html');
|
const indexHtmlPath = join(panelDir, 'index.html');
|
||||||
const html = existsSync(indexHtmlPath)
|
const html = existsSync(indexHtmlPath)
|
||||||
? readFileSync(indexHtmlPath, 'utf8')
|
? readFileSync(indexHtmlPath, 'utf8')
|
||||||
|
.replace(/\r\n/g, '\n')
|
||||||
.replace(/href="\/styles\.css(?:\?v=[^"]*)?"/, `href="/styles.css?v=${ver}"`)
|
.replace(/href="\/styles\.css(?:\?v=[^"]*)?"/, `href="/styles.css?v=${ver}"`)
|
||||||
.replace(/src="\/app\.js(?:\?v=[^"]*)?"/, `src="/app.js?v=${ver}"`)
|
.replace(/src="\/app\.js(?:\?v=[^"]*)?"/, `src="/app.js?v=${ver}"`)
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import {
|
|||||||
fetchTelemetry,
|
fetchTelemetry,
|
||||||
formatAgentBadgeText,
|
formatAgentBadgeText,
|
||||||
getAgentBadgeClass,
|
getAgentBadgeClass,
|
||||||
|
isMacHostPlatform,
|
||||||
normalizeClientHoverModules,
|
normalizeClientHoverModules,
|
||||||
normalizeClientPopoverWidth,
|
normalizeClientPopoverWidth,
|
||||||
normalizeClientPopoverWidthMode,
|
normalizeClientPopoverWidthMode,
|
||||||
@@ -1777,6 +1778,8 @@ export function mountWindowOverlay() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMac = () => isMacHostPlatform(telemetryStore.getState().telemetry);
|
||||||
|
|
||||||
function updateFixedFallbackPosition() {
|
function updateFixedFallbackPosition() {
|
||||||
const dockMode = capsuleHost.getAttribute('data-dock');
|
const dockMode = capsuleHost.getAttribute('data-dock');
|
||||||
if (dockMode === 'flow' || dockMode === 'ide-titlebar' || dockMode === 'composer') {
|
if (dockMode === 'flow' || dockMode === 'ide-titlebar' || dockMode === 'composer') {
|
||||||
@@ -1786,12 +1789,13 @@ export function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const vw = Number(window.innerWidth || 1280);
|
const vw = Number(window.innerWidth || 1280);
|
||||||
let rightOffset = 144;
|
const minRight = isMac() ? 12 : 144;
|
||||||
|
let rightOffset = minRight;
|
||||||
const anchor = findNativeTopRightAnchor();
|
const anchor = findNativeTopRightAnchor();
|
||||||
if (anchor?.getBoundingClientRect) {
|
if (anchor?.getBoundingClientRect) {
|
||||||
const r = anchor.getBoundingClientRect();
|
const r = anchor.getBoundingClientRect();
|
||||||
if (r.width > 0 && r.left > 0 && r.left < vw) {
|
if (r.width > 0 && r.left > 0 && r.left < vw) {
|
||||||
rightOffset = Math.max(144, Math.ceil(vw - r.left + 6));
|
rightOffset = Math.max(minRight, Math.ceil(vw - r.left + 6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
capsuleHost.style.top = '7px';
|
capsuleHost.style.top = '7px';
|
||||||
@@ -1801,6 +1805,16 @@ export function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncCapsuleOsAttr() {
|
||||||
|
const nextOs = isMac() ? 'mac' : 'default';
|
||||||
|
if (capsuleHost.getAttribute('data-os') !== nextOs) {
|
||||||
|
patchAttr(capsuleHost, 'data-os', nextOs);
|
||||||
|
if (capsuleHost.getAttribute('data-dock') === 'fixed') {
|
||||||
|
updateFixedFallbackPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function measureAvailableTitlebarWidth(dockTarget) {
|
function measureAvailableTitlebarWidth(dockTarget) {
|
||||||
try {
|
try {
|
||||||
const titlebar = dockTarget?.titlebar || null;
|
const titlebar = dockTarget?.titlebar || null;
|
||||||
@@ -1870,11 +1884,20 @@ export function mountWindowOverlay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasVisibleWindowControls && navigator?.windowControlsOverlay?.visible) {
|
if (navigator?.windowControlsOverlay?.visible) {
|
||||||
const wcoRect = navigator.windowControlsOverlay.getTitlebarAreaRect?.();
|
const wcoRect = navigator.windowControlsOverlay.getTitlebarAreaRect?.();
|
||||||
if (wcoRect && wcoRect.width > 0 && tbRect.right > wcoRect.right + 4) {
|
if (wcoRect && wcoRect.width > 0) {
|
||||||
|
if (!hasVisibleWindowControls && tbRect.right > wcoRect.right + 4) {
|
||||||
rightSiblingsWidth += tbRect.right - wcoRect.right;
|
rightSiblingsWidth += tbRect.right - wcoRect.right;
|
||||||
}
|
}
|
||||||
|
const leftOverlayInset = wcoRect.left - tbRect.left;
|
||||||
|
if (leftOverlayInset > leftContentWidth) {
|
||||||
|
leftContentWidth = Math.min(
|
||||||
|
Math.round(tbRect.width * 0.45),
|
||||||
|
Math.ceil(leftOverlayInset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tbRect.width - leftContentWidth - minCenterWidth - rightSiblingsWidth - 28;
|
return tbRect.width - leftContentWidth - minCenterWidth - rightSiblingsWidth - 28;
|
||||||
@@ -1886,10 +1909,11 @@ export function mountWindowOverlay() {
|
|||||||
if (tbRect.width > 0) {
|
if (tbRect.width > 0) {
|
||||||
const titleEl = titlebar.firstElementChild;
|
const titleEl = titlebar.firstElementChild;
|
||||||
const titleInner = titleEl?.firstElementChild;
|
const titleInner = titleEl?.firstElementChild;
|
||||||
|
const macTrafficReserve = isMac() ? 80 : 168;
|
||||||
const contentStart = titleInner?.getBoundingClientRect
|
const contentStart = titleInner?.getBoundingClientRect
|
||||||
? Math.max(8, titleInner.getBoundingClientRect().left - tbRect.left)
|
? Math.max(8, titleInner.getBoundingClientRect().left - tbRect.left)
|
||||||
: tbRect.left < 168
|
: tbRect.left < macTrafficReserve
|
||||||
? 168 - tbRect.left
|
? macTrafficReserve - tbRect.left
|
||||||
: 12;
|
: 12;
|
||||||
const minTitleWidth = 180;
|
const minTitleWidth = 180;
|
||||||
let siblingButtonsWidth = 64;
|
let siblingButtonsWidth = 64;
|
||||||
@@ -2167,6 +2191,7 @@ export function mountWindowOverlay() {
|
|||||||
if (bodyOrDoc && !portalHost.isConnected) {
|
if (bodyOrDoc && !portalHost.isConnected) {
|
||||||
bodyOrDoc.appendChild(portalHost);
|
bodyOrDoc.appendChild(portalHost);
|
||||||
}
|
}
|
||||||
|
syncCapsuleOsAttr();
|
||||||
ensureWorkbenchThemeObserved();
|
ensureWorkbenchThemeObserved();
|
||||||
|
|
||||||
const dockTarget = resolveRuntimeDockTarget();
|
const dockTarget = resolveRuntimeDockTarget();
|
||||||
@@ -2651,6 +2676,7 @@ export function mountWindowOverlay() {
|
|||||||
|
|
||||||
setI18nLanguage(telemetry?.settings?.language);
|
setI18nLanguage(telemetry?.settings?.language);
|
||||||
syncPortalAppearance(telemetry?.settings);
|
syncPortalAppearance(telemetry?.settings);
|
||||||
|
syncCapsuleOsAttr();
|
||||||
|
|
||||||
const showMulti = telemetry?.settings?.showTopbarMultiSession !== false;
|
const showMulti = telemetry?.settings?.showTopbarMultiSession !== false;
|
||||||
patchAttr(multiBtn, 'hidden', !showMulti);
|
patchAttr(multiBtn, 'hidden', !showMulti);
|
||||||
|
|||||||
@@ -399,6 +399,7 @@ function isEquivalentTelemetry(prev, next) {
|
|||||||
if ((pSet?.language ?? 'zh-CN') !== (nSet?.language ?? 'zh-CN')) return false;
|
if ((pSet?.language ?? 'zh-CN') !== (nSet?.language ?? 'zh-CN')) return false;
|
||||||
if ((pSet?.themeAccent ?? 'host') !== (nSet?.themeAccent ?? 'host')) return false;
|
if ((pSet?.themeAccent ?? 'host') !== (nSet?.themeAccent ?? 'host')) return false;
|
||||||
if ((pSet?.fontScale ?? 'md') !== (nSet?.fontScale ?? 'md')) return false;
|
if ((pSet?.fontScale ?? 'md') !== (nSet?.fontScale ?? 'md')) return false;
|
||||||
|
if ((prev.hostPlatform || '') !== (next.hostPlatform || '')) return false;
|
||||||
if (Boolean(pSet?.contextWindowRiskAccepted) !== Boolean(nSet?.contextWindowRiskAccepted)) {
|
if (Boolean(pSet?.contextWindowRiskAccepted) !== Boolean(nSet?.contextWindowRiskAccepted)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1490,3 +1491,21 @@ export function resolveScopedConversation(
|
|||||||
ctxAgent,
|
ctxAgent,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断宿主系统是否为 macOS (`darwin`):优先读取后端遥测或双栖桥接注入的 `platform`,首帧缺省时回退 UA/平台标识。
|
||||||
|
*
|
||||||
|
* @param {Record<string, any>|null|undefined} telemetry
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function isMacHostPlatform(telemetry) {
|
||||||
|
const p = String(telemetry?.hostPlatform || readInjectedWindowBridge()?.platform || '')
|
||||||
|
.trim()
|
||||||
|
.toLowerCase();
|
||||||
|
if (p) return p === 'darwin';
|
||||||
|
if (typeof navigator !== 'undefined') {
|
||||||
|
const ua = String(navigator.platform || navigator.userAgent || '');
|
||||||
|
return /\b(?:mac|darwin)\b|macintosh|mac\s*os/i.test(ua);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ body {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: var(--surface-bg);
|
background: var(--surface-bg);
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
font-family: var(--font-sans);
|
||||||
font-size: var(--fs-body);
|
font-size: var(--fs-body);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
button,
|
button,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
font-family: "Google Sans Flex", "Google Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
font-family: "Google Sans Flex", "Google Sans", system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 450;
|
font-weight: 450;
|
||||||
font-stretch: 100%;
|
font-stretch: 100%;
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
letter-spacing: 0.015em;
|
letter-spacing: 0.015em;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
z-index: 2147482900;
|
z-index: 2147482900;
|
||||||
}
|
}
|
||||||
@@ -77,6 +78,10 @@
|
|||||||
right: 144px;
|
right: 144px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host(.wm-capsule-host[data-dock="fixed"][data-os="mac"]) {
|
||||||
|
right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes wm-dot-pulse {
|
@keyframes wm-dot-pulse {
|
||||||
0%, 100% {
|
0%, 100% {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -518,11 +523,12 @@
|
|||||||
overflow: visible;
|
overflow: visible;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 2147483000;
|
z-index: 2147483000;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
font-family: var(--font-sans);
|
||||||
font-size: var(--fs-body);
|
font-size: var(--fs-body);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
:root,
|
:root,
|
||||||
:host {
|
:host {
|
||||||
|
/* Cross-Platform Typography Stacks (macOS SF Pro / SF Mono + Windows / Linux Fallbacks) */
|
||||||
|
--font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
|
||||||
|
--font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, "Cascadia Mono", Consolas, monospace;
|
||||||
|
|
||||||
/* Architectural Geometry: Only Top Nav uses --radius-pill */
|
/* Architectural Geometry: Only Top Nav uses --radius-pill */
|
||||||
--radius-pill: 999px;
|
--radius-pill: 999px;
|
||||||
--radius-sm: 4px;
|
--radius-sm: 4px;
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
:root,
|
:root,
|
||||||
:host {
|
:host {
|
||||||
|
/* Cross-Platform Typography Stacks (macOS SF Pro / SF Mono + Windows / Linux Fallbacks) */
|
||||||
|
--font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
|
||||||
|
--font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, "Cascadia Mono", Consolas, monospace;
|
||||||
|
|
||||||
/* Architectural Geometry: Only Top Nav uses --radius-pill */
|
/* Architectural Geometry: Only Top Nav uses --radius-pill */
|
||||||
--radius-pill: 999px;
|
--radius-pill: 999px;
|
||||||
--radius-sm: 4px;
|
--radius-sm: 4px;
|
||||||
@@ -204,11 +208,12 @@ body {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: var(--surface-bg);
|
background: var(--surface-bg);
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
font-family: var(--font-sans);
|
||||||
font-size: var(--fs-body);
|
font-size: var(--fs-body);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
button,
|
button,
|
||||||
@@ -4159,7 +4164,7 @@ html[data-standalone="true"] .app-shell {
|
|||||||
-webkit-app-region: no-drag;
|
-webkit-app-region: no-drag;
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
font-family: "Google Sans Flex", "Google Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
font-family: "Google Sans Flex", "Google Sans", system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 450;
|
font-weight: 450;
|
||||||
font-stretch: 100%;
|
font-stretch: 100%;
|
||||||
@@ -4168,6 +4173,7 @@ html[data-standalone="true"] .app-shell {
|
|||||||
letter-spacing: 0.015em;
|
letter-spacing: 0.015em;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
z-index: 2147482900;
|
z-index: 2147482900;
|
||||||
}
|
}
|
||||||
@@ -4221,6 +4227,10 @@ html[data-standalone="true"] .app-shell {
|
|||||||
right: 144px;
|
right: 144px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host(.wm-capsule-host[data-dock="fixed"][data-os="mac"]) {
|
||||||
|
right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes wm-dot-pulse {
|
@keyframes wm-dot-pulse {
|
||||||
0%, 100% {
|
0%, 100% {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -4662,11 +4672,12 @@ html[data-standalone="true"] .app-shell {
|
|||||||
overflow: visible;
|
overflow: visible;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 2147483000;
|
z-index: 2147483000;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
font-family: var(--font-sans);
|
||||||
font-size: var(--fs-body);
|
font-size: var(--fs-body);
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -638,7 +638,15 @@ test('panel typography scales all view/table/chart CSS rules via --fs-* tokens w
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const tokensCss = fs.readFileSync(join(stylesDir, 'tokens.css'), 'utf8');
|
const tokensCss = fs.readFileSync(join(stylesDir, 'tokens.css'), 'utf8');
|
||||||
|
assert.match(tokensCss, /--font-sans\s*:[^;]+"SF Pro Text"/);
|
||||||
|
assert.match(tokensCss, /--font-mono\s*:\s*ui-monospace,\s*SFMono-Regular,\s*"SF Mono"/);
|
||||||
assert.match(tokensCss, /:host\(\[data-font-scale="xl"\]\)/);
|
assert.match(tokensCss, /:host\(\[data-font-scale="xl"\]\)/);
|
||||||
assert.match(tokensCss, /\[data-font-scale\]\s*\{[\s\S]*?--fs-base-sm:/);
|
assert.match(tokensCss, /\[data-font-scale\]\s*\{[\s\S]*?--fs-base-sm:/);
|
||||||
assert.doesNotMatch(tokensCss, /:root,\s*:host\s*\{[^}]*--ui-font-scale\s*:\s*1\s*;/);
|
assert.doesNotMatch(tokensCss, /:root,\s*:host\s*\{[^}]*--ui-font-scale\s*:\s*1\s*;/);
|
||||||
|
|
||||||
|
const panelRoot = fileURLToPath(new URL('..', import.meta.url));
|
||||||
|
for (const artifact of ['styles.css', 'app.js', 'index.html']) {
|
||||||
|
const rawArtifact = fs.readFileSync(join(panelRoot, artifact), 'utf8');
|
||||||
|
assert.equal(rawArtifact.includes('\r\n'), false, `${artifact} must normalize line endings to LF`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ test('DevToolsActivePort parsing, cross-platform discovery (2.0 + IDE), and stri
|
|||||||
assert.equal(winPaths[3], path.join('C:\\Local', 'Antigravity IDE', 'DevToolsActivePort'));
|
assert.equal(winPaths[3], path.join('C:\\Local', 'Antigravity IDE', 'DevToolsActivePort'));
|
||||||
|
|
||||||
const macPaths = resolveDevToolsPortCandidates({}, 'darwin', '/Users/dev');
|
const macPaths = resolveDevToolsPortCandidates({}, 'darwin', '/Users/dev');
|
||||||
assert.equal(macPaths.length, 2);
|
assert.equal(macPaths.length, 6);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
macPaths[0],
|
macPaths[0],
|
||||||
path.join('/Users/dev', 'Library', 'Application Support', 'Antigravity', 'DevToolsActivePort')
|
path.join('/Users/dev', 'Library', 'Application Support', 'Antigravity', 'DevToolsActivePort')
|
||||||
@@ -80,6 +80,22 @@ test('DevToolsActivePort parsing, cross-platform discovery (2.0 + IDE), and stri
|
|||||||
macPaths[1],
|
macPaths[1],
|
||||||
path.join('/Users/dev', 'Library', 'Application Support', 'Antigravity IDE', 'DevToolsActivePort')
|
path.join('/Users/dev', 'Library', 'Application Support', 'Antigravity IDE', 'DevToolsActivePort')
|
||||||
);
|
);
|
||||||
|
assert.equal(
|
||||||
|
macPaths[2],
|
||||||
|
path.join('/Users/dev', 'Library', 'Application Support', 'antigravity', 'DevToolsActivePort')
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
macPaths[3],
|
||||||
|
path.join('/Users/dev', 'Library', 'Application Support', 'antigravity-ide', 'DevToolsActivePort')
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
macPaths[4],
|
||||||
|
path.join('/Users/dev', '.config', 'Antigravity', 'DevToolsActivePort')
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
macPaths[5],
|
||||||
|
path.join('/Users/dev', '.config', 'Antigravity IDE', 'DevToolsActivePort')
|
||||||
|
);
|
||||||
|
|
||||||
const linuxPaths = resolveDevToolsPortCandidates({ XDG_CONFIG_HOME: '/home/dev/.config' }, 'linux', '/home/dev');
|
const linuxPaths = resolveDevToolsPortCandidates({ XDG_CONFIG_HOME: '/home/dev/.config' }, 'linux', '/home/dev');
|
||||||
assert.equal(linuxPaths.length, 2);
|
assert.equal(linuxPaths.length, 2);
|
||||||
@@ -5718,3 +5734,277 @@ test('v1.5 feedback E2E: sticky bridge port/token across hot-reloads, CDP->HTTP
|
|||||||
ov.dispose();
|
ov.dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('WindowOverlayShell macOS (darwin) adaptation: sets data-os="mac", uses 12px fixed right fallback, and reserves 80px for traffic lights', async () => {
|
||||||
|
const panelDir = path.resolve(import.meta.dirname, '..');
|
||||||
|
const appJs = fs.readFileSync(path.join(panelDir, 'app.js'), 'utf8');
|
||||||
|
const stylesCss = fs.readFileSync(path.join(panelDir, 'styles.css'), 'utf8');
|
||||||
|
assert.match(stylesCss, /:host\(\.wm-capsule-host\[data-dock="fixed"\]\[data-os="mac"\]\)\s*\{\s*right:\s*12px;/);
|
||||||
|
|
||||||
|
function runOverlayForPlatform(platformKey, { withTitlebar = false, auxLeft = 0, winWidth = 1280 } = {}) {
|
||||||
|
function makeNode(tag) {
|
||||||
|
const attrs = new Map();
|
||||||
|
const clsSet = new Set();
|
||||||
|
const listeners = new Map();
|
||||||
|
let rectOverride = null;
|
||||||
|
const el = {
|
||||||
|
tagName: String(tag || 'DIV').toUpperCase(),
|
||||||
|
id: '',
|
||||||
|
textContent: '',
|
||||||
|
dataset: {},
|
||||||
|
offsetWidth: 0,
|
||||||
|
offsetHeight: 0,
|
||||||
|
clientWidth: 0,
|
||||||
|
scrollWidth: 0,
|
||||||
|
parentNode: null,
|
||||||
|
parentElement: null,
|
||||||
|
shadowRoot: null,
|
||||||
|
children: [],
|
||||||
|
style: {
|
||||||
|
setProperty(k, v) { this[k] = String(v); },
|
||||||
|
removeProperty(k) { delete this[k]; },
|
||||||
|
getPropertyValue(k) { return this[k] || ''; },
|
||||||
|
},
|
||||||
|
get isConnected() {
|
||||||
|
let cur = el;
|
||||||
|
while (cur) {
|
||||||
|
if (cur === body || cur === docEl) return true;
|
||||||
|
cur = cur.parentNode;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
get firstChild() { return el.children[0] || null; },
|
||||||
|
get firstElementChild() { return el.children[0] || null; },
|
||||||
|
get lastElementChild() { return el.children[el.children.length - 1] || null; },
|
||||||
|
get className() { return [...clsSet].join(' '); },
|
||||||
|
set className(v) {
|
||||||
|
clsSet.clear();
|
||||||
|
for (const c of String(v || '').split(/\s+/).filter(Boolean)) clsSet.add(c);
|
||||||
|
attrs.set('class', [...clsSet].join(' '));
|
||||||
|
},
|
||||||
|
classList: {
|
||||||
|
add: (...cs) => cs.forEach((c) => c && clsSet.add(c)),
|
||||||
|
remove: (...cs) => cs.forEach((c) => clsSet.delete(c)),
|
||||||
|
contains: (c) => clsSet.has(c),
|
||||||
|
toggle(c, force) {
|
||||||
|
const on = force !== undefined ? Boolean(force) : !clsSet.has(c);
|
||||||
|
if (on) clsSet.add(c);
|
||||||
|
else clsSet.delete(c);
|
||||||
|
return on;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setAttribute(k, v) {
|
||||||
|
if (k === 'class') { el.className = v; return; }
|
||||||
|
attrs.set(k, String(v));
|
||||||
|
if (k === 'id') el.id = String(v);
|
||||||
|
},
|
||||||
|
getAttribute: (k) => (k === 'class' ? el.className : attrs.has(k) ? attrs.get(k) : null),
|
||||||
|
hasAttribute: (k) => attrs.has(k),
|
||||||
|
removeAttribute: (k) => attrs.delete(k),
|
||||||
|
appendChild(ch) {
|
||||||
|
if (!ch) return ch;
|
||||||
|
if (ch.parentNode?.removeChild) ch.parentNode.removeChild(ch);
|
||||||
|
ch.parentNode = el;
|
||||||
|
ch.parentElement = el;
|
||||||
|
el.children.push(ch);
|
||||||
|
return ch;
|
||||||
|
},
|
||||||
|
insertBefore(ch, ref) {
|
||||||
|
if (!ref) return el.appendChild(ch);
|
||||||
|
if (ch.parentNode?.removeChild) ch.parentNode.removeChild(ch);
|
||||||
|
ch.parentNode = el;
|
||||||
|
ch.parentElement = el;
|
||||||
|
const i = el.children.indexOf(ref);
|
||||||
|
if (i < 0) el.children.push(ch);
|
||||||
|
else el.children.splice(i, 0, ch);
|
||||||
|
return ch;
|
||||||
|
},
|
||||||
|
removeChild(ch) {
|
||||||
|
const i = el.children.indexOf(ch);
|
||||||
|
if (i >= 0) {
|
||||||
|
el.children.splice(i, 1);
|
||||||
|
ch.parentNode = null;
|
||||||
|
ch.parentElement = null;
|
||||||
|
}
|
||||||
|
return ch;
|
||||||
|
},
|
||||||
|
remove() { if (el.parentNode?.removeChild) el.parentNode.removeChild(el); },
|
||||||
|
closest: () => null,
|
||||||
|
contains(t) {
|
||||||
|
let cur = t;
|
||||||
|
while (cur) { if (cur === el) return true; cur = cur.parentNode; }
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
attachShadow() {
|
||||||
|
const sr = makeNode('shadow-root');
|
||||||
|
el.shadowRoot = sr;
|
||||||
|
return sr;
|
||||||
|
},
|
||||||
|
addEventListener(type, fn) {
|
||||||
|
if (!listeners.has(type)) listeners.set(type, []);
|
||||||
|
listeners.get(type).push(fn);
|
||||||
|
},
|
||||||
|
removeEventListener() {},
|
||||||
|
setRect(r) { rectOverride = r; },
|
||||||
|
getBoundingClientRect() {
|
||||||
|
return rectOverride || { left: 0, right: 64, top: 6, bottom: 34, width: 64, height: 28 };
|
||||||
|
},
|
||||||
|
querySelectorAll(sel) {
|
||||||
|
const out = [];
|
||||||
|
const walk = (n) => {
|
||||||
|
for (const c of n.children || []) {
|
||||||
|
if (sel === '[class*="@container/titlebar"]' && c.className.includes('@container/titlebar')) out.push(c);
|
||||||
|
else if (sel === '[data-testid="toggle-aux-sidebar"]' && c.getAttribute('data-testid') === 'toggle-aux-sidebar') out.push(c);
|
||||||
|
else if (sel === ':scope > div.shrink-0' && n === el && c.classList.contains('shrink-0')) out.push(c);
|
||||||
|
walk(c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walk(el);
|
||||||
|
return out;
|
||||||
|
},
|
||||||
|
querySelector(sel) { return el.querySelectorAll(sel)[0] || null; },
|
||||||
|
};
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
const docEl = makeNode('html');
|
||||||
|
const body = makeNode('body');
|
||||||
|
docEl.appendChild(body);
|
||||||
|
|
||||||
|
if (withTitlebar) {
|
||||||
|
const tb = makeNode('div');
|
||||||
|
tb.className = 'flex @container/titlebar';
|
||||||
|
tb.setRect({ left: 0, right: winWidth, top: 0, bottom: 36, width: winWidth, height: 36 });
|
||||||
|
const titleGroup = makeNode('div');
|
||||||
|
const rightGroup = makeNode('div');
|
||||||
|
rightGroup.className = 'shrink-0';
|
||||||
|
const siblingBtn = makeNode('button');
|
||||||
|
siblingBtn.setRect({ left: winWidth - 56, right: winWidth, top: 4, bottom: 32, width: 56, height: 28 });
|
||||||
|
rightGroup.appendChild(siblingBtn);
|
||||||
|
tb.appendChild(titleGroup);
|
||||||
|
tb.appendChild(rightGroup);
|
||||||
|
body.appendChild(tb);
|
||||||
|
} else if (auxLeft > 0) {
|
||||||
|
const auxBtn = makeNode('button');
|
||||||
|
auxBtn.setAttribute('data-testid', 'toggle-aux-sidebar');
|
||||||
|
auxBtn.setRect({ left: auxLeft, right: auxLeft + 28, top: 8, bottom: 34, width: 28, height: 26 });
|
||||||
|
body.appendChild(auxBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
timestamp: '2026-11-17T00:00:00Z',
|
||||||
|
hostPlatform: platformKey,
|
||||||
|
settings: { windowMountMode: 'dual', enableWindowOverlay: true, showTopbarMultiSession: true, topbarCapsuleSlots: ['tps', 'ttft', 'context'] },
|
||||||
|
cloudStatus: { updateAvailable: false },
|
||||||
|
account: { planName: 'Pro' },
|
||||||
|
runningConversations: [],
|
||||||
|
conversations: [],
|
||||||
|
activeConversation: { cascadeId: '11111111-2222-3333-4444-555555555555', stepCount: 1, context: { totalTokens: 10000, limitTokens: 256000 } },
|
||||||
|
quotas: { pools: [] },
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockWin = {
|
||||||
|
innerWidth: winWidth,
|
||||||
|
innerHeight: 800,
|
||||||
|
location: { pathname: '/c/11111111-2222-3333-4444-555555555555', search: '' },
|
||||||
|
__AGUsageMonitorBridge: {
|
||||||
|
port: 43111,
|
||||||
|
token: 'c'.repeat(64),
|
||||||
|
bundleVersion: 'ver-mac',
|
||||||
|
platform: platformKey,
|
||||||
|
stylesCss,
|
||||||
|
initialTelemetry: payload,
|
||||||
|
},
|
||||||
|
addEventListener() {},
|
||||||
|
removeEventListener() {},
|
||||||
|
getComputedStyle: () => ({ paddingRight: '8px', getPropertyValue: () => '' }),
|
||||||
|
fetch: async () => ({ ok: true, status: 200, json: async () => payload }),
|
||||||
|
};
|
||||||
|
const mockDoc = {
|
||||||
|
hidden: false,
|
||||||
|
body,
|
||||||
|
head: makeNode('head'),
|
||||||
|
documentElement: docEl,
|
||||||
|
createElement: makeNode,
|
||||||
|
createElementNS: (_ns, t) => makeNode(t),
|
||||||
|
createTextNode: (txt) => ({ nodeType: 3, textContent: String(txt ?? ''), parentNode: null }),
|
||||||
|
getElementById: (id) => body.children.find((c) => c.id === id) || null,
|
||||||
|
querySelector: (s) => body.querySelector(s),
|
||||||
|
querySelectorAll: (s) => body.querySelectorAll(s),
|
||||||
|
addEventListener() {},
|
||||||
|
removeEventListener() {},
|
||||||
|
};
|
||||||
|
const sb = {
|
||||||
|
window: mockWin,
|
||||||
|
document: mockDoc,
|
||||||
|
navigator: { language: 'zh-CN', platform: platformKey === 'darwin' ? 'MacIntel' : 'Win32' },
|
||||||
|
URLSearchParams,
|
||||||
|
AbortController,
|
||||||
|
queueMicrotask,
|
||||||
|
requestAnimationFrame: (fn) => setTimeout(fn, 0),
|
||||||
|
cancelAnimationFrame: clearTimeout,
|
||||||
|
setTimeout,
|
||||||
|
clearTimeout,
|
||||||
|
setInterval,
|
||||||
|
clearInterval,
|
||||||
|
Promise,
|
||||||
|
Math,
|
||||||
|
Date,
|
||||||
|
JSON,
|
||||||
|
Number,
|
||||||
|
String,
|
||||||
|
Boolean,
|
||||||
|
Array,
|
||||||
|
Object,
|
||||||
|
Map,
|
||||||
|
Set,
|
||||||
|
RegExp,
|
||||||
|
Error,
|
||||||
|
TypeError,
|
||||||
|
parseFloat,
|
||||||
|
parseInt,
|
||||||
|
isNaN,
|
||||||
|
Infinity,
|
||||||
|
};
|
||||||
|
sb.globalThis = sb;
|
||||||
|
vm.runInNewContext(appJs, sb);
|
||||||
|
const cap = body._foundCap || (function findCap(n) {
|
||||||
|
if (n.id === 'ag-usage-monitor-capsule') return n;
|
||||||
|
for (const c of n.children || []) { const r = findCap(c); if (r) return r; }
|
||||||
|
return null;
|
||||||
|
})(body);
|
||||||
|
return { ov: mockWin.__AGUsageMonitorOverlay, cap };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Fixed fallback without native anchor: macOS uses 12px right inset vs Windows 144px window-controls reserve
|
||||||
|
const macFixed = runOverlayForPlatform('darwin');
|
||||||
|
const winFixed = runOverlayForPlatform('win32');
|
||||||
|
try {
|
||||||
|
assert.equal(macFixed.cap.getAttribute('data-os'), 'mac');
|
||||||
|
assert.equal(macFixed.cap.style.right, '12px');
|
||||||
|
assert.equal(winFixed.cap.getAttribute('data-os'), 'default');
|
||||||
|
assert.equal(winFixed.cap.style.right, '144px');
|
||||||
|
} finally {
|
||||||
|
macFixed.ov.dispose();
|
||||||
|
winFixed.ov.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Fixed fallback with native top-right button at x=1230 on 1280px viewport: macOS hugs button at 56px instead of jumping to 144px
|
||||||
|
const macAnchored = runOverlayForPlatform('darwin', { auxLeft: 1230, winWidth: 1280 });
|
||||||
|
try {
|
||||||
|
assert.equal(macAnchored.cap.style.right, '56px');
|
||||||
|
} finally {
|
||||||
|
macAnchored.ov.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Flow titlebar narrow window (610px): macOS 80px traffic-light reserve retains 'wide' capsule while Windows 168px reserve collapses
|
||||||
|
const macNarrowFlow = runOverlayForPlatform('darwin', { withTitlebar: true, winWidth: 610 });
|
||||||
|
const winNarrowFlow = runOverlayForPlatform('win32', { withTitlebar: true, winWidth: 610 });
|
||||||
|
try {
|
||||||
|
assert.equal(macNarrowFlow.cap.getAttribute('data-layout'), 'wide');
|
||||||
|
assert.notEqual(winNarrowFlow.cap.getAttribute('data-layout'), 'wide');
|
||||||
|
} finally {
|
||||||
|
macNarrowFlow.ov.dispose();
|
||||||
|
winNarrowFlow.ov.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user