Skip to content

Latest commit

 

History

History
69 lines (47 loc) · 2.92 KB

File metadata and controls

69 lines (47 loc) · 2.92 KB

ViewPDF — Agent Instructions

Build & Run

Build (no Node.js needed):

cargo tauri build

Dev:

cargo tauri dev

Frontend lives in src/ and is served directly (no bundler). No package.json.

CI triggers on v* tags and manual dispatch. Requires cargo install tauri-cli --locked first.

Rust Backend (src-tauri/)

  • Lib crate is viewstage_lib (_lib suffix avoids Cargo issue #8519 on Windows, see Cargo.toml:10-14).
  • main.rs calls viewstage_lib::run().
  • All Tauri commands registered in lib.rs:2928-2971 — check there before adding new ones.
  • Logging: simplelog writes to %APPDATA%/SECTL/ViewPDF/log/viewpdf_{date}.log.
  • Config: %APPDATA%/SECTL/ViewPDF/config.json, with a config version migration system (migrate_config/get_migrations).
  • Image save path: ~/Pictures/ViewPDF/.

Frontend (src/)

  • Entrypoint: src/index.html loads JS/pdf.min.js, JS/pdf.worker.min.js, i18n.js, then module scripts themes/theme.js, main.js, init.js.
  • No bundler — ES modules loaded directly; use type="module" for imports.
  • Init flow: init.js DOMContentLoaded → init i18n → initDOM → initCanvas → bindAllEvents → load settings → openCamera.
  • Architecture: image layer (<img>) + annotation layer (<canvas>) in a canvas-wrapper.
  • tauri.conf.json enables "withGlobalTauri": true — access via window.__TAURI__.
  • State management: global state object + global dom cache on window.
  • Tauri v2 IPC: window.__TAURI__.core.invoke(...).
  • CSP currently allows 'unsafe-inline' and 'unsafe-eval'.

Windows

  • oobe.html — first-run setup window (500×520, no decorations).
  • settings.html — settings popup (600×600).
  • doc-scan/index.html — document scanning sub-app (fullscreen, undecorated).

i18n

Locale files in src/locales/{zh-CN,zh-TW,en-US}.json. Setting stored in config.json under language key. i18n.init() called in init.js before anything else.

Tests

None found. No test framework is configured.

Key Quirks

  • Office document conversion uses PowerShell COM interop (Word/WPS/LibreOffice) — Windows only.
  • tauri.conf.json:bundle.targets is "all" — produces both MSI and NSIS installers.
  • NSIS installer hooks at installer-hooks.nsh — runs ViewPDF.exe --uninstall-cleanup on uninstall.
  • model/ and cache/ dirs are gitignored; ONNX model files go under %APPDATA%/SECTL/ViewPDF/models/.
  • gen/ under src-tauri/ is generated by Tauri build (schema files).

Uninstall Cleanup

  • ViewPDF.exe --uninstall-cleanup (or --cleanup) runs cleanup and exits without Tauri init.
  • Called automatically via NSIS uninstall hook (installer-hooks.nshNSIS_HOOK_PREUNINSTALL).
  • Cleans up: file association registry entries (ProgIDs, OpenWithProgids, UserChoice for .pdf/.docx/.doc) + deletes ViewPDF_MemClean scheduled task.
  • Implementation in lib.rs:3540-3558 (uninstall_cleanup_perform).