MCPcopy Create free account
hub / github.com/deta/surf / updateAllViewsColorScheme

Method updateAllViewsColorScheme

app/src/main/viewManager.ts:467–495  ·  view source on GitHub ↗
(colorScheme: 'light' | 'dark')

Source from the content-addressed store, hash-verified

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)

Callers 1

attachIPCEventsMethod · 0.95

Calls 6

checkIfSurfProtocolUrlFunction · 0.90
logMethod · 0.80
forEachMethod · 0.80
getURLMethod · 0.80
warnMethod · 0.80
executeJavaScriptMethod · 0.45

Tested by

no test coverage detected