Skip to content

Commit d471e68

Browse files
committed
fix: 完善更新流程
1 parent 41c4342 commit d471e68

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

electron/main/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class MainProcess {
9696
// mainWindow.maximize();
9797
});
9898

99+
// 主窗口事件
100+
this.mainWindowEvents();
101+
99102
// 设置窗口打开处理程序
100103
this.mainWindow.webContents.setWindowOpenHandler((details) => {
101104
shell.openExternal(details.url);
@@ -153,14 +156,31 @@ class MainProcess {
153156
// 注销全部快捷键
154157
globalShortcut.unregisterAll();
155158
});
156-
157159
// 当所有窗口都关闭时退出应用,macOS 除外
158160
app.on("window-all-closed", () => {
159161
if (process.platform !== "darwin") {
160162
app.quit();
161163
}
162164
});
163165
}
166+
167+
// 主窗口事件
168+
mainWindowEvents() {
169+
this.mainWindow.on("show", () => {
170+
console.info("窗口展示");
171+
this.mainWindow.webContents.send("lyricsScroll");
172+
});
173+
// this.mainWindow.on("hide", () => {
174+
// console.info("窗口隐藏");
175+
// });
176+
this.mainWindow.on("focus", () => {
177+
console.info("窗口获得焦点");
178+
this.mainWindow.webContents.send("lyricsScroll");
179+
});
180+
// this.mainWindow.on("blur", () => {
181+
// console.info("窗口失去焦点");
182+
// });
183+
}
164184
}
165185

166186
new MainProcess();

electron/main/utils/checkUpdates.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
const { autoUpdater } = require("electron-updater");
1+
import { dialog, shell } from "electron";
2+
import { is } from "@electron-toolkit/utils";
3+
import { autoUpdater } from "electron-updater";
24

3-
const checkForUpdates = () => {
4-
autoUpdater.checkForUpdates();
5+
// 更新弹窗
6+
const hasNewVersion = (info) => {
7+
dialog
8+
.showMessageBox({
9+
title: "发现新版本 v" + info.version,
10+
message: "发现新版本 v" + info.version,
11+
detail: "是否前往 GitHub 下载新版本安装包?",
12+
buttons: ["前往", "取消"],
13+
type: "question",
14+
noLink: true,
15+
})
16+
.then((result) => {
17+
if (result.response === 0) {
18+
shell.openExternal("https://github.com/imsyy/SPlayer/releases");
19+
}
20+
});
521
};
622

723
export const configureAutoUpdater = () => {
8-
checkForUpdates();
9-
10-
// 监听检查更新的事件
11-
autoUpdater.on("checking-for-update", () => {
12-
console.log("Checking for update...");
13-
});
14-
24+
if (is.dev) return false;
25+
autoUpdater.checkForUpdatesAndNotify();
26+
// 若有更新
1527
autoUpdater.on("update-available", (info) => {
16-
console.log("Update available:", info);
17-
});
18-
19-
autoUpdater.on("update-not-available", () => {
20-
console.log("Update not available.");
21-
});
22-
23-
autoUpdater.on("update-downloaded", () => {
24-
console.log("Update downloaded. Ready to install.");
25-
26-
// 在需要的时候,触发安装更新
27-
autoUpdater.quitAndInstall();
28+
hasNewVersion(info);
2829
});
2930
};

src/components/Player/Lyric.vue

+7
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ const jumpSeek = (time) => {
229229
fadePlayOrPause();
230230
};
231231

232+
// 主进程调用歌词滚动
233+
if (typeof electron !== "undefined") {
234+
electron.ipcRenderer.on("lyricsScroll", () => {
235+
lyricsScroll(playSongLyricIndex.value);
236+
});
237+
}
238+
232239
// 监听歌词滚动
233240
watch(
234241
() => playSongLyricIndex.value,

src/utils/globalEvents.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { checkPlatform } from "@/utils/helper";
22
import { playOrPause, changePlayIndex } from "@/utils/Player";
33
import { siteStatus } from "@/stores";
4-
import "vue-slider-component/theme/default.css";
54

65
const globalEvents = (router) => {
76
if (!checkPlatform.electron()) return false;

0 commit comments

Comments
 (0)