Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (48 loc) · 1.67 KB
/
Copy pathindex.js
File metadata and controls
57 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { app, BrowserWindow, shell } = require('electron');
const path = require('path');
const fs = require('fs');
const { startServer } = require('./server');
let mainWindow;
function loadPlugins() {
const pluginsDir = path.join(__dirname, 'plugins');
const plugins = []; // Array to hold loaded plugins
fs.readdirSync(pluginsDir).forEach(file => {
if (file.endsWith('.js')) {
const pluginPath = path.join(pluginsDir, file);
const plugin = require(pluginPath);
plugins.push(plugin); // Store the plugin for server hooks
}
});
return plugins; // Return loaded plugins
}
async function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: true,
}
});
mainWindow.loadURL(`file://${path.join(__dirname, 'loading.html')}`);
try {
const plugins = loadPlugins(); // Load plugins
const { port } = await startServer(plugins); // Pass plugins to the server
mainWindow.loadURL(`http://localhost:${port}`);
} catch (error) {
console.error('Error starting server:', error);
mainWindow.loadURL(`file://${path.join(__dirname, 'error.html')}`);
}
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('activate', () => {
if (mainWindow === null) createWindow();
});