Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
69 lines (63 loc) · 2.21 KB
/
Copy pathpreload.js
File metadata and controls
69 lines (63 loc) · 2.21 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
const { ipcRenderer } = require('electron');
const { allowedHosts } = require('./constants');
// Network status detection
function updateNetworkStatus() {
ipcRenderer.send('network-status', navigator.onLine);
}
window.addEventListener('online', updateNetworkStatus);
window.addEventListener('offline', updateNetworkStatus);
// Don't call updateNetworkStatus() immediately to avoid reload loops
// Only send status on actual online/offline events
// Listen for DOMContentLoaded event
window.addEventListener('DOMContentLoaded', () => {
// Wire up retry button on offline page
const retryBtn = document.getElementById('retry-btn');
if (retryBtn) {
retryBtn.addEventListener('click', () => {
ipcRenderer.send('retry-connection');
});
}
// Listen for click events and open non-allowed links externally
document.addEventListener('click', (event) => {
const target = event.target;
if (!(target instanceof Element)) {
return;
}
const link = target.closest('a');
if (link && link.href && link.href.startsWith('http')) {
try {
const host = new URL(link.href).host;
if (allowedHosts.has(host)) {
return; // Allow app + auth links to navigate in-app
}
} catch (e) {
// If URL parsing fails, open externally as a safety measure
}
event.preventDefault();
ipcRenderer.send('open-external-link', link.href);
}
});
});
// Handle keyboard shortcuts for zoom
document.addEventListener('keydown', (event) => {
if (event.ctrlKey) {
if (event.key === '+') {
ipcRenderer.send('zoom-in');
} else if (event.key === '-') {
ipcRenderer.send('zoom-out');
} else if (event.key === '0') {
ipcRenderer.send('zoom-reset');
}
}
});
// Handle mouse wheel zoom
document.addEventListener('wheel', (event) => {
if (event.ctrlKey) {
event.preventDefault(); // Prevent default scrolling
if (event.deltaY < 0) {
ipcRenderer.send('zoom-in');
} else {
ipcRenderer.send('zoom-out');
}
}
});