安装NodeJS

目前支持的最新版本为NodeJS 7.4.0,因为安装过程比较简单所以这里省略了。

安装Electron

npm install -g electron

创建项目工程

使用WebStorm创建一个Empty Project.

用npm init初始化这个项目。初始化后,package.json内容如下

{"name": "facerecognition_test","version": "1.0.0","description": "","main": "main.js","scripts": {"start": "electron .","pack": "electron-packager --electron-version=16.11 .","build": "build "},"author": "Chen Haifeng","license": "ISC"
}

添加文件index.html

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>人脸识别测试程序</title>
</head>
<body>
<button id="CAMOpen" name="CAMOpen">调用人脸识别DLL</button>
</body>
</html>

添加文件main.js

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
//import url from "url"// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let winfunction createWindow () {console.log('createWindow')// Create the browser window.win = new BrowserWindow({width: 800, height: 600})// and load the index.html of the app.win.loadURL(url.format({pathname: path.join(__dirname, 'index.html'),protocol: 'file:',slashes: true}))// Open the DevTools.win.webContents.openDevTools()// Emitted when the window is closed.win.on('closed', () => {// Dereference the window object, usually you would store windows// in an array if your app supports multi windows, this is the time// when you should delete the corresponding element.win = null})
}// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)// Quit when all windows are closed.
app.on('window-all-closed', () => {// On macOS it is common for applications and their menu bar// to stay active until the user quits explicitly with Cmd + Qif (process.platform !== 'darwin') {app.quit()}
})app.on('activate', () => {// On macOS it's common to re-create a window in the app when the// dock icon is clicked and there are no other windows open.if (win === null) {console.log('activate')createWindow()}
})// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

测试项目

如果electron是采用全局安装的,使用electron .来运行项目。

如果electron是安装在项目的node_modules目录,使用.\node_modules\.bin\electron .来运行项目。

因为在package.json文件中做了配置,所以这里可以使用npm start运行项目。

打包项目

安装electron-packager

npm install -g electron-packager

electron-packager --electron-version=1.6.11 .

生成结果如下

运行一下打包后的exe程序

制作平台安装包

npm install -g electron-builder

执行命令build, 整个过程比较漫长。

自动更新下次补充。

electron开发相关推荐

  1. electron 开发环境搭建

    electron开发环境的搭建共包括两个部分:一.动态链接库(dll)编译部分:二.Native模块编译部分 tips:cnpm和npm的依赖可能不同,npm安装时可以通过任务管理器查看网速 ``` ...

  2. JS是世界上最好的语言—— 使用Electron开发桌面应用(一)

    Electron 可以让你使用纯 JavaScript 调用丰富的原生(操作系统) APIs 来创造桌面应用. 你可以把它看作一个专注于桌面应用的 Node. js 的变体,而不是 Web 服务器. ...

  3. 如何搭建Electron开发环境

    原文发表于 https://lleohao.github.io/2017/09/02/如何搭建Electron开发环境/ 这个项目结构是我在编写 基于Electron 和 Angular 的七牛文件上 ...

  4. 送你一份用Electron开发桌面应用的避坑指南【送3本书,含犀牛书】

    大家好,我是若川.持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,新年第一次送3本书.抽奖规则见文末. 如今,Electron 领域发生了重大的变革,Electro ...

  5. 入坑 Electron 开发跨平台桌面应用

    ‍ 作为一个跨平台的桌面应用开发框架,Electron 的迷人之处在于,它是建立在 Chromium 和 Node.js 之上的 -- 二位分工明确,一个负责界面,一个负责背后的逻辑,典型的「你负责貌 ...

  6. Vue 全家桶 + Electron 开发的一个跨三端的应用 1

    代码地址如下: http://www.demodashi.com/demo/11738.html GitHub Repo:vue-objccn Follow: halfrost · GitHub 利用 ...

  7. 2020-11-05 转载 国内配置Electron开发环境的正确方式

    原作者: 国内配置Electron开发环境的正确方式 https://blog.yasking.org/a/zh-install-electron-development-2020.html http ...

  8. Electron开发桌面应用

    由 Bazzzinga威 同学翻译自 Medium.https://medium.com/developers-writing/building-a-desktop-application-with- ...

  9. 使用 Vue 和 Electron 开发一款简单的 Markdown 编辑器

    2021SC@SDUSC 本文并不涉及自己设计一套 Markdown 渲染组件的部分,Markdown 渲染组件可通过 marked 和 highlight.js 自行实现.但本文重点在于如何使用 E ...

  10. 用Electron开发的Windows快捷启动工具:Dawn Launcher

    一开始是自己有这个需求,感觉桌面东西多了之后杂乱无章,就算分好类,还是需要进入某个文件夹找也是很麻烦,有的时候想打开某个软件或者某个文件的时候,可能要卡住一下,不能马上找到我想找目标,然后突然想起来N ...

最新文章

  1. jvm性能调优实战 - 27亿级数据量的实时分析引擎,为啥频繁发生Full GC
  2. java概述、安装、配置环境、运行
  3. HTML5 Web SQL
  4. 【软考-软件设计师】程序设计的基本成分
  5. jsp文件上传_文件上传
  6. 未声明spire。它可能因保护级别而不可访问_信息系统安全:访问控制技术概述...
  7. 第一个JavaWeb项目——教室预约系统
  8. 详细介绍Linux shell脚本基础学习(一)
  9. 当前读和快照读是什么 区别
  10. 共享充电宝APP小程序开发解决方案
  11. 给zabbix更换nagios图标
  12. 日期格式 Wed Oct 16 00:00:00 CEST 2020 转换
  13. 常见信息安全威胁与经典案例
  14. QT 按钮保持按下时样式
  15. 咸鱼软件应用—Cura3D切片
  16. 首师大附中互测题:LJX的校园:入学典礼【C003】
  17. echarts 柱状图如何不顶格_echarts图表的使用经验总结(避免踩坑)
  18. Win10显示器驱动程序无法启动
  19. vue使用element-ui开发的后台管理系统使用中英文切换多语言国际化方案步骤流程
  20. 在JSP页面中获取JavaScript中var变量的值

热门文章

  1. NSIS打包软件(一)
  2. 关于程序中查询效率的问题
  3. 几大搜索引擎的网站登录入口
  4. 用oracle的ODP.NET创建实体数据模型
  5. linux没有jre文件夹,linux上配置jdk时,java命令提示没有此文件或文件夹的解决方法...
  6. 动态规划算法-07背包问题进阶
  7. Windows系统CUDA10.2+CUDNN安装教程
  8. HDU4006(The kth great number)
  9. [loj556][Antileaf's Round]咱们去烧菜吧
  10. SSDT表的遍历(源码)