-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
117 lines (92 loc) · 2.32 KB
/
Copy pathmain.js
File metadata and controls
117 lines (92 loc) · 2.32 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const { app, BrowserWindow, screen, ipcMain, shell } = require('electron');
const path = require('path');
let win;
ipcMain.on('open-external', (event, url) => {
try {
const parsed = new URL(url);
// ✅ strict allowlist
if (
parsed.hostname.endsWith('ogdp.in') ||
parsed.hostname.endsWith('emsc-csem.org')
) {
shell.openExternal(url);
} else {
console.warn('Blocked external:', url);
}
} catch {
console.warn('Invalid URL:', url);
}
});
function createWindow() {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
const widgetWidth = 400;
const iconMap = {
win32: 'icon.ico',
linux: 'icon.png',
darwin: 'icon.png'
};
const iconPath = path.join(__dirname, 'build', 'icons', iconMap[process.platform]);
win = new BrowserWindow({
width: widgetWidth,
height,
x: width - widgetWidth,
y: 0,
resizable: false,
frame: false,
transparent: true,
backgroundColor: '#00000000',
alwaysOnTop: false,
skipTaskbar: false,
icon: iconPath,
fullscreenable: false,
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true,
sandbox: true
}
});
win.on('enter-full-screen', () => {
win.setFullScreen(false);
});
win.setMenuBarVisibility(false);
win.loadFile('index.html');
win.webContents.setWindowOpenHandler(({ url }) => {
try {
const parsed = new URL(url);
if (parsed.hostname.endsWith('ogdp.in')) {
shell.openExternal(url);
}
} catch {}
return { action: 'deny' };
});
win.webContents.on('will-navigate', (event, url) => {
event.preventDefault();
try {
const parsed = new URL(url);
if (parsed.hostname.endsWith('ogdp.in')) {
shell.openExternal(url);
}
} catch {}
});
win.once('ready-to-show', () => {
win.show();
});
win.on('closed', () => {
win = null;
});
}
ipcMain.on('close-window', () => {
if (win) win.close();
});
app.whenReady().then(() => {
createWindow();
setTimeout(() => {}, 100);
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});