| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 'use strict'
- /**
- *
- *
- * @author EllisRan.
- * @date 2018/6/4
- * @version
- */
- const electron = require('electron')
- const ipcMain = electron.ipcMain
- const autoUpdater = require('electron-updater').autoUpdater
- const uploadUrl = 'http://d2.smartcost.com.cn/startup/'
- exports.initialize = function (win) {
- // let message = {
- // error: '检查更新出错 1',
- // checking: '正在检查更新…… 2',
- // updateAva: '检测到新版本,正在下载…… 3',
- // updateNotAva: '现在使用的就是最新版本,不用更新 4'
- // }
- autoUpdater.setFeedURL(uploadUrl)
- autoUpdater.autoDownload = false
- autoUpdater.on('error', function () {
- // sendUpdateMessage(win, message.error)
- })
- autoUpdater.on('checking-for-update', function () {
- // sendUpdateMessage(win, message.checking)
- })
- autoUpdater.on('update-available', function (info) {
- sendUpdateMessage(win, 2)
- })
- autoUpdater.on('update-not-available', function (info) {
- // sendUpdateMessage(win, message.updateNotAva)
- })
- // 更新下载进度事件
- autoUpdater.on('download-progress', function (progressObj) {
- win.webContents.send('downloadProgress', progressObj)
- win.setProgressBar(progressObj.percent / 100)
- // console.log(progressObj)
- })
- autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
- ipcMain.on('isUpdateNow', (e, arg) => {
- // some code here to handle event
- autoUpdater.quitAndInstall()
- })
- win.webContents.send('isUpdateNow')
- })
- ipcMain.on('checkForUpdate', () => {
- // 执行自动更新检查
- autoUpdater.checkForUpdates()
- })
- }
- ipcMain.on('downloadUpdate', () => {
- autoUpdater.downloadUpdate()
- })
- // 通过main进程发送事件给renderer进程,提示更新信息
- function sendUpdateMessage (win, status = 0) {
- win.webContents.send('msgBox', status)
- }
|