在 Electron 中创建新的 BrowserWindow 时使用透明参数并将其设置为 true 通常会为窗口提供透明背景......但据我所知在 Linux 上情况并非如此
现在我听说您可以设置一些命令行参数...但是那不起作用...无论如何它都显示黑色或白色...
// Should set the commandLine arguments and work...
const {app} = require('electron')
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');
现在我听说这不是 Electron 的问题而是硬件的问题......但我只需要确保因此创建这个问题!
最佳答案
我遇到了和你一样的问题,所以我写了:
- 这个 StackOverFlow 问题: Can't succeed in making transparent window in Electron (javascript)
- 本期 Electron 问题:https://github.com/electron/electron/issues/15947
- 最后请求此功能:https://github.com/electron/electron/issues/16809
在实现请求的功能之前,解决方案很简单,只需在启动窗口之前添加延迟即可。
你可以克隆this git repo ,把延迟调到500,正常魔法就会出现。
编辑 1: 使用此存储库:https://gitlab.com/doom-fr/electron-transparency-demo
git clone https://gitlab.com/doom-fr/electron-transparency-demo
cd electron-transparency-demo
npm install
npm start
# or npm run startWithTransparentOption
# or npm run startWithAllOptions
对我来说,对于 npm start
、npm run startWithTransparentOption
,它可以与 Debian Jessie 和 electron 4.0.5 开箱即用,但不能与 npm run startWithAllOptions
.
注意:请小心设置至少 500 毫秒,以确保其正常工作。之后可以减少延迟但不稳定。这就是为什么需要 transparentReady 事件的原因。
末日
关于javascript - Linux 上的透明 Windows (Electron),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54763647/