-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme-manager.js
46 lines (39 loc) · 1.42 KB
/
theme-manager.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
// Theme management
const themeManager = {
init() {
this.applySystemTheme();
this.setupSystemThemeListener();
// Listen for theme changes from main process
window.api.receive('apply-theme', (theme) => {
this.applyTheme(theme);
});
// Ensure webview theme is synced after it loads
const webview = document.getElementById('perplexityView');
if (webview) {
webview.addEventListener('dom-ready', () => {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
window.api.send('theme-change', systemTheme);
});
}
},
applySystemTheme() {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
this.setTheme(systemTheme);
},
setupSystemThemeListener() {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
this.setTheme(e.matches ? 'dark' : 'light');
});
},
setTheme(theme) {
this.applyTheme(theme);
// Send theme change to main process
window.api.send('theme-change', theme);
},
applyTheme(theme) {
const isDark = theme === 'dark';
document.body.classList.toggle('dark-mode', isDark);
}
};
// Export for use in other files
window.themeManager = themeManager;