Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

6.0 KB
Raw Blame
import { createApp } from "vue";
import { createPinia } from "pinia";
import "./styles/globals.css";
import { installDebugLogCapture } from "@/lib/backend/debugLog";
import { retryStartupAfterPreloadFailure } from "@/lib/startup/startupPreloadRecovery";
import { markStartupPhase } from "@/lib/startup/startupTiming";
import { applyLegacyWebViewClass, isBlockingCompatFailure } from "@/lib/ui/legacyWebView";
import { hydrateAppAppearance } from "@/lib/app/appAppearance";
import { isFloatingPluginWindow } from "@/lib/app/windowContext";

function startupErrorMessage(error: unknown): string {
  if (error instanceof Error) {
    return [error.message, error.stack].filter(Boolean).join("\n");
  }
  return String(error);
}

function renderStartupError(error: unknown) {
  if (retryStartupAfterPreloadFailure(error)) return;
  const message = startupErrorMessage(error);
  console.error("[STARTUP] bootstrap failed", error);
  const root = document.querySelector<HTMLDivElement>("#root");
  if (!root) return;
  root.innerHTML = "";
  const panel = document.createElement("div");
  panel.style.cssText = ["display:flex", "min-height:100vh", "align-items:center", "justify-content:center", "background:#ffffff", "color:#111827", "padding:24px", "font-family:ui-sans-serif,system-ui,sans-serif"].join(";");
  const card = document.createElement("div");
  card.style.cssText = ["max-width:760px", "width:100%", "border:1px solid #e5e7eb", "border-radius: var(--dbx-radius-fixed-6)", "padding:20px", "box-shadow:0 10px 30px rgba(0,0,0,0.08)", "background:#fff"].join(";");
  const title = document.createElement("h1");
  title.textContent = "DBX startup failed";
  title.style.cssText = "margin:0 0 12px;font-size:18px;font-weight:700;";
  const text = document.createElement("p");
  text.textContent = "The desktop UI crashed during startup. Please copy the error below and send it to the DBX team.";
  text.style.cssText = "margin:0 0 12px;font-size:13px;line-height:1.5;color:#4b5563;";
  const pre = document.createElement("pre");
  pre.textContent = message;
  pre.style.cssText = ["margin:0", "white-space:pre-wrap", "word-break:break-word", "font-size:12px", "line-height:1.5", "background:#f9fafb", "border-radius: var(--dbx-radius-fixed-4)", "padding:12px", "overflow:auto"].join(";");
  card.append(title, text, pre);
  panel.append(card);
  root.append(panel);
}

function installStartupErrorHandlers() {
  window.addEventListener("error", (event) => {
    console.error("[STARTUP] window error", event.error ?? event.message);
  });
  window.addEventListener("unhandledrejection", (event) => {
    console.error("[STARTUP] unhandled rejection", event.reason);
  });
}

function installGlobalInputAttrs() {
  const ATTRS: [string, string][] = [
    ["autocomplete", "off"],
    ["autocapitalize", "off"],
    ["autocorrect", "off"],
    ["spellcheck", "false"],
  ];
  const MARKER = "data-input-attrs-set";
  const apply = (el: Element) => {
    if ((el.tagName === "INPUT" || el.tagName === "TEXTAREA") && !el.hasAttribute(MARKER)) {
      for (const [k, v] of ATTRS) el.setAttribute(k, v);
      el.setAttribute(MARKER, "");
    }
  };
  document.querySelectorAll("input, textarea").forEach(apply);
  new MutationObserver((mutations) => {
    for (const m of mutations) {
      for (const node of m.addedNodes) {
        if (node instanceof Element) {
          apply(node);
          node.querySelectorAll("input, textarea").forEach(apply);
        }
      }
    }
  }).observe(document.body, { childList: true, subtree: true });
}

async function bootstrap() {
  markStartupPhase("bootstrap");
  console.log("[STARTUP] frontend bootstrap begin");

  // The inline engine probe in index.html has already painted an upgrade notice when this
  // engine cannot style the shell; mounting over it would only replace a readable message
  // with an unstyled UI. The notice's own button reloads once the user opts to continue.
  if (isBlockingCompatFailure()) {
    markStartupPhase("compat-blocked");
    console.warn("[STARTUP] blocked by engine compatibility notice");
    window.dispatchEvent(new Event("dbx:startup-ready"));
    return;
  }
  // Tauri WebViews may not retain localStorage across macOS restarts. Load the
  // durable appearance record before importing i18n and the theme composable;
  // those modules synchronously read the compatibility keys during evaluation.
  await hydrateAppAppearance();
  // A floating plugin window is a widget, not the workbench: it mounts its own
  // root (one plugin workbench on a transparent page) and skips StartupGate/App,
  // so shell singletons — authentication, tab restore, update prompts — stay in
  // the main window instead of booting a second time per widget.
  if (isFloatingPluginWindow()) {
    const [{ default: i18n, loadSavedLocale }, { default: PluginFloatingWindow }] = await Promise.all([import("./i18n"), import("@/components/plugins/PluginFloatingWindow.vue")]);
    const localeReady = loadSavedLocale();
    const floatingApp = createApp(PluginFloatingWindow, { localeReady });
    floatingApp.use(createPinia());
    floatingApp.use(i18n);
    floatingApp.mount("#root");
    // The inline startup guard in index.html swallows Escape until this fires; a
    // widget has no startup wizard, so release it as soon as the root is mounted.
    window.dispatchEvent(new Event("dbx:startup-ready"));
    void localeReady.catch(() => {});
    return;
  }
  const [{ default: i18n, loadSavedLocale }, { default: App }] = await Promise.all([import("./i18n"), import("./StartupGate.vue")]);
  console.log("[STARTUP] frontend modules loaded");
  const localeReady = loadSavedLocale();
  const app = createApp(App, { localeReady });
  app.use(createPinia());
  app.use(i18n);
  app.mount("#root");
  markStartupPhase("gate-mounted");
  void localeReady.then(() => window.dispatchEvent(new Event("dbx:startup-ready"))).catch(() => {});
  console.log("[STARTUP] vue mounted");

  installGlobalInputAttrs();
}

installDebugLogCapture();
installStartupErrorHandlers();
applyLegacyWebViewClass();
void bootstrap().catch(renderStartupError);