Transparent Windows on Linux (Electron)

后端 未结 3 983
陌清茗
陌清茗 2021-02-14 23:10

Using the transparent argument and setting it to true when creating a new BrowserWindow in Electron usually gives the window a transparent background... But on Linux that isn\'t

3条回答
  •  时光说笑
    2021-02-14 23:12

    This code might work for you. I add explain in comment.

    //electron can't be transparent on linux
    //see issue on github: https://github.com/electron/electron/issues/2170
    
    // app.disableHardwareAcceleration(); //use this
    //or use these two lines code
    app.commandLine.appendSwitch('enable-transparent-visuals');
    app.commandLine.appendSwitch('disable-gpu');
    
    //createWindow need to wait(more than about 100ms) if you want the window to be transparent
    // app.whenReady().then(createWindow); //this won't work
    app.commandLine.appendSwitch('enable-transparent-visuals');
    app.commandLine.appendSwitch('disable-gpu');
    app.on('ready', () => {
        setTimeout(() => {
            createWindow();
        }, 200);
    });
    

提交回复
热议问题