Electron学习笔记:quickstart, 结合Editor.md

一个小任务

在electron中加入Editor.md,让它看起来像一个真的小型本地编辑器。

quick_start_sample的核心代码分析

首先两个概念:
main process : main.js
render process: nameOfPage.html

render process 中的关键部分:

  <script>
    // You can also require other files to run in this process
    require('./renderer.js')
  </script>

renderer.js中的注释:

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

main.js

组件部分:

const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

事件监听:

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', createWindow) 

// Quit when all windows are closed.
app.on('window-all-closed',...
// 处理多次点击桌面图标
app.on('activate', ..

创建初始窗口:

function createWindow () {
  // Create the browser window. 用JSON对象设置大小
  mainWindow = new BrowserWindow({width: 800, height: 600})

  // 用.loadURL加载HTML文件
  // 用键'pathname'指定文件路径
  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true
  }))

  // Open the DevTools.
  // 暂不知道有什么用
 mainWindow.webContents.openDevTools()

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // 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.
    mainWindow = null
  })
}

Editor.md 简单样例代码分析

\editor.md-master\examples\simple.html

为样例。

Making

重新clone quick-start的时候又出现了安装时的一堆bug,还没发现什么原因,装了electron-download也不行,最后复制上次的node_modules文件夹就好了囧。可能是缺了什么文件?

链接好了文件却在editormd.min.js里提示

Zepto is not defined

html里似乎也没法使用jQuery。Google一下

electron zepto is not defined

SO上给出了完美解答:electron-jquery-is-not-defined

<!-- Insert this line above script imports  -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>

<!-- normal script imports etc  -->
<script src="scripts/jquery.min.js"></script>    
<script src="scripts/vendor.js"></script>    

<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>

这样子写代码就ok了!

然后还有一些小问题,主要是editor.md的依赖没有放好,就是lib文件夹。
创建editor时JSON对象中键值path设定为lib文件夹,lib下控制了工具栏图标的显示。

进阶任务1:增加“保存到本地”的功能

【未完成】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值