-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
106 lines (92 loc) · 2.89 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
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
99
100
101
102
103
104
105
106
/**
* Main process of the Electron application.
*
* This script sets up the main window of the application, configures the application behavior
* (like handling window creation and application lifecycle events), and establishes inter-process
* communication (IPC) for actions like opening URLs in the user's default browser.
*/
// Electron modules and Node.js path module are required for Electron app functionality and file path operations.
const { app, BrowserWindow, ipcMain, shell, Menu } = require("electron");
const path = require("path");
const isDev = process.env.NODE_ENV === "development";
/**
* Creates the main window of the Electron application.
*/
function createWindow() {
// Initialize the BrowserWindow with specific properties.
const mainWindow = new BrowserWindow({
width: 600,
height: 480,
resizable: false,
title: "Chapter Injector by Mark Battistella",
movable: true,
minimizable: false,
maximizable: false,
skipTaskbar: true,
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, "./modules/preload.mjs"),
nodeIntegration: true, // Deprecated and should generally be false for security.
contextIsolation: true, // Enable context isolation for security.
contentSecurityPolicy: "default-src 'self'", // Content security policy.
webSecurity: true, // Enable web security.
},
});
// Hide the menu bar
mainWindow.setMenu(null);
// Load the HTML file for the window.
mainWindow.loadFile("data/index.html");
// Open the DevTools in development mode for debugging.
if (isDev) {
mainWindow.webContents.openDevTools();
}
}
// When Electron app is ready, create the main window.
app.whenReady().then(createWindow);
/**
* Handles the 'window-all-closed' event to quit the application when all windows are closed,
* except on macOS (Darwin), where applications generally continue running.
*/
app.on("window-all-closed", () => {
app.quit();
});
const isMac = process.platform === 'darwin'
const template = [
...(isMac ?
[{
role: 'help',
title: 'dd',
submenu: [
{
label: 'Source code',
click: async () => {
await shell.openExternal('https://github.com/markbattistella/video-chapter-injector')
}
},
{
label: 'Author Website',
click: async () => {
await shell.openExternal('https://markbattistella.com')
}
}
]
}]
: []
)
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
/**
* Listens for 'open-url' messages from the renderer process to open URLs in the default web browser.
*/
ipcMain.on("open-url", (event, url) => {
shell.openExternal(url);
});
// Attempt to enable live reload during development.
if (isDev) {
try {
require('electron-reloader')(module, {
ignore: ['_test/**']
});
} catch (_) {}
}