Skip to content

Commit

Permalink
✨ feat: 支持配置自动更新开关 #148
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Mar 21, 2024
1 parent d46c4c4 commit 428ce4b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 0 additions & 3 deletions electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -161,8 +160,6 @@ class MainProcess {
app.whenReady().then(async () => {
// 创建主窗口
this.createWindow();
// 检测更新
configureAutoUpdater();
// 引入主 Ipc
mainIpcMain(this.mainWindow);
// 系统托盘
Expand Down
5 changes: 5 additions & 0 deletions electron/main/mainIpcMain.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -41,6 +42,10 @@ const mainIpcMain = (win) => {
app.relaunch();
app.quit();
});
ipcMain.on("check-updates", () => {
console.info("开始检查更新");
configureAutoUpdater();
});

// 显示进度
ipcMain.on("setProgressBar", (_, val) => {
Expand Down
10 changes: 9 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// 公告数据
Expand Down Expand Up @@ -145,6 +145,12 @@ if ("serviceWorker" in navigator) {
});
}
// 自动检查更新
const checkUpdates = () => {
if (!checkPlatform.electron()) return false;
electron.ipcRenderer.send("check-updates");
};
// 显示公告
const showAnnouncements = () => {
if (annShow) {
Expand Down Expand Up @@ -192,6 +198,8 @@ onMounted(async () => {
}
// 自动签到
if (autoSignIn.value) await userSignIn();
// 检查更新
if (autoCheckUpdates.value) checkUpdates();
// 显示公告
showAnnouncements();
});
Expand Down
1 change: 1 addition & 0 deletions src/stores/siteSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const useSiteSettingsStore = defineStore("siteSettings", {
showGithub: true,
showSider: true, // 显示侧边栏
siderShowCover: false, // 侧边栏显示封面
autoCheckUpdates: true, // 自动检查更新
// 主题部分
themeType: "dark",
themeAuto: false,
Expand Down
8 changes: 8 additions & 0 deletions src/views/Setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@
@update:value="closeTaskbarProgress"
/>
</n-card>
<n-card class="set-item">
<div class="name">
自动检查更新
<n-text class="tip">在开启软件时自动检查更新</n-text>
</div>
<n-switch v-model:value="autoCheckUpdates" :round="false" />
</n-card>
</div>
<div v-else class="set-type">
<n-h3 prefix="bar"> 系统 </n-h3>
Expand Down Expand Up @@ -629,6 +636,7 @@ const {
downloadMeta,
downloadCover,
downloadLyrics,
autoCheckUpdates,
} = storeToRefs(settings);

// 标签页数据
Expand Down

0 comments on commit 428ce4b

Please sign in to comment.