feat: add auto update for electron app

This commit is contained in:
qier222 2020-11-23 18:07:03 +08:00
parent 7d32e8f3bf
commit 86f89239e6

View File

@ -1,5 +1,5 @@
"use strict";
import { app, protocol, BrowserWindow, globalShortcut } from "electron";
import { app, protocol, BrowserWindow } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
import { startNeteaseMusicApi } from "./electron/services";
@ -8,7 +8,7 @@ import { createMenu } from "./electron/menu";
import { createTouchBar } from "./electron/touchBar";
import { createDockMenu } from "./electron/dockMenu";
import { createTray } from "./electron/tray.js";
// import { autoUpdater } from "electron-updater"
import { autoUpdater } from "electron-updater";
const isDevelopment = process.env.NODE_ENV !== "production";
@ -19,6 +19,9 @@ let win;
// ipcMain
initIpcMain(win);
// check for update
autoUpdater.checkForUpdatesAndNotify();
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
@ -80,7 +83,7 @@ app.on("ready", async () => {
// start netease music api
startNeteaseMusicApi();
// Install Vue Devtools xtension
// Install Vue Devtools extension
if (isDevelopment && !process.env.IS_TEST) {
try {
await installExtension(VUEJS_DEVTOOLS);
@ -89,11 +92,6 @@ app.on("ready", async () => {
}
}
// Register shortcut for debug
globalShortcut.register("CommandOrControl+K", function () {
win.webContents.openDevTools();
});
// create window
createWindow();
win.once("ready-to-show", () => {
@ -108,27 +106,8 @@ app.on("ready", async () => {
// create touchbar
win.setTouchBar(createTouchBar(win));
// autoUpdater.checkForUpdatesAndNotify()
});
// autoUpdater.on("checking-for-update", () => {});
// autoUpdater.on("update-available", info => {
// console.log(info);
// dialog.showMessageBox({
// title: "新版本发布",
// message: "有新内容更新,稍后将重新为您安装",
// buttons: ["确定"],
// type: "info",
// noLink: true
// });
// });
// autoUpdater.on("update-downloaded", info => {
// console.log(info);
// autoUpdater.quitAndInstall();
// });
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === "win32") {