diff --git a/electron/main/index.js b/electron/main/index.js index 55a85431..60157ea3 100644 --- a/electron/main/index.js +++ b/electron/main/index.js @@ -3,7 +3,6 @@ import { app, protocol, shell, BrowserWindow, globalShortcut, nativeImage } from import { platform, optimizer, is } from "@electron-toolkit/utils"; import { startNcmServer } from "@main/startNcmServer"; import { startMainServer } from "@main/startMainServer"; -import { configureAutoUpdater } from "@main/utils/checkUpdates"; import createSystemTray from "@main/utils/createSystemTray"; import createGlobalShortcut from "@main/utils/createGlobalShortcut"; import mainIpcMain from "@main/mainIpcMain"; @@ -161,8 +160,6 @@ class MainProcess { app.whenReady().then(async () => { // 创建主窗口 this.createWindow(); - // 检测更新 - configureAutoUpdater(); // 引入主 Ipc mainIpcMain(this.mainWindow); // 系统托盘 diff --git a/electron/main/mainIpcMain.js b/electron/main/mainIpcMain.js index d3a3e164..c0421716 100644 --- a/electron/main/mainIpcMain.js +++ b/electron/main/mainIpcMain.js @@ -1,5 +1,6 @@ import { ipcMain, dialog, app, clipboard, shell } from "electron"; import { File, Picture, Id3v2Settings } from "node-taglib-sharp"; +import { configureAutoUpdater } from "@main/utils/checkUpdates"; import { readDirAsync } from "@main/utils/readDirAsync"; import { parseFile } from "music-metadata"; import { download } from "electron-dl"; @@ -41,6 +42,10 @@ const mainIpcMain = (win) => { app.relaunch(); app.quit(); }); + ipcMain.on("check-updates", () => { + console.info("开始检查更新"); + configureAutoUpdater(); + }); // 显示进度 ipcMain.on("setProgressBar", (_, val) => { diff --git a/src/App.vue b/src/App.vue index 23bfeab9..d6eb7ee4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -93,7 +93,7 @@ const router = useRouter(); const music = musicData(); const status = siteStatus(); const settings = siteSettings(); -const { autoPlay, showSider, autoSignIn } = storeToRefs(settings); +const { autoPlay, showSider, autoSignIn, autoCheckUpdates } = storeToRefs(settings); const { showPlayBar, asideMenuCollapsed, showFullPlayer } = storeToRefs(status); // 公告数据 @@ -145,6 +145,12 @@ if ("serviceWorker" in navigator) { }); } +// 自动检查更新 +const checkUpdates = () => { + if (!checkPlatform.electron()) return false; + electron.ipcRenderer.send("check-updates"); +}; + // 显示公告 const showAnnouncements = () => { if (annShow) { @@ -192,6 +198,8 @@ onMounted(async () => { } // 自动签到 if (autoSignIn.value) await userSignIn(); + // 检查更新 + if (autoCheckUpdates.value) checkUpdates(); // 显示公告 showAnnouncements(); }); diff --git a/src/stores/siteSettings.js b/src/stores/siteSettings.js index 3e7b2e8e..70a0da74 100644 --- a/src/stores/siteSettings.js +++ b/src/stores/siteSettings.js @@ -13,6 +13,7 @@ const useSiteSettingsStore = defineStore("siteSettings", { showGithub: true, showSider: true, // 显示侧边栏 siderShowCover: false, // 侧边栏显示封面 + autoCheckUpdates: true, // 自动检查更新 // 主题部分 themeType: "dark", themeAuto: false, diff --git a/src/views/Setting/index.vue b/src/views/Setting/index.vue index 37d123dd..707c8bae 100644 --- a/src/views/Setting/index.vue +++ b/src/views/Setting/index.vue @@ -193,6 +193,13 @@ @update:value="closeTaskbarProgress" /> + +
+ 自动检查更新 + 在开启软件时自动检查更新 +
+ +
系统 @@ -629,6 +636,7 @@ const { downloadMeta, downloadCover, downloadLyrics, + autoCheckUpdates, } = storeToRefs(settings); // 标签页数据