简体   繁体   English

正确使用电子

[英]Properly using Electron

I want to get into Electron, and I have already started learning about it, however I don't think I quite understand how I am supposed to use it. 我想进入Electron,我已经开始了解它,但我不认为我完全理解我应该如何使用它。 From what I gathered, with Electron I am able to create cross-desktop applications (Chromium) with HTML, CSS and Javascript and do tasks in the background (NodeJS) . 从我收集的内容中,通过Electron,我可以使用HTML,CSS和Javascript创建跨桌面应用程序(Chromium) ,并在后台执行任务(NodeJS)

What confuses me is the following: 令我困惑的是以下内容:

  • How am I supposed to use this with my server? 我该如何在服务器上使用它?

For example , I built a simple NodeJS application that uses Passport and a few other modules to create a login/registration system (with MongoDB) . 例如 ,我构建了一个简单的NodeJS应用程序,它使用Passport和一些其他模块来创建登录/注册系统(使用MongoDB) It has HTML files for logging in and registering. 它具有用于登录和注册的HTML文件。

I am not sure how to use this with my Electron app, as the matter of fact, I don't quite understand how to actually use Electron. 我不知道如何在我的Electron应用程序中使用它,事实上,我不太明白如何实际使用Electron。 Should I move all of my login/register application code to the Electron application, or should I use Electron to somehow connect to my login/registration application and load the websites? 我应该将所有登录/注册应用程序代码移动到Electron应用程序,还是应该使用Electron以某种方式连接到我的登录/注册应用程序并加载网站?

  • If I were to move my code to my Electron app, would it cause security issues? 如果我要将我的代码移到我的Electron应用程序中,是否会导致安全问题?

How am I supposed to use this with my server? 我该如何在服务器上使用它?

You need to think about separating the application as a stand-alone desktop app (that acts as a client-side application) vs the server for your API and backend logic which are hosted by a cloud provider. 您需要考虑将应用程序分离为独立的桌面应用程序(充当客户端应用程序)与由云提供程序托管的API和后端逻辑的服务器。

By doing this, you can focus on the separation of concerns for the desktop (electron) application as well as ensuring servers (such as API, authentication, and other backend logic) are well optimised and serving as multiple workers of themselves. 通过这样做,您可以专注于桌面(电子)应用程序的关注点分离,并确保服务器(如API,身份验证和其他后端逻辑)得到很好的优化,并充当自己的多个工作者。

If I were to move my code to my Electron app, would it cause security issues? 如果我要将我的代码移到我的Electron应用程序中,是否会导致安全问题?

There are some security concerns with an Electron application development if you do not regularly update your Node version (such as memory buffer overflow attacks). 如果您不定期更新Node版本(例如内存缓冲区溢出攻击),则Electron应用程序开发存在一些安全问题。

Another issue to consider is how the Electron community serves and resolves issues of permissions for the client-side app and the regular file permissions which are granted when the user installs your app. 另一个需要考虑的问题是Electron社区如何服务并解决客户端应用程序的权限问题以及用户安装应用程序时授予的常规文件权限。

As a developer, the onus is on you to ensure third-party libraries are not damaging the user's computer. 作为开发人员,您有责任确保第三方库不会损坏用户的计算机。 (imagine installing a library dependency whose purpose is to maliciously delete the entire file system). (想象一下安装一个库依赖项,其目的是恶意删除整个文件系统)。

I built a simple NodeJS application that uses Passport and a few other modules to create a login/registration system 我构建了一个简单的NodeJS应用程序,它使用Passport和一些其他模块来创建登录/注册系统

For authentication, you can serve responses from your API based on the client-side requests/Posts that you provide to the authentication service. 对于身份验证,您可以根据您提供给身份验证服务的客户端请求/帖子来提供API响应。 You don't necessarily have to provide/install the authentication server into your Electron app, as this can be somewhat troublesome for the user to update, as well as it exposes your authentication service for others to reverse-engineer/crack. 您不一定必须在您的Electron应用程序中提供/安装认证服务器,因为这对于用户更新来说有点麻烦,并且它会使您的身份验证服务暴露给其他人以进行逆向工程/破解。

You can simply start your Electron Journey with Basic app which allows you to play with it. 你可以简单地用Basic应用程序启动你的Electron Journey,它可以让你玩它。

Best part about electron is - You can run it anywhere (Mac, Windows & Linux) 关于电子的最佳部分是 - 你可以在任何地方运行它(Mac,Windows和Linux)

Do a checkout 结帐

git clone https://github.com/geek4teck/electron-quick-start git clone https://github.com/geek4teck/electron-quick-start

Change your Current Working Directory to electron-quick-start 将您当前的工作目录更改为电子快速启动

cd electron-quick-start cd电子快速启动

You can then run 然后你就可以跑了

npm install npm安装

(Make sure nodejs is installed) (确保已安装nodejs)

You can then run 然后你就可以跑了

npm start npm开始

which should start a basic browserwindow and should show your current node, npm version etc. 应该启动一个基本的浏览器窗口,并显示您当前的节点,npm版本等。

Hope this helps 希望这可以帮助

certainly the best Tutorial I've seen for electronjs is The Electron API Demos app which is the official tutorial from electron and completely FREE :) 当然,我见过的关于electronjs的最好的教程是电子API演示应用程序 ,这是电子的官方教程 ,完全免费:)

just download the main tutorial application which is named "ElectronAPIDemosSetup.exe" from GitHub (of course you can download "Electron API Demos-win32-ia32" and "electron-api-demos-2.0.2" to view and play with source codes) then run it and enjoy... 只需从GitHub下载名为“ElectronAPIDemosSetup.exe”的主教程应用程序(当然您可以下载“Electron API Demos-win32-ia32”和“electron-api-demos-2.0.2”来查看和播放源代码)然后运行它并享受...

just as an additional hint I attached a screenshot from application here: 作为一个额外的提示,我在这里附上了应用程序的截图:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM