-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (52 loc) · 1.41 KB
/
main.js
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
const { app, BrowserWindow } = require('electron');
const path = require('path');
let win;
function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
icon: process.platform === 'darwin'
? path.join(__dirname, 'icons/icon.icns')
: path.join(__dirname, 'icons/icon_256x256.ico'),
});
win.maximize();
win.loadFile('index.html');
}
function openFile(filePath) {
console.log('File opened:', filePath);
}
app.whenReady().then(() => {
createWindow();
app.on('open-file', (event, filePath) => {
event.preventDefault();
if (win) {
openFile(filePath);
} else {
app.once('browser-window-created', () => {
openFile(filePath);
});
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
if (process.platform === 'win32' && process.argv.length >= 2) {
const openedFilePath = process.argv[1];
openFile(openedFilePath);
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('second-instance', (event, argv) => {
if (process.platform === 'win32' && argv.length >= 2) {
const openedFilePath = argv[1];
if (win) {
openFile(openedFilePath);
}
}
});