在没有GUI的情况下运行Electron [英] Run Electron without GUI

查看:106
本文介绍了在没有GUI的情况下运行Electron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了这个问题被问到,但是该问题的内容有所不同,所以有没有关于我的用例的答案,所以我要问一个新问题

I see this question has been asked but the context of that question is different and so there are no answers relavent to my use case so I'm asking a new question

我有一个基于电子的Web服务器.它适用于不习惯命令行的新手Web开发人员,学生和艺术家(是的,这是一个巨大的争论,但是我受到了加州大学洛杉矶分校艺术与设计学院的老师的责骂,要求他们的学生使用该命令行,因此是带有GUI的简单服务器.请不要争论这一点.这不是问题的重点)

I have an Electron based Web Server. It's meant for beginning web developers, students, and artists that are not used to the command line (yes that's a huge debate right there but I was scolded by the teachers at the Art and Design School at UCLA for asking their students to use the command line, hence a simple server with a GUI. Please don't debate this point. It's not the point of the question)

在任何情况下,使用此Web服务器的人有时都希望在端口80上运行.在Mac(和Linux?)上,端口80需要管理员权限,因此我想升级服务器的权限.

In any case, people using this web server sometimes want to run on port 80. On Mac (and Linux?) port 80 requires admin rights and so I'd like to escalate the server's permissions to do this.

我的理解是最简单(唯一?)的方法是生成另一个进程.由于我的Web服务器的服务器部分实际上是用node.js编写的,并且因为node.js(或至少是API)是内置在Electron中的,所以看来最好的解决方案是重新生成我的Electron应用程序以运行仅服务器部分.

My understanding is the easiest (only?) way to do this is to spawn another process. Since the server part of my web server is effectively written in node.js and since node.js (or at least the API) is built into Electron then it seems like the best solution would be to just re-spawn my Electron app to run only the server portion.

换句话说,假设我可以像这样运行应用程序

In other words, imagine I could run the app like

/Applications/Servez.app/Contents/MacOS/Servez --no-gui --server-only --port 80

然后我可以在Mac上使用一些生成命令,例如

Then I could use some spawn command on Mac like

/usr/bin/osascript -e '
do shell "/Applications/Servez.app/Contents/MacOS/Servez --no-gui --server-only --port 80" with administrator privileges
'

并且macOS将在运行服务器之前询问管理员权限.

And macOS will ask for admin privileges before running the server.

如果我无法在没有GUI的情况下运行Electron,那么我可以在Electron包中包含一个node.js副本,但是由于Electron中已经具有相同的功能,因此这似乎是对空间的巨大浪费.也许还有其他解决方案?(我可以拨打一些API来请求使用端口80的许可?)

If I can't run Electron with no GUI then I could include a copy of node.js inside the Electron package but it seems like a huge waste of space given the same functionality is already inside Electron. Or maybe there is some other solution? (some API call I can make to ask for permission to use port 80?)

推荐答案

设置环境变量 ELECTRON_RUN_AS_NODE 会将Electron作为节点运行,因此我可以在生成Electron时设置该环境变量

Setting the environment variable ELECTRON_RUN_AS_NODE will run Electron as node so I can just set that environment variable when spawning Electron

这篇关于在没有GUI的情况下运行Electron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆