×

Electron 教程

Electron 教程简介Electron 快速入门Electron 桌面环境集成Electron 在线/离线事件探测Electron 进程支持的 Chrome 命令行开关Electron 环境变量Electron 支持的平台Electron 应用部署Mac App Store 应用提交向导Electron 应用打包Electron 使用原生模块Electron 主进程调试使用 Selenium 和 WebDriverElectron DevTools扩展使用 Pepper Flash 插件使用 Widevine CDM 插件Electron 术语表Electron 离屏渲染Electron 交互式解释器 (REPL)Electron 自动更新功能autoUpdater

Electron API

Electron DOM File对象Electron DOM <webview>Electron window.open 函数

在主进程内可用的模块

Electron app 模块Electron autoUpdater 模块Electron BrowserWindow 模块Electron contentTracing 模块Electron dialog 模块Electron global-shortcut 模块Electron ipcMain 模块Electron menu 模块Electron MenuItem 模块Electron powerMonitor 模块Electron powerSaveBlockerElectron protocol 模块Electron session 模块Electron webContents 模块Electron Tray 模块Electron Locales

在渲染进程(网页)可用模块

Electron desktopCapturer模块Electron ipcRenderer 模块Electron remote 模块Electron webFrame 模块

两种进程都可用的模块

Electron clipboard 模块Electron crashReporter 模块Electron nativeImage 模块Electron screen 模块Electron shell 模块

Electron 开发

Electron 编码规范Electron 源码目录结构Electron 和 NW.js技术上的差异Electron 构建系统概览Electron 构建步骤 (OS X)Electron 构建步骤 (Windows)Electron 构建步骤 (Linux)调试中使用 Symbol ServerElectron 常见问题Electron 版本管理electron window 提交指南自动化持续集成系统(CI)测试Electron 文档风格指南

Electron 教程简介


所有的Node.js's built-in modules在Electron中都可用,并且所有的node的第三方组件也可以放心使用(包括自身的模块)。

Electron也提供了一些额外的内置组件来开发传统桌面应用。一些组件只可以在主进程中使用,一些只可以在渲染进程中使用,但是也有部分可以在这2种进程中都可使用。

基本规则:GUI模块或者系统底层的模块只可以在主进程中使用。要使用这些模块,你应当很熟悉主进程vs渲染进程脚本的概念。

主进程脚本看起来像个普通的nodejs脚本

const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

var window = null;

app.on('ready', function() {
  window = new BrowserWindow({width: 800, height: 600});
  window.loadURL('https://www.bootwiki.com');
});

渲染进程和传统的web界面一样,除了它具有使用node模块的能力:


<html>
<body>
<script>
  const remote = require('electron').remote;
  console.log(remote.app.getVersion());
script>
body>
html>

如果想运行应用,参考 Run your app

解构任务

如果你使用的是CoffeeScript或Babel,你可以使用destructuring assignment来让使用内置模块更简单:

const {app, BrowserWindow} = require('electron');

然而如果你使用的是普通的JavaScript,你就需要等到Chrome支持ES6了。

使用内置模块时禁用旧样式

在版本v0.35.0之前,所有的内置模块都需要按造 require('module-name') 形式来使用,虽然它有很多弊端,我们仍然在老的应用中友好的支持它。

为了完整的禁用旧样式,你可以设置环境变量 ELECTRON_HIDE_INTERNAL_MODULES :

process.env.ELECTRON_HIDE_INTERNAL_MODULES = 'true'

或者调用 hideInternalModules API:

require('electron').hideInternalModules()

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)