(colorScheme: 'light' | 'dark')
| 465 | } |
| 466 | |
| 467 | updateAllViewsColorScheme(colorScheme: 'light' | 'dark') { |
| 468 | log.log('[main] Updating all WebContentsView color schemes to:', colorScheme) |
| 469 | |
| 470 | // Set nativeTheme to allow websites to detect dark mode preference via prefers-color-scheme |
| 471 | nativeTheme.themeSource = colorScheme |
| 472 | |
| 473 | // Inject color scheme into all existing views (only for internal surf:// URLs) |
| 474 | this.views.forEach((view) => { |
| 475 | if (view.wcv && !view.wcv.webContents.isDestroyed()) { |
| 476 | const url = view.wcv.webContents.getURL() |
| 477 | const isSurfUrl = checkIfSurfProtocolUrl(url) || url.startsWith('surf-internal://') |
| 478 | |
| 479 | if (isSurfUrl) { |
| 480 | view.wcv.webContents |
| 481 | .executeJavaScript( |
| 482 | ` |
| 483 | if (document.documentElement) { |
| 484 | document.documentElement.dataset.colorScheme = '${colorScheme}'; |
| 485 | document.documentElement.style.colorScheme = '${colorScheme}'; |
| 486 | } |
| 487 | ` |
| 488 | ) |
| 489 | .catch((err) => { |
| 490 | log.warn('[main] Failed to inject color scheme into view:', view.id, err) |
| 491 | }) |
| 492 | } |
| 493 | } |
| 494 | }) |
| 495 | } |
| 496 | |
| 497 | getWebContentsViews() { |
| 498 | return Array.from(this.views.values()).map((v) => v.wcv) |
no test coverage detected