問題描述
在 Electron 中創(chuàng)建新的 BrowserWindow 時使用 transparent 參數(shù)并將其設(shè)置為 true 通常會為窗口提供透明背景...但據(jù)我所知,在 Linux 上并非如此
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 the case for my knowledge
現(xiàn)在我聽說您可以設(shè)置一些命令行參數(shù)...但這不起作用...無論如何它只會顯示黑色或白色...
Now I heard you can set some Command Line Arguments... But that isn't working... It just displays black or white no matter what...
// Should set the commandLine arguments and work...
const {app} = require('electron')
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');
現(xiàn)在我聽說這不是電子問題,而是硬件問題......但我只需要確保因此創(chuàng)建這個問題!
Now i have heard this is no problem with electron rather a problem with hardware... But i just needed to make sure therefore creating this question!
推薦答案
我遇到了和你一樣的問題,所以寫了:
I have encounter the same problem as you and so I have written :
- 這個 StackOverFlow 問題:無法在 Electron (javascript) 中成功制作透明窗口
- 這個 Electron 問題:https://github.com/electron/electron/issues/15947
- 最后請求此功能:https://github.com/electron/electron/issues/16809
在實現(xiàn)所請求的功能之前,解決方案很簡單,只需在啟動窗口之前添加延遲即可.
Till the requested feature is implemented, the solution is simple just add a delay before launching the window.
你可以克隆 這個 git repo,把延遲放到500,一般會出現(xiàn)魔法.
You can clone this git repo, put the delay to 500, and normally magic will appear.
編輯 1:使用這個倉庫:https://gitlab.com/doom-fr/electron-transparency-demo
EDIT 1 : Use this repo : 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
對我來說,它適用于 Debian Jessie 和 electron 4.0.5,適用于 npm start
、npm run startWithTransparentOption
但不適用于 npm runstartWithAllOptions
.
For me, it works out of the box with Debian Jessie and electron 4.0.5, for npm start
, npm run startWithTransparentOption
but not with npm run startWithAllOptions
.
注意:請小心設(shè)置至少 500 毫秒,以便有機會正常工作.之后可以減少延遲但不穩(wěn)定.這就是為什么需要在 transparentReady 上的事件.
NB : be carefull to set at least 500ms to have chance it works. After you can reduce the delay but it is not stable. It is why an event on transparentReady is needed.
厄運
這篇關(guān)于Linux 上的透明窗口(電子)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!