From b7f51f02c2456d01b249e82a6186d6cc212d150c Mon Sep 17 00:00:00 2001 From: qier222 Date: Fri, 4 Dec 2020 18:46:35 +0800 Subject: [PATCH] fix(electron): auto update --- package.json | 2 +- src/background.js | 33 +++++++++++++++++++++++++++++---- vue.config.js | 2 -- yarn.lock | 8 ++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4186308..1629c89 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "electron-devtools-installer": "^3.1.1", "electron-icon-builder": "^1.0.2", "electron-is-dev": "^1.2.0", - "electron-log": "^4.2.4", + "electron-log": "^4.3.0", "electron-updater": "^4.3.5", "express": "^4.17.1", "express-fileupload": "^1.2.0", diff --git a/src/background.js b/src/background.js index 2cfa7c5..d2326e9 100644 --- a/src/background.js +++ b/src/background.js @@ -1,5 +1,5 @@ "use strict"; -import { app, protocol, BrowserWindow, shell } from "electron"; +import { app, protocol, BrowserWindow, shell, dialog } from "electron"; import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer"; import { startNeteaseMusicApi } from "./electron/services"; @@ -20,9 +20,6 @@ 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 } }, @@ -91,6 +88,34 @@ app.on("ready", async () => { // start netease music api startNeteaseMusicApi(); + // check for update + const log = require("electron-log"); + log.transports.file.level = "debug"; + autoUpdater.logger = log; + autoUpdater.checkForUpdatesAndNotify(); + + if (process.platform === "darwin") { + autoUpdater.on("update-available", (info) => { + log.debug(info); + dialog + .showMessageBox({ + title: "发现新版本 v" + info.version, + message: "发现新版本 v" + info.version, + detail: "是否前往 Github 下载新版本安装包?", + buttons: ["下载", "取消"], + type: "question", + noLink: true, + }) + .then((result) => { + if (result.response === 0) { + shell.openExternal( + "https://github.com/qier222/YesPlayMusic/releases" + ); + } + }); + }); + } + // Install Vue Devtools extension if (isDevelopment && !process.env.IS_TEST) { try { diff --git a/vue.config.js b/vue.config.js index 1f5b623..ddb3366 100644 --- a/vue.config.js +++ b/vue.config.js @@ -61,7 +61,6 @@ module.exports = { owner: "qier222", repo: "YesPlayMusic", vPrefixedTagName: true, - private: true, releaseType: "draft", }, ], @@ -70,7 +69,6 @@ module.exports = { }, mac: { category: "public.app-category.music", - target: "dmg", darkModeSupport: true, }, win: { diff --git a/yarn.lock b/yarn.lock index 8da41d4..5aed028 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4379,10 +4379,10 @@ electron-localshortcut@^3.1.0: keyboardevent-from-electron-accelerator "^2.0.0" keyboardevents-areequal "^0.2.1" -electron-log@^4.2.4: - version "4.2.4" - resolved "https://registry.npm.taobao.org/electron-log/download/electron-log-4.2.4.tgz#a13e42a9fc42ca2cc7d2603c3746352efa82112e" - integrity sha1-oT5CqfxCyizH0mA8N0Y1LvqCES4= +electron-log@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.0.tgz#6e841a5c9af34ed3ca83e5a8a4156fdc39bed464" + integrity sha512-iuJjH/ZEJkDyCbuAMvvFxAjCMDLMXIQ5NqvppETGrbtf4b/007r5P36BSvexdy0UzwDNzDtIuEXLR34vRXWZrg== electron-publish@22.9.1: version "22.9.1"