fix(desktop): restore legacy webview tints and active tab background

This commit is contained in:
知食分子 authored and GitHub committed 2026-09-26 07:20:45 +08:00
1 parent b504b3e8a9
commit 4ad9c5f38f
11 files changed
+364 -16

No files matched your search

+37 -4
View File
@@ -685,10 +685,43 @@ describe("shared tab presentation helpers", () => {
});
it("builds active/inactive color styles for classic and non-classic layouts", () => {
const activeClassic = tabColorStyle(queryTab({}), true, true);
expect(activeClassic?.boxShadow).toContain("var(--foreground)");
const inactiveModern = tabColorStyle(queryTab({}), false, false);
expect(inactiveModern?.borderColor).toBeUndefined();
// Node has no window/CSS globals: pin both to modern-engine answers.
vi.stubGlobal("CSS", { supports: () => true });
vi.stubGlobal("window", {
matchMedia: (query: string) => ({
media: query,
matches: true,
addEventListener: () => {},
removeEventListener: () => {},
}),
});
try {
const activeClassic = tabColorStyle(queryTab({}), true, true);
expect(activeClassic?.boxShadow).toContain("var(--foreground)");
const inactiveModern = tabColorStyle(queryTab({}), false, false);
expect(inactiveModern?.borderColor).toBeUndefined();
} finally {
vi.unstubAllGlobals();
}
});
it("swaps inline color-mix tab colors for concrete rgba on legacy WebViews", () => {
// WebKit without color-mix() invalidates the inline values at computed-value
// time, which left the active tab with no background at all (macOS 12); and
// it cannot substitute var() inside inline custom properties, so the legacy
// branch resolves the token to concrete rgb. Node has no document: the
// helper falls back to the default theme's foreground (10, 10, 10).
vi.stubGlobal("CSS", { supports: () => false });
try {
const pill = tabColorStyle(queryTab({}), true, false);
expect(pill?.["--app-tab-background"]).toBe("rgba(10, 10, 10, 0.18)");
expect(pill?.borderColor).toBe("var(--ring)");
const classic = tabColorStyle(queryTab({}), true, true);
expect(classic?.["--app-tab-background"]).toBe("rgba(10, 10, 10, 0.18)");
expect(classic?.boxShadow).toBe("inset 0 -2px 0 rgba(10, 10, 10, 0.72)");
} finally {
vi.unstubAllGlobals();
}
});
it("resolves MQ driver icons from the connection store", () => {
+28 -3
View File
@@ -1,6 +1,7 @@
import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { hexToRgba } from "@/lib/common/color";
import { isLegacyWebView } from "@/lib/ui/legacyWebView";
import type { CSSProperties } from "vue";
import { findConnectionGroupPath } from "@/lib/sidebar/sidebarLayout";
import { supportsConnectionDatabaseInfo } from "@/lib/connection/connectionDatabaseInfo";
@@ -682,14 +683,38 @@ export function tabIconClass(tab: QueryTab): string {
return "text-blue-600 dark:text-blue-400";
}
// WebKit without color-mix() (macOS 12 Safari < 16.2) invalidates these inline
// values at computed-value time, leaving the active tab with no background at
// all — and it also fails to substitute var() references inside inline custom
// properties, so the legacy branch resolves the theme token to concrete rgb
// once per call instead of leaning on rgba(var(--dbx-foreground-rgb), …).
function foregroundRgb(): string {
if (typeof document !== "undefined") {
const rgb = getComputedStyle(document.documentElement).getPropertyValue("--dbx-foreground-rgb").trim();
if (rgb) return rgb;
}
return "10, 10, 10";
}
export function appTabActiveBackground(): string {
if (isLegacyWebView()) return `rgba(${foregroundRgb()}, 0.18)`;
return "color-mix(in srgb, var(--foreground) 18%, var(--background))";
}
export function appTabActiveIndicator(): string {
if (isLegacyWebView()) return `inset 0 -2px 0 rgba(${foregroundRgb()}, 0.72)`;
return "inset 0 -2px 0 color-mix(in srgb, var(--foreground) 72%, transparent)";
}
export function tabColorStyle(tab: QueryTab, active: boolean, isClassic: boolean): CSSProperties | undefined {
const activeIndicator = "inset 0 -2px 0 color-mix(in srgb, var(--foreground) 72%, transparent)";
const activeIndicator = appTabActiveIndicator();
const color = connectionColor(tab.connectionId);
if (!color) {
const background = appTabActiveBackground();
if (isClassic) {
return active ? { "--app-tab-background": "color-mix(in srgb, var(--foreground) 18%, var(--background))", boxShadow: activeIndicator } : undefined;
return active ? { "--app-tab-background": background, boxShadow: activeIndicator } : undefined;
}
return active ? { "--app-tab-background": "color-mix(in srgb, var(--foreground) 18%, var(--background))", borderColor: "var(--ring)" } : undefined;
return active ? { "--app-tab-background": background, borderColor: "var(--ring)" } : undefined;
}
if (isClassic) {
return {