Files
bolt-diy/electron/main/ui/window.ts
zhaomenghuan02 33725102e2 feat: add Electron hot-reload development mode
- Add electron-dev.mjs script for hot-reload development
- Support automatic Electron dependency building
- Start Remix dev server and Electron app concurrently
- Add proper process management and cleanup
- Fix preload script path for development mode
- Add electron:dev and electron:dev:inspect npm scripts

This enables developers to run 'pnpm electron:dev' for a complete
hot-reload development experience with automatic rebuilding and
process management.
2025-09-13 00:19:42 +08:00

55 lines
1.4 KiB
TypeScript

import { app, BrowserWindow } from 'electron';
import path from 'node:path';
import { isDev } from '../utils/constants';
import { store } from '../utils/store';
export function createWindow(rendererURL: string) {
console.log('Creating window with URL:', rendererURL);
const bounds = store.get('bounds');
console.log('restored bounds:', bounds);
// preload path
const preloadPath = path.join(isDev ? process.cwd() : app.getAppPath(), 'build', 'electron', 'preload', 'index.cjs');
const win = new BrowserWindow({
...{
width: 1200,
height: 800,
...bounds,
},
vibrancy: 'under-window',
visualEffectState: 'active',
webPreferences: {
preload: preloadPath,
},
});
console.log('Window created, loading URL...');
win.loadURL(rendererURL).catch((err) => {
console.log('Failed to load URL:', err);
});
win.webContents.on('did-fail-load', (_, errorCode, errorDescription) => {
console.log('Failed to load:', errorCode, errorDescription);
});
win.webContents.on('did-finish-load', () => {
console.log('Window finished loading');
});
// Open devtools in development
if (isDev) {
win.webContents.openDevTools();
}
const boundsListener = () => {
const bounds = win.getBounds();
store.set('bounds', bounds);
};
win.on('moved', boundsListener);
win.on('resized', boundsListener);
return win;
}