zoukankan      html  css  js  c++  java
  • Electron备忘录

    Electron是由GitHub开发的一个开源框架,原名为Atom Shell。其基于Node.js,使用chrome渲染引擎作为前端,可以进行跨平台的桌面GUI应用程序开发。如VSCode就是采用Electron开发的。

    使用中出现的问题

    linux下的root权限问题

    在linux下运行时,如果直接以非root用户运行,会得到如下错误信息:

    [184165:1125/121932.289721:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /electrontest/node_modules/electron/dist/chrome-sandbox is owned by root and has mode 4755.
    Trace/breakpoint trap (core dumped)

    根据错误提示,只需运行如下命令即可(需要root权限)

    sudo chown root:root /electrontest/node_modules/electron/dist/chrome-sandbox
    sudo chmod 4755 /electrontest/node_modules/electron/dist/chrome-sandbox
    

    需要注意的是,该错误是由于chrome-sandbox由于是沙箱程序,所以底层调用了需要root权限的api(大概)才产生的。在没有root权限的情况下(如统一管理的大型服务器系统),经测试,无论使用electron-packager打包成二进制软件,还是使用electron-builder打包成AppImage文件,都无法简单绕过该问题。

    Windows下 GPU process exited unexpectedly

    在笔者的一台Win10台式机上,electron官方demo运行时报出了如下错误,主窗口成功产生但内容空白。吊诡的是,通过菜单栏打开的子窗口内容显示正常,且没有新的报错信息产生,原因不明。除此之外,当全部窗口关闭时,electron程序并不能正常退出,依然留在后台,需要使用任务管理器手动关闭。

    > electrontest@1.0.0 start D:\electron-quick-start
    electron .

    [15988:1125/122710.428:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819
    [15988:1125/122710.556:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819
    [15988:1125/122710.678:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819
    [15988:1125/122710.795:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819
    [15988:1125/122710.913:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819
    [15988:1125/122711.030:ERROR:gpu_process_host.cc(968)] GPU process exited unexpectedly: exit_code=-1073741819

    该错误产生时,使用的electron版本是16.0.1,硬件为R5 3600+GTX760。该错误目前尚未在其他win10电脑上观察到。

    在electron版本16.0.1下,可添加如下代码部分解决问题(GPU进程异常退出提示减少为2条,主窗口正常显示内容):

    app.disableHardwareAcceleration();
    
    // 只加上面那个就行,下面两个加上效果相同
    app.commandLine.appendSwitch('enable-transparent-visuals');
    app.commandLine.appendSwitch('disable-gpu');
    

    此外,经测试可直接将package.js中electron版本设为^12.0.012.x版本中目前最新的是12.2.3,发布于2021年11月16日。采用该版本运行时完全没有出现GPU进程异常退出错误。

  • 相关阅读:
    hdu5593--ZYB's Tree(树形dp)
    poj1637--Sightseeing tour(最大流)
    Educational Codeforces Round 81 (Rated for Div. 2)
    【cf1286B】B. Numbers on Tree(贪心)
    【cf1285E】E. Delete a Segment(vector+二分)
    【cf1293E】E.Xenon's Attack on the Gangs(dp)
    Codeforces Round #609 (Div. 2)
    Educational Codeforces Round 78 (Rated for Div. 2)
    【bzoj4671】异或图(容斥+斯特林反演+线性基)
    【bzoj5339】[TJOI2018]教科书般的亵渎(拉格朗日插值/第二类斯特林数)
  • 原文地址:https://www.cnblogs.com/esctrionsit/p/15602157.html
Copyright © 2011-2022 走看看