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

Method applyColorSchemeToView

app/src/main/viewManager.ts:443–465  ·  view source on GitHub ↗
(view: WCView, colorScheme: 'light' | 'dark')

Source from the content-addressed store, hash-verified

441 }
442
443 applyColorSchemeToView(view: WCView, colorScheme: 'light' | 'dark') {
444 // This method is now only used for overlay views
445 // Regular views get color scheme injection via attachViewIPCEvents dom-ready handler
446 if (view.wcv && !view.wcv.webContents.isDestroyed() && view.isOverlay) {
447 const url = view.wcv.webContents.getURL()
448 const isSurfUrl = checkIfSurfProtocolUrl(url) || url.startsWith('surf-internal://')
449
450 if (isSurfUrl) {
451 view.wcv.webContents
452 .executeJavaScript(
453 `
454 if (document.documentElement) {
455 document.documentElement.dataset.colorScheme = '${colorScheme}';
456 document.documentElement.style.colorScheme = '${colorScheme}';
457 }
458 `
459 )
460 .catch((err) => {
461 log.warn('[main] Failed to inject color scheme into overlay view:', view.id, err)
462 })
463 }
464 }
465 }
466
467 updateAllViewsColorScheme(colorScheme: 'light' | 'dark') {
468 log.log('[main] Updating all WebContentsView color schemes to:', colorScheme)

Callers 1

createOverlayViewMethod · 0.95

Calls 4

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

Tested by

no test coverage detected