diff --git a/src/native/window.ts b/src/native/window.ts index 5164de6..47341e2 100644 --- a/src/native/window.ts +++ b/src/native/window.ts @@ -142,7 +142,10 @@ export function createMainWindow() { }); // send the config - mainWindow.webContents.on("did-finish-load", () => config.sync()); + mainWindow.webContents.on("did-finish-load", () => { + config.sync(); + injectBranding(mainWindow.webContents); + }); // configure spellchecker context menu mainWindow.webContents.on("context-menu", (_, params) => { @@ -200,6 +203,37 @@ export function createMainWindow() { // setInterval(() => setBadgeCount((++i % 30) + 1), 1000); } +function injectBranding(wc: Electron.WebContents) { + const logoUrl = windowIconAsset; + wc.insertCSS(` + /* Hide Revolt text/wordmark labels */ + [class*="wordmark"], [class*="Wordmark"], [data-app-name] { display: none !important; } + `); + wc.executeJavaScript(` + (function() { + const LOGO = ${JSON.stringify(logoUrl)}; + function patch() { + document.querySelectorAll('img').forEach(function(img) { + var src = img.getAttribute('src') || ''; + var alt = (img.getAttribute('alt') || '').toLowerCase(); + if ( + src.includes('revolt') || + alt === 'revolt' || + alt === 'stoat' || + (src.startsWith('/') && src.match(/\\.(svg|png|webp)/) && alt.match(/revolt|logo/i)) + ) { + img.src = LOGO; + img.removeAttribute('srcset'); + img.alt = 'Sanctum'; + } + }); + } + patch(); + new MutationObserver(patch).observe(document.documentElement, { childList: true, subtree: true }); + })(); + `, true).catch(function() {}); +} + /** * Quit the entire app */