-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.js
More file actions
98 lines (88 loc) · 2.2 KB
/
electron.js
File metadata and controls
98 lines (88 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// public/electron.js
const { app, BrowserWindow, Menu } = require('electron'); // Add Menu import
const path = require('path');
const isDev = require('electron-is-dev');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 900,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js') // Add preload script
},
});
// Load the app
mainWindow.loadURL(
isDev
? 'http://localhost:3000'
: `file://${path.join(__dirname, '../build/index.html')}`
);
// Create and set the application menu
const template = [
{
label: 'File',
submenu: [
{ role: 'quit' }
]
},
{
label: 'View',
submenu: [
{
label: 'Magnetization Calculator',
click: () => {
mainWindow.webContents.send('switch-component', 'magnetization');
}
},
{
label: 'Arbitrary Lattice',
click: () => {
mainWindow.webContents.send('switch-component', 'arbitrary');
}
},
{ type: 'separator' },
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Help',
submenu: [
{
label: 'About',
click: async () => {
require('electron').dialog.showMessageBox({
title: 'About Ising Model Calculator',
message: 'Ising Model Calculator v1.0.0',
buttons: ['OK']
});
}
}
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
// Open DevTools if in development
if (isDev) {
mainWindow.webContents.openDevTools();
}
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});