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 / tauri-bootstrap

Tauri Bootstrap

Path coverage: Cargo.toml, Cargo.lock, rustfmt.toml, src-tauri/Cargo.toml, src-tauri/build.rs, src-tauri/tauri.conf.json, src-tauri/Info.plist, src-tauri/capabilities/**, src-tauri/icons/**, src-tauri/…/main.rs, src-tauri/…/mod.rs, src-tauri/…/setup.rs, src-tauri/…/constant.rs.

Overview

This repository is a single-crate Rust workspace for the desktop shell: the root Cargo.toml declares only src-tauri as a workspace member and tunes release builds for small, non-incremental, LTO-enabled binaries. src-tauri/Cargo.toml names the package chatgpt, pins Rust 1.77.1, uses Tauri 2.0.0-beta with unstable and devtools, and wires the runtime plugins used at bootstrap: shell, dialog, OS, plus app code dependencies such as serde, once_cell, dark-light, regex, and semver. Cargo.lock records the resolved dependency graph for that package, including the Tauri plugins initialized by the app.

The native entry point is src-tauri/…/main.rs. It builds a default tauri::Builder, initializes tauri_plugin_os, tauri_plugin_shell, and tauri_plugin_dialog, registers command handlers from core::cmd and core::window, then hands app setup to core::setup::init before running tauri::generate_context!(). src-tauri/…/mod.rs is the module wiring point: it exposes cmd, conf, constant, setup, template, and window to the bootstrap layer.

src-tauri/…/setup.rs creates the application UI during setup. It loads persisted configuration through AppConf::load, derives whether the ask panel should reserve ASK_HEIGHT, and calls template::Template::new(AppConf::get_scripts_path(...)) so the bundled ask.js template is created or updated in the per-user scripts directory before the main webview injects it. Window construction is async: setup spawns a task that builds one native window labeled core, titled ChatGPT, sized 800x600 with minimum 300x200, and themed from AppConf::get_theme. On macOS it applies an overlay title bar and hides the native title text.

The core window contains three child webviews created in src-tauri/…/setup.rs: main, titlebar, and ask. main loads WebviewUrl::App("https://chatgpt.com"), injects the user-configurable ask.js script and the static INIT_SCRIPT, and handles downloads by rewriting the destination into the platform download directory, then opening successful downloads via tauri_plugin_shell. titlebar and ask both load the local frontend index.html. Initial child-webview placement differs by platform: macOS places titlebar at the top, ask at the bottom, and main between them; non-macOS places main from the top and stacks titlebar plus ask at the bottom. A resize listener recalculates child webview positions and sizes using the current config, the window scale factor, and constants from src-tauri/…/constant.rs.

src-tauri/…/constant.rs centralizes bootstrap constants: TITLEBAR_HEIGHT is 28.0, ASK_HEIGHT is 120.0, WINDOW_SETTINGS is the settings window label, and INIT_SCRIPT is injected into the ChatGPT webview. The script listens for history and popstate URL changes, rewrites certain clicked links to _blank, and emits navigation:change with the current URL to the webview window labeled titlebar via window.__TAURI__.webviewWindow.WebviewWindow.getByLabel('titlebar').

Tauri configuration lives in src-tauri/tauri.conf.json. The product is ChatGPT, the bundle identifier is com.nofwl.chatgpt, and the app version is read from ../package.json rather than from the Rust crate version. Dev mode runs pnpm dev at http://localhost:1420; production builds run pnpm build and serve ../dist. The app enables withGlobalTauri, declares no top-level windows because setup constructs them manually, disables CSP by setting it to null, bundles all targets, and references the main icon assets under src-tauri/…/32x32.png, 128x128.png, 128x128@2x.png, icon.icns, and icon.ico. Additional Windows/Store icon sizes also live under src-tauri/icons/**.

Platform and permission configuration is split across src-tauri/build.rs, src-tauri/Info.plist, and src-tauri/…/desktop.json. The build script exports MACOSX_DEPLOYMENT_TARGET=10.13 before delegating to tauri_build::build(). Info.plist adds an App Transport Security exception for chatgpt.com including subdomains and insecure HTTP loads. The desktop capability applies to all windows on Linux, macOS, and Windows, grants access to remote https://chatgpt.com/*, and allows window, webview, event, shell, and OS permissions including shell open/execute and webview creation/devtools-related permissions. Formatting policy for the Rust side is captured by rustfmt.toml with Rust 2021 style, 100-column width, spaces, reordered imports/modules, and explicit ABIs.

Coupling

  • If any child webview label in src-tauri/…/setup.rs changes, update src-tauri/…/constant.rs at the same time: INIT_SCRIPT hard-codes titlebar as the event recipient, and a label drift would stop navigation updates from reaching the local titlebar webview.
  • If app identity changes in src-tauri/tauri.conf.json, also check src-tauri/…/conf.rs because setup reaches user state through AppConf, whose config and scripts paths are rooted under the hard-coded com.nofwl.chatgpt directory rather than reading the identifier from Tauri config.
  • If the remote origin changes in src-tauri/…/setup.rs or src-tauri/tauri.conf.json, update both src-tauri/…/desktop.json and src-tauri/Info.plist: capabilities only grant remote access to https://chatgpt.com/*, while the macOS ATS exception is scoped to chatgpt.com and subdomains.
  • If TITLEBAR_HEIGHT or ASK_HEIGHT changes in src-tauri/…/constant.rs, verify both initial placement and resize placement in src-tauri/…/setup.rs; the layout math is duplicated in platform-specific blocks and uses physical sizes derived from the window scale factor.
  • If a new Tauri plugin is initialized in src-tauri/…/main.rs, add the matching dependency in src-tauri/Cargo.toml and review src-tauri/…/desktop.json for its frontend permissions; plugin initialization alone does not grant webview access to its commands.
  • If bundle icons are renamed or regenerated under src-tauri/icons/**, keep src-tauri/tauri.conf.json in sync because the bundle config references a fixed subset of icon paths.

Risks

  • src-tauri/…/desktop.json grants shell open and execute permissions to all windows and remote https://chatgpt.com/* while src-tauri/tauri.conf.json enables withGlobalTauri and disables CSP. If untrusted remote content can access the Tauri API surface, broad shell permissions can turn a web content issue into local command or file-opening behavior.
  • src-tauri/…/setup.rs uses expect/unwrap throughout setup, download handling, child-webview insertion, config reload, and resize processing. If platform paths, webview creation, or config parsing fail at runtime, the app can panic instead of degrading gracefully.
  • src-tauri/…/setup.rs has separate initial and resize layout formulas for non-macOS child webviews. Initial placement subtracts both ask_mode_height and TITLEBAR_HEIGHT for the titlebar position, while the resize handler positions the titlebar using only TITLEBAR_HEIGHT; if ask mode is enabled, a resize can place titlebar and ask views differently than the initial layout.