Skip to content

Desktop

nodemode-ai edited this page Dec 3, 2026 · 4 revisions

Desktop

The desktop app is a thin Tauri 2 shell around the same window, with the engine frozen by PyInstaller as formchem-engine. On macOS the engine ships as a folder inside the app (FormChem.app/Contents/Resources/engine); on Linux and Windows it is a one-file sidecar. The shell shows a splash, starts the engine with FORMCHEM_PORT=0 and FORMCHEM_PORT_PREFER=8221, reads the real port from the engine, reveals the window when the page is ready, and stops the engine on exit.

Source path What lives there
src-tauri/src/main.rs Engine start, splash and reveal, single instance, the Windows job object that ends the engine with the app, the macOS overlay title bar with the traffic lights inset, clipboard access for the windows
src-tauri/src/packaged.rs Finds the engine folder: ../Resources/engine/formchem-engine in the app bundle, or engine/formchem-engine beside the program under tauri dev; without it the shell starts the sidecar
src-tauri/tauri.conf.json Identity ai.nodemode.formchem, windows, bundle targets, externalBin, the updater endpoint
src-tauri/tauri.macos.conf.json macOS only: no externalBin, and the engine folder src-tauri/engine shipped as the resource engine
src-tauri/capabilities/ Window permissions
src-tauri/flatpak/ The Flatpak manifest and ai.nodemode.formchem.metainfo.xml
setup/freeze_backend PyInstaller build of backend/formchem_engine.py: on macOS a one-folder build copied to src-tauri/engine, flattened and checked; elsewhere a one-file sidecar named formchem-engine-<target triple>
setup/lib.sh fc_engine_folder, fc_flatten_engine and fc_sign_engine, shared by freeze_backend and build_app
build_app, build_app.bat Freeze the engine and build the desktop bundle on this machine

Startup

Before 0.7.0 the engine was one file on every system. A one-file engine unpacks itself (RDKit, Indigo, numpy and Python: several hundred megabytes and hundreds of libraries) into a new temporary folder at every launch, and macOS checks every unpacked library again each time, which is why the owner's Mac took about 30 seconds to open the app. On macOS the engine now ships already unpacked, so nothing is unpacked at launch. Measured on Linux, where the same freeze was timed: the engine reaches its address in 0.46 s from source, 1.5 s frozen as one file and 0.55 s frozen as a folder. The splash stays at least 2.6 s from launch (the family value, running alongside the engine start), so the expected open time on a Mac is about 3 seconds. This has not been measured on a Mac yet.

The one-folder build must be flattened before Tauri can carry it as a resource: every symbolic link is replaced by a copy, and _internal/Python.framework by a plain _internal/Python (the folder grows from about 314 to 426 MB). When APPLE_SIGNING_IDENTITY is set, PyInstaller signs with it and fc_sign_engine signs every Mach-O file left unsigned. ./formchem desktop check fails on macOS if src-tauri/engine has no program, a symbolic link or a .framework, and ./formchem clean removes the folder. On macOS cargo check, cargo build and tauri dev need the folder to exist; ./formchem desktop dev freezes first when it is missing. Linux and Windows keep the one-file sidecar for now (Linux packages put resources in another place than the program, and neither could be bundled and tested for this version).

Contract

  • The engine is called formchem-engine everywhere: the sidecar name in externalBin and in main.rs, and the program inside the macOS engine folder.
  • The macOS engine folder holds no symbolic links and no .framework.
  • The title bar on macOS is the overlay style: the traffic lights sit over the window's own title bar, which carries data-tauri-drag-region.
  • The updater reads https://dl.formai.studio/formchem/updates/latest.json; the public key in the repository stays empty, because formcompiler holds the key pair.
  • Nothing GPL goes into the frozen engine.
  • Signing identities are held by formcompiler; local builds are unsigned.

Run it from source with ./formchem desktop dev; ./formchem desktop build makes a local bundle. Released builds come only from formcompiler (see Releasing).

Building on this machine

./build_app (or build_app.bat on Windows) builds the desktop app from a fresh checkout in one step and writes everything it does to build_app.log. In order it checks and prepares:

Step What it checks or does
System macOS: the Xcode Command Line Tools; Linux: WebKitGTK 4.1 and the build packages
Python 3.12 or newer (it tries python3.14, python3.13, python3.12, then python3); an older venv is recreated
Node.js 20.19 or newer
Rust rustc and cargo from the same install (rustup expected), building for this machine's architecture
Notices THIRD-PARTY-NOTICES.txt must exist (python3 setup/notices.py after ./formchem install)
Engine packages backend/requirements*.txt into backend/venv, reinstalled when the files or Python change
Window packages npm ci in frontend/, rerun when package-lock.json or Node change
Tauri CLI frontend/node_modules/.bin/tauri must exist, and its major.minor must equal the tauri crate's in src-tauri/Cargo.lock; each @tauri-apps/plugin-* package must share major.minor with its tauri-plugin-* crate
Build the window (npm run build), the engine frozen by PyInstaller with the window, the notices and the template library (on macOS as a flattened one-folder in src-tauri/engine, signed when APPLE_SIGNING_IDENTITY is set; elsewhere as one file), a --selfcheck of the frozen engine, then the Tauri bundle (.app and .dmg on macOS, .deb, .rpm or AppImage on Linux)

The Tauri CLI pin. @tauri-apps/cli is a dev dependency in frontend/package.json, pinned at 2.12.6 because the tauri crate in Cargo.lock is 2.12.7: the CLI's major.minor must always equal the crate's, so a crate update to 2.13 needs the CLI at 2.13 in the same change. Before 0.6.0 package.json did not list the CLI at all and the build stopped with "the Tauri CLI did not install"; the message now names package.json. With the pin, the owner's ./build_app on macOS (Apple silicon, Python 3.14) built the app. ./formchem desktop check runs the same version comparison without building.

--reinstall reinstalls both package sets, --clean removes earlier build output (including src-tauri/engine), --bundles picks the bundle kinds and --config merges an extra Tauri config (formcompiler's contract mode).

Desktop-only paths

  • Saving exports. The window shows the system's save dialog (a folder dialog for Each structure) and asks the engine to write the file through POST /api/files/write, because the webview cannot write files itself; the engine writes outside your home folder only where you chose the place in the dialog.
  • Printing goes through the shell's print_window command, because the macOS webview ignores the page's own print call.
  • Clipboard. The windows may read and write the clipboard from the page (WebKitGTK on Linux and WebView2 on Windows need this for Edit > Paste). On macOS, Cut, Copy, Paste and Select All in the system Edit menu are the system's own items, so they reach the drawing as well as text fields.
  • Menus. The macOS menu bar is built from the same menu definitions as the in-window menus, so Scale, Grid, Dark Page, Export, Copy As and Paste Special appear there too. In the window, menus that do not fit beside the title fold into More menus.

None of these paths, nor the startup time, has been run in a macOS build of 0.7.0 yet.

Clone this wiki locally