Skip to content

Commit

Permalink
fix: 完善更新流程
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Nov 30, 2023
1 parent 41c4342 commit d471e68
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
22 changes: 21 additions & 1 deletion electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class MainProcess {
// mainWindow.maximize();
});

// 主窗口事件
this.mainWindowEvents();

// 设置窗口打开处理程序
this.mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url);
Expand Down Expand Up @@ -153,14 +156,31 @@ class MainProcess {
// 注销全部快捷键
globalShortcut.unregisterAll();
});

// 当所有窗口都关闭时退出应用,macOS 除外
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
}

// 主窗口事件
mainWindowEvents() {
this.mainWindow.on("show", () => {
console.info("窗口展示");
this.mainWindow.webContents.send("lyricsScroll");
});
// this.mainWindow.on("hide", () => {
// console.info("窗口隐藏");
// });
this.mainWindow.on("focus", () => {
console.info("窗口获得焦点");
this.mainWindow.webContents.send("lyricsScroll");
});
// this.mainWindow.on("blur", () => {
// console.info("窗口失去焦点");
// });
}
}

new MainProcess();
45 changes: 23 additions & 22 deletions electron/main/utils/checkUpdates.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
const { autoUpdater } = require("electron-updater");
import { dialog, shell } from "electron";
import { is } from "@electron-toolkit/utils";
import { autoUpdater } from "electron-updater";

const checkForUpdates = () => {
autoUpdater.checkForUpdates();
// 更新弹窗
const hasNewVersion = (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/imsyy/SPlayer/releases");
}
});
};

export const configureAutoUpdater = () => {
checkForUpdates();

// 监听检查更新的事件
autoUpdater.on("checking-for-update", () => {
console.log("Checking for update...");
});

if (is.dev) return false;
autoUpdater.checkForUpdatesAndNotify();
// 若有更新
autoUpdater.on("update-available", (info) => {
console.log("Update available:", info);
});

autoUpdater.on("update-not-available", () => {
console.log("Update not available.");
});

autoUpdater.on("update-downloaded", () => {
console.log("Update downloaded. Ready to install.");

// 在需要的时候,触发安装更新
autoUpdater.quitAndInstall();
hasNewVersion(info);
});
};
7 changes: 7 additions & 0 deletions src/components/Player/Lyric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ const jumpSeek = (time) => {
fadePlayOrPause();
};
// 主进程调用歌词滚动
if (typeof electron !== "undefined") {
electron.ipcRenderer.on("lyricsScroll", () => {
lyricsScroll(playSongLyricIndex.value);
});
}
// 监听歌词滚动
watch(
() => playSongLyricIndex.value,
Expand Down
1 change: 0 additions & 1 deletion src/utils/globalEvents.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { checkPlatform } from "@/utils/helper";
import { playOrPause, changePlayIndex } from "@/utils/Player";
import { siteStatus } from "@/stores";
import "vue-slider-component/theme/default.css";

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

0 comments on commit d471e68

Please sign in to comment.