-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreload.js
More file actions
78 lines (64 loc) · 2.1 KB
/
preload.js
File metadata and controls
78 lines (64 loc) · 2.1 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
const { contextBridge, ipcRenderer, nativeTheme } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
openExternal: (url) => ipcRenderer.invoke('open-external', url),
platform: process.platform,
isDarkMode: () => nativeTheme.shouldUseDarkColors
});
window.addEventListener('DOMContentLoaded', () => {
const userAgent = navigator.userAgent.replace(/Electron\/[^\s]+\s/, '');
Object.defineProperty(navigator, 'userAgent', {
value: userAgent,
writable: false
});
// Inject system theme CSS
const style = document.createElement('style');
style.textContent = `
/* System-native scrollbars */
::-webkit-scrollbar {
width: 12px;
height: 12px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
border-radius: 6px;
border: 2px solid transparent;
background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.3);
}
/* Dark mode scrollbars */
@media (prefers-color-scheme: dark) {
::-webkit-scrollbar-thumb {
background-color: rgba(255, 255, 255, 0.2);
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(255, 255, 255, 0.3);
}
}
/* System font stack */
body, * {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
}
/* System selection colors */
::selection {
background: Highlight;
color: HighlightText;
}
`;
document.head.appendChild(style);
// Apply theme class based on system preference
const applyTheme = () => {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
}
};
applyTheme();
// Listen for theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', applyTheme);
});