|
@@ -1,65 +1,15 @@
|
|
|
'use strict'
|
|
|
|
|
|
-import { app, protocol, BrowserWindow, Menu,ipcMain } from 'electron'
|
|
|
+import { app, protocol, BrowserWindow, Menu, ipcMain } from 'electron'
|
|
|
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
|
|
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
|
|
|
const path = require('path')
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
|
|
// 注意这个autoUpdater不是electron中的autoUpdater
|
|
|
import { autoUpdater } from "electron-updater"
|
|
|
-// 更新服务器地址,比如"http://**.**.**.**:3002/download/"
|
|
|
import config from "../vue.config";
|
|
|
-let uploadUrl = config.pluginOptions.electronBuilder.builderOptions.publish[0].url
|
|
|
-// 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写
|
|
|
-function updateHandle(mainWindow) {
|
|
|
- let message = {
|
|
|
- error: '检查更新出错',
|
|
|
- checking: '正在检查更新……',
|
|
|
- updateAva: '检测到新版本,正在下载……',
|
|
|
- updateNotAva: '现在使用的就是最新版本,不用更新',
|
|
|
- };
|
|
|
- const os = require('os');
|
|
|
-
|
|
|
- autoUpdater.setFeedURL(uploadUrl);
|
|
|
- autoUpdater.on('error', function (error) {
|
|
|
- sendUpdateMessage(message.error)
|
|
|
- });
|
|
|
- autoUpdater.on('checking-for-update', function () {
|
|
|
- sendUpdateMessage(message.checking)
|
|
|
- });
|
|
|
- autoUpdater.on('update-available', function (info) {
|
|
|
- sendUpdateMessage(message.updateAva)
|
|
|
- });
|
|
|
- autoUpdater.on('update-not-available', function (info) {
|
|
|
- sendUpdateMessage(message.updateNotAva)
|
|
|
- });
|
|
|
-
|
|
|
- // 更新下载进度事件
|
|
|
- autoUpdater.on('download-progress', function (progressObj) {
|
|
|
- mainWindow.webContents.send('downloadProgress', progressObj)
|
|
|
- })
|
|
|
- autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
|
|
- ipcMain.on('isUpdateNow', (e, arg) => {
|
|
|
- console.log(arguments);
|
|
|
- console.log("开始更新");
|
|
|
- //some code here to handle event
|
|
|
- autoUpdater.quitAndInstall();
|
|
|
- });
|
|
|
-
|
|
|
- mainWindow.webContents.send('isUpdateNow')
|
|
|
- });
|
|
|
-
|
|
|
- ipcMain.on("checkForUpdate", () => {
|
|
|
- //执行自动更新检查
|
|
|
- autoUpdater.checkForUpdates();
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-// 通过main进程发送事件给renderer进程,提示更新信息
|
|
|
-function sendUpdateMessage(text) {
|
|
|
- mainWindow.webContents.send('message', text)
|
|
|
-}
|
|
|
-
|
|
|
+let uploadUrl = config.pluginOptions.electronBuilder.builderOptions.publish[0].url;
|
|
|
+let win;
|
|
|
// Scheme must be registered before the app is ready
|
|
|
protocol.registerSchemesAsPrivileged([
|
|
|
{ scheme: 'app', privileges: { secure: true, standard: true } }
|
|
@@ -67,9 +17,9 @@ protocol.registerSchemesAsPrivileged([
|
|
|
|
|
|
async function createWindow() {
|
|
|
// 隐藏菜单栏
|
|
|
- Menu.setApplicationMenu(null)
|
|
|
+ // Menu.setApplicationMenu(null)
|
|
|
// Create the browser window.
|
|
|
- const win = new BrowserWindow({
|
|
|
+ win = new BrowserWindow({
|
|
|
width: 1200,
|
|
|
height: 800,
|
|
|
title: '猎豹AI聚合配送',
|
|
@@ -83,7 +33,8 @@ async function createWindow() {
|
|
|
}
|
|
|
})
|
|
|
// 检查更新
|
|
|
- updateHandle(win)
|
|
|
+ updateHandle();
|
|
|
+ win.webContents.openDevTools()
|
|
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
|
|
// Load the url of the dev server if in development mode
|
|
|
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
|
|
@@ -93,6 +44,12 @@ async function createWindow() {
|
|
|
// Load the index.html when not in development
|
|
|
win.loadURL('app://./index.html')
|
|
|
}
|
|
|
+ // // 32位 64位
|
|
|
+ // if (process.arch === 'x64') {
|
|
|
+ // uploadUrl = uploadUrl + 'dist_electron';
|
|
|
+ // } else {
|
|
|
+ // uploadUrl = uploadUrl + 'dist_electron32';
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// Quit when all windows are closed.
|
|
@@ -139,3 +96,52 @@ if (isDevelopment) {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写
|
|
|
+function updateHandle() {
|
|
|
+ let message = {
|
|
|
+ error: '检查更新出错',
|
|
|
+ checking: '正在检查更新……',
|
|
|
+ updateAva: '检测到新版本,正在下载……',
|
|
|
+ updateNotAva: '现在使用的就是最新版本,不用更新',
|
|
|
+ };
|
|
|
+ autoUpdater.setFeedURL(uploadUrl);
|
|
|
+ autoUpdater.autoDownload = false;
|
|
|
+ autoUpdater.on('error', function (error) {
|
|
|
+ sendUpdateMessage(message.error)
|
|
|
+ });
|
|
|
+ autoUpdater.on('checking-for-update', function () {
|
|
|
+ sendUpdateMessage(message.checking)
|
|
|
+ });
|
|
|
+ autoUpdater.on('update-available', function (info) {
|
|
|
+ sendUpdateMessage(message.updateAva)
|
|
|
+ });
|
|
|
+ autoUpdater.on('update-not-available', function (info) {
|
|
|
+ sendUpdateMessage(message.updateNotAva)
|
|
|
+ });
|
|
|
+
|
|
|
+ // 更新下载进度事件
|
|
|
+ autoUpdater.on('download-progress', function (progressObj) {
|
|
|
+ win.webContents.send('downloadProgress', progressObj)
|
|
|
+ })
|
|
|
+ autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
|
|
+ ipcMain.on('isUpdateNow', (e, arg) => {
|
|
|
+ console.log("开始更新");
|
|
|
+ console.log(arguments);
|
|
|
+ //some code here to handle event
|
|
|
+ autoUpdater.quitAndInstall();
|
|
|
+ });
|
|
|
+
|
|
|
+ win.webContents.send('isUpdateNow')
|
|
|
+ });
|
|
|
+
|
|
|
+ ipcMain.on("checkForUpdate", () => {
|
|
|
+ //执行自动更新检查
|
|
|
+ autoUpdater.checkForUpdates();
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 通过main进程发送事件给renderer进程,提示更新信息
|
|
|
+function sendUpdateMessage(text) {
|
|
|
+ win.webContents.send('message', text)
|
|
|
+}
|