Transparent Windows on Linux (Electron)

后端 未结 3 2045
长情又很酷
长情又很酷 2021-02-14 23:07

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:18

    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);
    });
    

提交回复
热议问题