|
| 1 | +/** |
| 2 | + * @fileoverview Bootstrap module for FlashForgeUI Electron application. |
| 3 | + * |
| 4 | + * CRITICAL: This file must be imported FIRST in index.ts, before any other imports. |
| 5 | + * |
| 6 | + * Purpose: |
| 7 | + * Sets the Electron app name and user model ID before any singletons are instantiated. |
| 8 | + * This ensures that all services using app.getPath('userData') point to the correct |
| 9 | + * directory across all platforms and execution modes (normal UI and headless). |
| 10 | + * |
| 11 | + * Problem it solves: |
| 12 | + * - Singletons like ConfigManager and PrinterDetailsManager capture app.getPath('userData') |
| 13 | + * during construction |
| 14 | + * - If app.setName() is called after these singletons are created, they will use the wrong |
| 15 | + * directory (e.g., "Electron" instead of "FlashForgeUI") |
| 16 | + * - This caused headless mode on macOS/Linux to read from a different config directory |
| 17 | + * than the main UI, resulting in missing per-printer settings (custom camera/LED config) |
| 18 | + * |
| 19 | + * Platform-specific userData paths: |
| 20 | + * - macOS: ~/Library/Application Support/FlashForgeUI/ |
| 21 | + * - Linux: ~/.config/FlashForgeUI/ |
| 22 | + * - Windows: %APPDATA%/FlashForgeUI/ |
| 23 | + * |
| 24 | + * Without this bootstrap (default "Electron" name): |
| 25 | + * - macOS: ~/Library/Application Support/Electron/ |
| 26 | + * - Linux: ~/.config/Electron/ |
| 27 | + * - Windows: %APPDATA%/Electron/ |
| 28 | + */ |
| 29 | + |
| 30 | +import { app } from 'electron'; |
| 31 | + |
| 32 | +// Set app name BEFORE any singletons are created |
| 33 | +// This ensures ConfigManager, PrinterDetailsManager, and all other services |
| 34 | +// use the correct userData directory path |
| 35 | +app.setName('FlashForgeUI'); |
| 36 | + |
| 37 | +// Set AppUserModelId to match electron-builder appId for proper notification routing |
| 38 | +// This works across all platforms (Windows uses it for Action Center, macOS for notification attribution) |
| 39 | +app.setAppUserModelId('com.ghosttypes.flashforgeui'); |
| 40 | + |
| 41 | +console.log('[Bootstrap] App name set to "FlashForgeUI"'); |
| 42 | +console.log(`[Bootstrap] userData path: ${app.getPath('userData')}`); |
0 commit comments