mirror of
https://github.com/LukeHagar/sveltekit-adapters.git
synced 2025-12-09 20:57:48 +00:00
testing out a swap to a handler for electron
This commit is contained in:
@@ -3,37 +3,57 @@ import { start, load } from 'adapter-electron/functions';
|
||||
import isDev from 'electron-is-dev';
|
||||
import log from 'electron-log/main';
|
||||
import nodePath from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
log.info('Hello, log!');
|
||||
// Handle __dirname in ES modules
|
||||
const __dirname = nodePath.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
log.info('Starting Electron app with SvelteKit protocol integration...');
|
||||
|
||||
// Initialize the protocol manager
|
||||
const port = await start();
|
||||
|
||||
async function createWindow() {
|
||||
// Create the browser window
|
||||
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
width: 1200,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
preload: nodePath.join(__dirname, '../preload/index.mjs')
|
||||
preload: nodePath.join(__dirname, '../preload/index.mjs'),
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
webSecurity: true
|
||||
}
|
||||
});
|
||||
|
||||
// Load the local URL for development or the local
|
||||
// html file for production
|
||||
load(mainWindow, port);
|
||||
// Load the app - all routing is handled by protocol interception
|
||||
load(mainWindow);
|
||||
|
||||
if (isDev) mainWindow.webContents.openDevTools();
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools();
|
||||
}
|
||||
|
||||
// Handle window events
|
||||
mainWindow.webContents.on('did-finish-load', () => {
|
||||
log.info('Window loaded successfully');
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
|
||||
log.error('Window failed to load:', errorDescription);
|
||||
});
|
||||
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
app.whenReady().then(async () => {
|
||||
log.info('App is ready');
|
||||
|
||||
log.info('Creating window...');
|
||||
createWindow();
|
||||
await createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
app.on('activate', async () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
await createWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -43,3 +63,9 @@ app.on('window-all-closed', () => {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle render process crashes
|
||||
app.on('render-process-gone', (event, webContents, details) => {
|
||||
log.error('Render process crashed:', details.reason);
|
||||
// You could restart the window here if needed
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user