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
messageis passed to Tauri, also update src-tauri/…/cmd.rs:ask_syncinterpolates the string directly intoChatAsk.sync(...), so it currently depends on the frontend sending a JavaScript string literal viaJSON.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_syncandask_sendcallChatAsk.syncandChatAsk.submitby string-evaluated JavaScript in themainwebview. - If the Ask view height or visibility behavior changes, update both
set_view_askin src-tauri/…/cmd.rs and the startup/resize layout in src-tauri/…/setup.rs; both independently position and size theask,main, andtitlebarwebviews fromask_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
mainwebview.
Risks
- src/…/Ask.tsx passes a
messageargument toask_send, but src-tauri/…/cmd.rs ignores it and submits whatever was last synced into themainwebview. Becauseask_syncis 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 (
textareaand the lastmain form button). If the external ChatGPT DOM changes,ask_syncmay stop populating the prompt orask_sendmay 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 invokingask_sync, quotes, newlines, or user-controlled JavaScript syntax can break evaluation in themainwebview.