mirror of
https://github.com/LukeHagar/sveltekit-adapters.git
synced 2025-12-06 04:21:32 +00:00
testing out a swap to a handler for electron
This commit is contained in:
@@ -7,44 +7,47 @@
|
||||
"name": "Luke Hagar",
|
||||
"email": "lukeslakemail@gmail.com"
|
||||
},
|
||||
"homepage": "https://github.com/lukehagar/sveltekit-adapters",
|
||||
"main": "./out/main/index.js",
|
||||
"scripts": {
|
||||
"start": "electron-vite preview",
|
||||
"dev": "electron-vite dev",
|
||||
"dev": "svelte-kit sync && electron-vite dev",
|
||||
"build": "electron-vite build",
|
||||
"build:all": "npm run build && electron-builder -mwl --config",
|
||||
"build:win": "npm run build && electron-builder --win --config",
|
||||
"build:mac": "npm run build && electron-builder --mac --config",
|
||||
"build:linux": "npm run build && electron-builder --linux --config"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fontsource/fira-mono": "^5.0.8",
|
||||
"@neoconfetti/svelte": "^2.2.1",
|
||||
"@sveltejs/kit": "^2.5.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
||||
"@types/eslint": "8.56.2",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
||||
"@typescript-eslint/parser": "^7.0.1",
|
||||
"@fontsource/fira-mono": "^5.2.6",
|
||||
"@neoconfetti/svelte": "^2.2.2",
|
||||
"@sveltejs/kit": "^2.22.2",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.1.0",
|
||||
"@types/eslint": "9.6.1",
|
||||
"@types/node": "^24.0.10",
|
||||
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
||||
"@typescript-eslint/parser": "^8.35.1",
|
||||
"adapter-electron": "workspace:*",
|
||||
"concurrently": "^8.2.2",
|
||||
"concurrently": "^9.2.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^16.4.4",
|
||||
"electron": "^28.2.3",
|
||||
"electron-builder": "^24.9.1",
|
||||
"dotenv": "^17.0.1",
|
||||
"electron": "^37.2.0",
|
||||
"electron-builder": "^26.0.12",
|
||||
"electron-is-dev": "^3.0.1",
|
||||
"electron-log": "^5.1.1",
|
||||
"electron-util": "^0.18.0",
|
||||
"electron-vite": "^2.0.0",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-svelte": "^2.35.1",
|
||||
"electron-log": "^5.4.1",
|
||||
"electron-util": "^0.18.1",
|
||||
"electron-vite": "^3.1.0",
|
||||
"eslint": "^9.30.1",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-svelte": "^3.10.1",
|
||||
"polka": "^0.5.2",
|
||||
"prettier": "^3.2.5",
|
||||
"prettier-plugin-svelte": "^3.2.1",
|
||||
"svelte": "^4.2.11",
|
||||
"svelte-check": "^3.6.4",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.1.3"
|
||||
"prettier": "^3.6.2",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"svelte": "^5.35.1",
|
||||
"svelte-check": "^4.2.2",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.0.0"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
"moduleResolution": "bundler",
|
||||
"module": "ES2022",
|
||||
"target": "ES2022",
|
||||
"types": ["node", "electron"]
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
//
|
||||
|
||||
@@ -2,6 +2,9 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
target: 'chrome107'
|
||||
},
|
||||
logLevel: 'info',
|
||||
plugins: [sveltekit()]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user