$ show jgraph/drawio-desktop
drawio-desktop is an Electron-based desktop application that wraps the core draw.io diagramming editor (included as a git submodule). It provides a fully offline diagramming experience with a security-first design: Content Security Policy prevents remote script execution, IPC is gated through contextBridge with sender validation, and file operations enforce path authorisation against symlink attacks. The application supports CLI-based batch export (PNG, PDF, SVG, HTML, XML) with a hand-rolled argument parser, per-window file watching, auto-update via electron-updater, and platform-specific builds for Windows (x64/arm64, MSI, NSIS, APPX), macOS (dmg, zip, Quick Look preview), and Linux (AppImage, deb, rpm, snap). The architecture is a monolithic Electron main process (src/main/electron.js) communicating with the renderer (drawio submodule) through a secure IPC bridge. The codebase demonstrates high craftsmanship in security-sensitive areas such as backup file writes using exclusive temp files and rename, CLI export symlink handling, and per-window file watch registry. It is actively maintained with recent commits and comprehensive CI/CD pipelines.
The LLM identified 4 files worth highlighting for reuse:
Implements writeBackupFile which writes a backup using an exclusively created temporary file followed by rename, preventing symlink-based attacks (GHSA-36x5-vw5q-29rv). The pattern is self-contained, uses only Node.js built-in modules (fs, path, crypto), and can be extracted into any project needing safe file overwrites without following symlinks.
Provides listExportFiles and openExportFile for CLI export mode. listExportFiles scans directories without following symbolic links (even inside the folder) and never stats their targets, preventing credential leakage via UNC paths. openExportFile refuses to write through symlinks using lstat + O_NOFOLLOW. Pure Node.js, no Electron dependencies, fully unit-testable. Reusable for any CLI tool that needs to safely process user-provided directories.
Implements a per-owner (webContents) file watch registry that prevents change events from leaking between windows and avoids duplicate listeners. The fs implementation is injected, making it unit-testable without Electron. Provides watch, unwatch, and unwatchAll methods. Reusable pattern for any application that needs to manage multiple file watchers tied to different consumers.
Provides parseLastWinSize and placeWindowOnDisplays to restore window bounds safely across display changes. Validates saved positions against current work areas, centering on the primary display if the saved position is off-screen or the title bar is not visible. Pure functions with no Electron imports, fully unit-testable. Reusable for any desktop application that needs to persist and restore window geometry.