Skip to content

feat: Add native splash screen support via Electron#112

Open
Nexus633 wants to merge 4 commits into
NativePHP:mainfrom
Nexus633:main
Open

feat: Add native splash screen support via Electron#112
Nexus633 wants to merge 4 commits into
NativePHP:mainfrom
Nexus633:main

Conversation

@Nexus633
Copy link
Copy Markdown

🚀 The Problem

Currently, there is a significant "dead zone" (especially on Windows) between launching the application .exe and the first window appearing. This is because NativePHP must first initialize the PHP binary, start the local server, and boot the Laravel framework before any window can be opened via the NativeAppServiceProvider.

On some systems, this leads to several seconds of "silence" where the user might think the application didn't start.

✨ The Solution

This PR introduces a native Electron splash screen that triggers immediately after the Electron process starts, providing instant visual feedback.

Since it runs in the Electron main process, it doesn't wait for PHP to be ready. It includes a robust .env parser that works in both development (vendor context) and production environments.

🛠 Key Features

  • Instant Feedback: Shows a window within milliseconds of the double-click.
  • Smart Env Discovery: A recursive "Find-Up" algorithm to locate the .env file regardless of the directory depth (Dev vs. Prod).
  • Fully Configurable: Options for dimensions, custom HTML, and a master toggle.
  • Auto-Cleanup: The splash screen automatically closes as soon as the first application window is created by the PHP side.

⚙️ Configuration

Users can customize the behavior by adding these keys to their .env file:

NATIVEPHP_SPLASH_ENABLED=true
NATIVEPHP_SPLASH_WIDTH=400
NATIVEPHP_SPLASH_HEIGHT=300
NATIVEPHP_SPLASH_HTML=public/splash.html

📂 Implementation Details

splash.js

A new module responsible for:

  • Finding the project root and parsing the .env.
  • Creating a frameless, transparent BrowserWindow.

index.js

Modified the Electron entry point to:

  • Import and trigger the splash screen during app.whenReady().
  • Listen for the browser-window-created event to dismiss the splash screen once the Laravel app is ready.

✅ Checklist

  • Tested in Development mode (native:serve)
  • Tested in Production build (native:build)
  • Verified .env parsing logic on Windows
  • Ensured no breaking changes for users without splash configuration (defaults to false)

Andre added 3 commits May 13, 2026 16:17
…iately on app ready.

- Bypasses the "dead zone" while the PHP binary and Laravel framework are booting.
- Added a `splash.js` module to handle .env parsing and window management.
- Configuration is handled via .env variables for toggle, dimensions, and custom HTML paths.
…ly on app startup.

- Fixes the "empty space" issue where the app appears non-responsive while the PHP binary and Laravel framework are booting.
- Implements robust .env parsing on the Electron side using process.env.
- Adds intelligent closing logic that waits for the local Laravel URL (did-navigate) to ensure the main UI is ready.
- Support for both development and production (packaged) environments.
…ata directory in packaged environments.

- Implements app.isPackaged check for reliable path resolution within and outside the ASAR archive.
- Updates closing logic to use the 'did-navigate' event filtered by the local PHP server URL.
- This prevents premature dismissal of the splash screen by background installer or update processes.
- Ensures window dimensions are cast to integers to satisfy Electron API requirements.
- Replaced UI error dialogs with silent console logging for production-ready error handling.
@Nexus633
Copy link
Copy Markdown
Author

fix: Resolve splash screen visibility and lifecycle in production builds

📂 The Problem (Why the previous version failed)

The initial implementation of the splash screen worked in development but encountered two critical issues once the application was packaged and installed:

  1. Path Resolution: In the installed state (Windows AppData), the application runs from within an app.asar archive. The previous path-finding logic couldn't reliably locate the .env or the splash.html file outside of the development directory structure.
  2. Premature Closing: In production, Electron often triggers background windows (e.g., for installer hooks or auto-updates). The previous browser-window-created listener would catch these invisible windows and close the splash screen before the actual PHP-backed UI was ready.

✨ The Fix

This PR provides a robust update to ensure the splash screen is visible and functions correctly in all environments.

Technical Improvements:

  • Environment-Aware Pathing: Uses app.isPackaged to switch between a recursive "Find-Up" search for development and a direct appPath reference for production. This ensures compatibility with the resources/app structure in installed apps.
  • Smart URL Filtering: The splash screen now listens for the did-navigate event. It only dismisses itself when a window successfully navigates to the local PHP server (http://127.0.0.1 or localhost), ignoring any background system processes.
  • ASAR & Windows Compatibility: Forced absolute file URLs (file:///) for the splash HTML to ensure Electron can load assets reliably from the local filesystem on Windows.
  • Type-Safe Dimensions: Added parseInt() with a radix of 10 for all dimension variables to prevent Electron from falling back to default window sizes due to string-type inputs.

⚙️ Configuration (.env)

The configuration remains consistent with the previous iteration:

NATIVEPHP_SPLASH_ENABLED=true
NATIVEPHP_SPLASH_WIDTH=400
NATIVEPHP_SPLASH_HEIGHT=300
NATIVEPHP_SPLASH_HTML="public/splash.html"

📂 Implementation Details

splash.js: Modularized window management and .env parsing.
index.js: Integration into the Electron entry point and implementation of the did-navigate event listener for clean handoffs.

✅ Checklist

  • Verified in Development mode (native:serve)
  • Verified in Production build (Installed .exe)
  • Verified ASAR compatibility
  • No breaking changes (Defaults to disabled)

…ata directory in packaged environments.

- Implements app.isPackaged check for reliable path resolution within and outside the ASAR archive.
- Updates closing logic to use the 'did-navigate' event filtered by the local PHP server URL.
- This prevents premature dismissal of the splash screen by background installer or update processes.
- Ensures window dimensions are cast to integers to satisfy Electron API requirements.
- Replaced UI error dialogs with silent console logging for production-ready error handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant