Skip to content

Commit 90ba39c

Browse files
committed
Inject CSS to bypass Linux software renderer black background bugs
1 parent cf51a38 commit 90ba39c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

build/after-pack.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ exec "\${ELECTRON_BIN}" "\${extra_args[@]}" "$@"
114114
}
115115

116116
// Hide the native menu bar and fix black transparent background on Linux
117-
const buildDir = path.join(appOutDir, 'resources', 'app', '.vite', 'build');
117+
let buildDir = path.join(appOutDir, 'resources', 'app', '.vite', 'build');
118118
const bootstrapPath = path.join(buildDir, 'bootstrap.js');
119119
if (fs.existsSync(bootstrapPath)) {
120120
let content = fs.readFileSync(bootstrapPath, 'utf8');
121-
const inject = `(()=>{const {app,nativeTheme}=require("electron");app.on("browser-window-created",(e,w)=>{w.setMenuBarVisibility(false);w.autoHideMenuBar=true;const updateBg=()=>{try{w.setBackgroundColor(nativeTheme.shouldUseDarkColors?"#1c1c1e":"#f5f5f7");}catch(err){}};updateBg();nativeTheme.on("updated",updateBg);});})();`;
121+
const inject = `(()=>{const {app,nativeTheme}=require("electron");app.on("browser-window-created",(e,w)=>{w.setMenuBarVisibility(false);w.autoHideMenuBar=true;const updateBg=()=>{try{const bg=nativeTheme.shouldUseDarkColors?"#1e1e1e":"#ffffff";w.setBackgroundColor(bg);w.webContents.insertCSS(\`* { backdrop-filter: none !important; } aside, nav, [class*="sidebar"] { background-color: \${bg} !important; }\`);}catch(err){}};w.webContents.on("dom-ready",updateBg);updateBg();nativeTheme.on("updated",updateBg);});})();`;
122122
if (!content.includes('setMenuBarVisibility')) {
123123
content = content.replace('require("electron");', `require("electron");${inject}`);
124124
fs.writeFileSync(bootstrapPath, content);
125-
} else if (content.includes('w.setMenuBarVisibility(false);w.autoHideMenuBar=true;});')) {
126-
content = content.replace('require("electron").app.on("browser-window-created",(e,w)=>{w.setMenuBarVisibility(false);w.autoHideMenuBar=true;});', inject);
125+
} else if (content.includes('const updateBg=()=>{try{w.setBackgroundColor')) {
126+
// Replace the previous injection with the new one
127+
content = content.replace(/\(\(\)=>\{const \{app,nativeTheme\}=require\("electron"\);app\.on\("browser-window-created",\(e,w\)=>\{w\.setMenuBarVisibility\(false\);w\.autoHideMenuBar=true;const updateBg=\(\)=>\{try\{w\.setBackgroundColor.*?\}\)\(\);/g, inject);
127128
fs.writeFileSync(bootstrapPath, content);
128129
}
129130
}

0 commit comments

Comments
 (0)