diff --git a/apps/tauri/src/theme/queryaTheme.ts b/apps/tauri/src/theme/queryaTheme.ts index 11163793..df0020a5 100644 --- a/apps/tauri/src/theme/queryaTheme.ts +++ b/apps/tauri/src/theme/queryaTheme.ts @@ -5,7 +5,8 @@ const STORAGE_KEY = "querya.theme"; export function readStoredTheme(): QueryaThemeMode { const raw = localStorage.getItem(STORAGE_KEY); if (raw === "light" || raw === "dark" || raw === "system") return raw; - return "system"; + // Flutter QueryaTheme.darkDefault — first launch is dark, not OS light. + return "dark"; } export function applyTheme(mode: QueryaThemeMode): void { diff --git a/apps/tauri/src/ui/ResultGrid.vue b/apps/tauri/src/ui/ResultGrid.vue index f1eebfdd..f30d82e9 100644 --- a/apps/tauri/src/ui/ResultGrid.vue +++ b/apps/tauri/src/ui/ResultGrid.vue @@ -3,8 +3,13 @@ import { onBeforeUnmount, onMounted, ref, watch } from "vue"; import { createElement } from "react"; import { createRoot, type Root } from "react-dom/client"; import { storeToRefs } from "pinia"; +import type { Theme } from "@glideapps/glide-data-grid"; import { useQueryResultStore } from "../stores/queryResult"; import { ResultDataEditor } from "./glide/ResultDataEditor"; +import { + buildQueryaGlideTheme, + subscribeThemeChanges, +} from "./glide/queryaGlideTheme"; import "@glideapps/glide-data-grid/dist/index.css"; const query = useQueryResultStore(); @@ -14,6 +19,8 @@ const host = ref(null); const size = ref({ width: 640, height: 320 }); let root: Root | null = null; let ro: ResizeObserver | null = null; +let unsubTheme: (() => void) | null = null; +let glideTheme: Partial = buildQueryaGlideTheme(); function render() { if (!root || !host.value) return; @@ -23,10 +30,16 @@ function render() { rows: rows.value, width: Math.max(100, size.value.width), height: Math.max(100, size.value.height), + theme: glideTheme, }), ); } +function refreshTheme() { + glideTheme = buildQueryaGlideTheme(); + render(); +} + onMounted(() => { if (!host.value) return; root = createRoot(host.value); @@ -40,12 +53,15 @@ onMounted(() => { render(); }); ro.observe(host.value); - render(); + unsubTheme = subscribeThemeChanges(refreshTheme); + refreshTheme(); }); watch([columns, rows], () => render(), { deep: true }); onBeforeUnmount(() => { + unsubTheme?.(); + unsubTheme = null; ro?.disconnect(); ro = null; root?.unmount(); @@ -68,6 +84,7 @@ onBeforeUnmount(() => { height: 100%; min-height: 120px; overflow: hidden; - background: var(--q-surface); + background: var(--q-editor-bg); + color: var(--q-foreground); } diff --git a/apps/tauri/src/ui/glide/ResultDataEditor.ts b/apps/tauri/src/ui/glide/ResultDataEditor.ts index 0edf2b36..bbc57505 100644 --- a/apps/tauri/src/ui/glide/ResultDataEditor.ts +++ b/apps/tauri/src/ui/glide/ResultDataEditor.ts @@ -10,6 +10,7 @@ import { type GridCell, type GridColumn, type Item, + type Theme, } from "@glideapps/glide-data-grid"; export type ResultDataEditorProps = { @@ -17,6 +18,8 @@ export type ResultDataEditorProps = { rows: unknown[][]; width: number; height: number; + /** Querya workbench → Glide theme (dark/light). */ + theme: Partial; }; function cellText(value: unknown): string { @@ -27,7 +30,7 @@ function cellText(value: unknown): string { } export function ResultDataEditor(props: ResultDataEditorProps): ReactElement { - const { columns, rows, width, height } = props; + const { columns, rows, width, height, theme } = props; const gridColumns: GridColumn[] = useMemo( () => @@ -39,6 +42,8 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement { [columns], ); + const muted = theme.textMedium ?? theme.textLight ?? "#94a3b8"; + const getCellContent = useCallback( ([col, row]: Item): GridCell => { const raw = rows[row]?.[col]; @@ -49,12 +54,10 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement { displayData: isNull ? "NULL" : cellText(raw), allowOverlay: true, readonly: true, - themeOverride: isNull - ? { textDark: "var(--q-muted-foreground)" } - : undefined, + themeOverride: isNull ? { textDark: muted } : undefined, }; }, - [rows], + [rows, muted], ); return createElement(DataEditor, { @@ -63,6 +66,7 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement { getCellContent, width, height, + theme, rowMarkers: "number", smoothScrollX: true, smoothScrollY: true, diff --git a/apps/tauri/src/ui/glide/queryaGlideTheme.ts b/apps/tauri/src/ui/glide/queryaGlideTheme.ts new file mode 100644 index 00000000..474e093c --- /dev/null +++ b/apps/tauri/src/ui/glide/queryaGlideTheme.ts @@ -0,0 +1,95 @@ +import type { Theme } from "@glideapps/glide-data-grid"; + +/** Read a Querya CSS token as a concrete color (Glide paints on canvas). */ +function cssVar(name: string, fallback: string): string { + if (typeof document === "undefined") return fallback; + const v = getComputedStyle(document.documentElement) + .getPropertyValue(name) + .trim(); + return v || fallback; +} + +function withAlpha(hexOrCss: string, alpha: number): string { + const m = /^#([0-9a-f]{6})$/i.exec(hexOrCss.trim()); + if (!m) return hexOrCss; + const n = parseInt(m[1]!, 16); + const r = (n >> 16) & 255; + const g = (n >> 8) & 255; + const b = n & 255; + return `rgba(${r}, ${g}, ${b}, ${alpha})`; +} + +/** + * Glide theme from Querya workbench tokens — Flutter darkDefault parity + * (near-black canvas, cyan accent) and lightDefault when `data-theme=light`. + */ +export function buildQueryaGlideTheme(): Partial { + const fg = cssVar("--q-foreground", "#f8fafc"); + const muted = cssVar("--q-muted-foreground", "#94a3b8"); + const surface = cssVar("--q-editor-bg", cssVar("--q-surface", "#0c0c0c")); + const canvas = cssVar("--q-canvas", "#000000"); + const border = cssVar("--q-border", "#27272a"); + const primary = cssVar("--q-primary", "#22d3ee"); + const primaryFg = cssVar("--q-primary-foreground", "#0a0a0a"); + const accent = cssVar("--q-accent", "#27272a"); + const mono = cssVar( + "--q-font-mono", + '"JetBrains Mono", "SF Mono", ui-monospace, monospace', + ); + const sans = cssVar( + "--q-font-sans", + '"Segoe UI", "SF Pro Text", system-ui, sans-serif', + ); + + return { + accentColor: primary, + accentFg: primaryFg, + accentLight: withAlpha(primary, 0.16), + textDark: fg, + textMedium: muted, + textLight: muted, + textBubble: fg, + bgIconHeader: muted, + fgIconHeader: fg, + textHeader: muted, + textGroupHeader: muted, + textHeaderSelected: primaryFg, + bgCell: surface, + bgCellMedium: canvas, + bgHeader: canvas, + bgHeaderHasFocus: accent, + bgHeaderHovered: accent, + bgBubble: accent, + bgBubbleSelected: surface, + bgSearchResult: withAlpha(primary, 0.18), + borderColor: withAlpha(border, 0.55), + horizontalBorderColor: withAlpha(border, 0.35), + headerBottomBorderColor: withAlpha(border, 0.55), + drilldownBorder: "transparent", + linkColor: primary, + fontFamily: `${sans}, ${mono}`, + headerFontStyle: "600 12px", + baseFontStyle: "12px", + markerFontStyle: "10px", + editorFontSize: "12px", + cellHorizontalPadding: 8, + cellVerticalPadding: 4, + lineHeight: 1.35, + }; +} + +/** Fire when `data-theme` or OS color-scheme changes (token values update). */ +export function subscribeThemeChanges(onChange: () => void): () => void { + const root = document.documentElement; + const mo = new MutationObserver((mutations) => { + if (mutations.some((m) => m.attributeName === "data-theme")) onChange(); + }); + mo.observe(root, { attributes: true, attributeFilter: ["data-theme"] }); + const mq = window.matchMedia("(prefers-color-scheme: dark)"); + const onMq = () => onChange(); + mq.addEventListener("change", onMq); + return () => { + mo.disconnect(); + mq.removeEventListener("change", onMq); + }; +}