Files
DeepTutor/apps/desktop/README.md
LIziak112 9ea0e96040 fix(desktop): preserve Windows content zoom across restarts (#2970)
* fix(desktop): preserve Windows content zoom across restarts

* fix(desktop): apply rendered Windows content zoom

Use isolated webContents zoom so saved factors scale the rendered page without affecting the shell. Add native Windows Electron coverage for viewport and DPR changes, reloads, and cold-start restoration.
2026-12-01 14:37:47 +08:00

191 lines
11 KiB
Markdown

# Open DeepTutor for MacOS and Windows
A double-clickable desktop app for DeepTutor. On first launch it installs its
bundled runtime, starts the Python and Node services on loopback, and opens
the complete DeepTutor web UI in its window. Users need no terminal, Python,
Node, npm, Git or source checkout.
This is a preview. Models and providers are configured in DeepTutor's normal
Settings; no credentials or user data ship with the app. Optional external
tools (Manim/LaTeX, partner CLIs, remote services) keep their usual
requirements.
## Editions
| Target | Name | Short | Downloads |
| ------------- | --------------------------------------------- | ----------------------- | ---------------------------------------------------------- |
| `macos-arm64` | Open DeepTutor for MacOS with Apple Silicon | MacOS (Apple Silicon) | `Open-DeepTutor-MacOS-Apple-Silicon-v<version>.dmg` |
| `macos-x64` | Open DeepTutor for MacOS with Intel Silicon | MacOS (Intel) | `Open-DeepTutor-MacOS-Intel-v<version>.dmg` |
| `windows-x64` | Open DeepTutor for Windows | Windows | `Open-DeepTutor-Windows-v<version>-Setup.exe`, `…-Portable.zip` |
- The app version is the DeepTutor version it bundles, read from
`deeptutor/__version__.py` via the sealed runtime, so `package.json` stays at
`0.0.0`. The start screen and About show the full name with the version;
the web UI's sidebar uses the short name, and Settings → About shows both.
The web UI recognises the app by the `OpenDeepTutor/<version> (macOS; arm64)`
user-agent marker (`(macOS; x64)`, `(Windows; x64)`); names live in
`src/platform.mjs` and `web/lib/version.ts`.
- The shell (start screen, menus, dialogs) follows the interface language and
theme in `data/user/settings/interface.json`, including live changes. On
Windows, Preferences also changes these settings: it updates the Web page's
localStorage and sends `/api/settings/ui`, falling back to the settings file
while the backend is unavailable. The Web interface supports 13 languages;
shell copy in `src/i18n.mjs` currently covers English, Chinese, German, French,
Polish, Ukrainian, Vietnamese, Portuguese and Turkish. Japanese, Korean,
Italian and Hungarian remain valid Web preferences but shell copy falls back
to English. Selecting one does not change the saved language to English.
## Layout
```
src/ the shell, shared by every platform
platform.mjs every run-time difference between MacOS and Windows
scripts/ build-runtime, seal-runtime, smoke, package (all take --target)
lib/ target loading, app staging, MacOS packaging
platforms/
macos-arm64/ target.mjs (Python/Node builds) + package.mjs (DMG)
macos-x64/ target.mjs + package.mjs (DMG)
windows-x64/ target.mjs + package.mjs (zip) + installer.nsi (Setup.exe)
```
Every build file of a target goes to `.local/<target>/`; downloads go to `out/`.
## Components
- **Shell**: Electron window, native menus, downloads, runtime supervision.
- **Core bundle**: Python source and modules, the production Next.js standalone
build, Python 3.12.13 and Node 22.23.4 for the target, built from a
committed revision.
- **Protocol 1**: the shell only manages startup, readiness, shutdown and core
artifacts. No business API or React components are copied into the shell.
| | MacOS | Windows |
| -------- | ------------------------------------------------------ | ----------------------------------------- |
| Data | `~/Library/Application Support/Open DeepTutor/workspace/data` | `%LOCALAPPDATA%\Open DeepTutor\workspace\data` |
| Runtimes | `…/Open DeepTutor/runtimes/<runtime-id>` | same, under `%LOCALAPPDATA%` |
| Logs | `…/Open DeepTutor/logs/runtime.log` | same, under `%LOCALAPPDATA%` |
| Window | the shell's own title bar under the traffic lights | overlay title bar with shell buttons and native popup menus |
| Shutdown | SIGTERM to each service's process group, then SIGKILL | `taskkill /T /F` on each service's tree |
On Windows, **Open DeepTutor**, **Preferences**, **View**, and **Core** are
in the title bar. Preferences changes language, theme and Modern/Classic layout;
**View** also offers always-on-top and force reload. Use the window caption to
minimize and the focused editor's shortcuts for cut, copy, paste, undo, redo and
select all. macOS keeps its existing menu structure.
Quitting stops the services this app started. It does not stop a separately
running `deeptutor start`. Web content has no preload, Node integration or
desktop IPC privileges; only the private shell page owns the native bridge.
In Windows conversations, click a file to preview it. The right-click menu
also lets you save the conversation copy or copy readable text. If the
workspace original is available, you can choose an associated Windows app,
select the original in File Explorer, or copy its path. When a file is
unavailable, use **Back to conversation** to close its preview.
## Build
Prerequisites (developers only): Node/npm and `uv`. MacOS targets build on a
Mac (`macos-x64` also on Apple Silicon, through Rosetta); `windows-x64` builds
on Windows 10+ with NSIS (`makensis`) installed.
```sh
cd apps/desktop
npm ci
npm run check && npm test
npm run build:runtime -- --target macos-arm64 # snapshots this checkout's committed HEAD
npm run smoke -- --target macos-arm64 # boots the bundled core with no developer tools on PATH
npm run package -- --target macos-arm64 # out/Open-DeepTutor-MacOS-Apple-Silicon-v<version>.dmg
```
`--target` defaults to the computer you build on. Every build step (npm, Next)
runs on the target's own Node, so native packages match the target
architecture. `build:runtime` uses `git archive HEAD`, so commit first;
uncommitted changes are not bundled. Set `DEEPTUTOR_SOURCE` to build another
checkout. `npm start` runs the shell against this computer's bundled core.
`npm run icon` regenerates `assets/icon.icns` and `assets/icon.ico` from
`assets/mark.png` (MacOS only).
## Signing
- **Core bundles** are signed with one Ed25519 key for every platform; the
manifest binds platform and architecture, so a bundle only installs on the
edition it was built for. The private key is `.local/signing-private.pem`
(ignored) or the `OPEN_DEEPTUTOR_SIGNING_KEY` environment variable; only
`assets/runtime-public.pem` ships. Sealing refuses a key that does not match
the public key. Keep a secure backup: losing it means shipped apps can no
longer accept core updates. `--new-key` deliberately starts a new identity.
- **The MacOS apps** are signed ad hoc by default. Set `APPLE_SIGNING_IDENTITY`
to a Developer ID Application identity during both runtime building and app
packaging. Native code in the bundled Python, Node and Web dependencies is
signed with secure timestamps before the core archive is sealed; interpreter
entitlements live in `assets/entitlements.runtime.mac.plist`. The outer app
uses `assets/entitlements.mac.plist`. Then notarize the DMG with
`node scripts/notarize.mjs`; only an Accepted result is stapled and validated.
- **The Windows app** is unsigned; SmartScreen asks for confirmation on first
open until an Authenticode certificate is added.
## Releases
Starting with the release after v1.7.1, every release must include both macOS
architectures: Apple Silicon (`macos-arm64`) and Intel (`macos-x64`), alongside
the Windows installer and portable ZIP. The `verify-release` job requires all
three builds to succeed and checks that all four versioned downloads and their
unversioned aliases are uploaded and nonempty. A missing Intel DMG means the
desktop release is incomplete; fix and rerun the failed build before reporting
the release as complete.
`.github/workflows/desktop-release.yml` runs when a DeepTutor GitHub Release is
published. For each target it verifies the tag matches
`deeptutor/__version__.py`, builds and smoke-tests the runtime, packages the
app and attaches the downloads to the release. Signed builds read the runtime
key and Apple signing and notarization credentials from the protected
`desktop-release` environment after deployment approval.
Pull requests, pushes to `dev` and manual branch validations use disposable
runtime keys. To validate signing, dispatch the workflow on a version tag.
To attach downloads to an existing release, select that same tag as the
workflow ref and the tag input, and enable `publish`. The notarization
diagnostics workflow also runs manually on version tags. Windows Authenticode
signing is not configured by this workflow.
## Core updates
The shell never `git pull`s or mutates a running Python environment. **Core →
Install Core Update…** accepts a signed `runtime.json` beside its `.tar.gz`.
The app verifies the signature, SHA-256, platform, architecture and protocol,
installs into a new version directory, backs up the desktop workspace, then
starts the candidate. A failed or interrupted trial restores the previous
runtime and workspace. Backups are kept. Automatic update discovery is not
connected yet.
Installing a newer app over an older one works the same way: on the next start,
a bundled core whose `coreVersion` is newer than the active one is installed and
trialled with the same backup and rollback. A bundled core that fails its trial
is not tried again, and an older bundled core never replaces a newer one that
was installed by hand.
## Verification
`npm test` covers edition names, language resolution, config validation,
signature and platform rejection, process shutdown, cancellation and local
service behaviour; CI runs it on Linux and Windows. `npm run smoke` boots the
real bundled core in a fresh temporary workspace, checks backend, frontend and
API proxy, then verifies both ports close. It does not call a paid model or
test optional external renderers. Windows CI also runs
`platforms/windows-x64/smoke-installer.ps1`: it silently installs the app,
opens the actual Electron window with a fresh data path containing spaces and
Chinese characters, checks UI/API readiness and service shutdown on window
close, then verifies uninstall preserves learning data and unrelated files.
`OPEN_DEEPTUTOR_TEST_HOME` selects a disposable desktop home for UI checks.
On Windows, `npm test` also launches real Electron windows for the content-zoom
regression check (no bundled core or Python services required). It measures the
rendered viewport and device pixel ratio after zoom commands, Ctrl+Shift+Plus,
and reload, then starts a second Electron process with a fresh Chromium profile
to verify the saved factor on a new loopback origin. The private shell, native
window bounds and a same-origin companion view must stay unscaled. This native
check is skipped on other platforms; the controller unit tests still run there.
To run only the native check, use `node --test test/content-zoom-native.test.mjs`
from `apps/desktop` on an interactive Windows desktop.