Introducing a new way to review your PRs.

Read the announcement

lencx / chatgpt

❄️ ChatGPT Desktop Application (Mac, Windows and Linux)

View on GitHub

10 documents · Updated Nov 16, 2026

docs / ask-view-flow

Ask View Flow

Overview

The Ask flow is a small Tauri side-panel flow that lets the app's own ask webview type into, and submit from, the embedded ChatGPT page running in the main webview. src/App.tsx selects src/…/Ask.tsx only when the current webview label is ask, so the React component is rendered in the dedicated child webview created by src-tauri/…/setup.rs.

src/…/Ask.tsx owns the visible chat input. It keeps the current textarea value in React state and, after a 300 ms lodash debounce, calls the Tauri command ask_sync with message: JSON.stringify(message). The Rust command in src-tauri/…/cmd.rs evaluates ChatAsk.sync(<json string>) inside the main webview, so the frontend string is intentionally serialized before crossing into an evaluated JavaScript call. Sending can be triggered by clicking the SendIcon or by ⌘+Enter on macOS / Ctrl+Enter elsewhere; handleSend calls ask_send, clears the Ask textarea, and refocuses it.

The browser-side half of the flow is src-tauri/…/ask.js. src-tauri/…/template.rs embeds this file as SCRIPT_ASK, and src-tauri/…/setup.rs injects the configured ask.js into the main webview with .initialization_script(&AppConf::load_script(&handle, "ask.js")). The injected script exposes window.ChatAsk: ChatAsk.sync(message) finds the first textarea, uses the native HTMLTextAreaElement.value setter, and dispatches an input event so the ChatGPT page's own handlers observe the change; ChatAsk.submit() finds all main form button elements, focuses and enables the last one, and clicks it.

The Ask view can be shown or hidden from the titlebar flow. src/…/Titlebar.tsx invokes set_view_ask, and src-tauri/…/cmd.rs persists ask_mode, moves focus between the ask and main webviews, and resizes main, titlebar, and ask using ASK_HEIGHT. src-tauri/…/setup.rs uses the same ask_mode sizing on startup and on window resize. On ask_send, Rust submits in the main webview and then schedules focus back to the ask webview after 500 ms.

docs/…/chatgpt-v2.gif is the static documentation/demo asset covered by this area; it is not part of the runtime command path described above.

Coupling

  • If src/…/Ask.tsx changes how message is passed to Tauri, also update src-tauri/…/cmd.rs: ask_sync interpolates the string directly into ChatAsk.sync(...), so it currently depends on the frontend sending a JavaScript string literal via JSON.stringify(message) rather than a raw textarea value.
  • If src-tauri/…/ask.js changes the global name or method signatures, also update src-tauri/…/cmd.rs; ask_sync and ask_send call ChatAsk.sync and ChatAsk.submit by string-evaluated JavaScript in the main webview.
  • If the Ask view height or visibility behavior changes, update both set_view_ask in src-tauri/…/cmd.rs and the startup/resize layout in src-tauri/…/setup.rs; both independently position and size the ask, main, and titlebar webviews from ask_mode, ASK_HEIGHT, and platform-specific titlebar placement.
  • If the injected script is renamed or moved, update src-tauri/…/template.rs and src-tauri/…/setup.rs; the template code writes ask.js, and setup loads that exact script name into the main webview.

Risks

  • src/…/Ask.tsx passes a message argument to ask_send, but src-tauri/…/cmd.rs ignores it and submits whatever was last synced into the main webview. Because ask_sync is debounced by 300 ms in src/…/Ask.tsx, pressing send immediately after typing can submit stale content if the latest debounce has not executed yet.
  • src-tauri/…/ask.js relies on ChatGPT page selectors (textarea and the last main form button). If the external ChatGPT DOM changes, ask_sync may stop populating the prompt or ask_send may click the wrong button without a compile-time failure.
  • src-tauri/…/cmd.rs uses eval(&format!("ChatAsk.sync({})", message)); if any caller stops JSON-stringifying the message before invoking ask_sync, quotes, newlines, or user-controlled JavaScript syntax can break evaluation in the main webview.