diff --git a/electron/main/loginWin.ts b/electron/main/loginWin.ts index aa69ec2d..20e520da 100644 --- a/electron/main/loginWin.ts +++ b/electron/main/loginWin.ts @@ -1,13 +1,23 @@ -import { BrowserWindow, MenuItemConstructorOptions, Menu, session, dialog } from "electron"; +import { + BrowserWindow, + MenuItemConstructorOptions, + Menu, + session, + dialog, + ipcMain, +} from "electron"; +import icon from "../../public/icons/favicon.png?asset"; const openLoginWin = (mainWin: BrowserWindow) => { const loginSession = session.fromPartition("login-win"); const loginWin = new BrowserWindow({ parent: mainWin, + title: "登录网易云音乐", width: 1280, height: 800, center: true, modal: true, + icon, // resizable: false, // movable: false, // minimizable: false, @@ -20,35 +30,90 @@ const openLoginWin = (mainWin: BrowserWindow) => { }); // 打开网易云 - loginWin.loadURL("https://music.163.com/#/login"); + loginWin.loadURL("https://music.163.com/#/my/"); // 阻止新窗口创建 loginWin.webContents.setWindowOpenHandler(() => { return { action: "deny" }; }); + // 登录完成 + const loginFinish = async () => { + if (!loginWin) return; + // 获取 Cookie + const cookies = await loginWin.webContents.session.cookies.get({ name: "MUSIC_U" }); + if (!cookies?.[0]?.value) { + dialog.showMessageBox({ + type: "info", + title: "登录失败", + message: "未查找到登录信息,请重试", + }); + return; + } + const value = `MUSIC_U=${cookies[0].value};`; + // 发送回主进程 + mainWin?.webContents.send("send-cookies", value); + await loginSession?.clearStorageData(); + loginWin.close(); + }; + + // 页面注入 + // loginWin.webContents.once("did-finish-load", () => { + // const script = ` + // const style = document.createElement('style'); + // style.innerHTML = \` + // .login-btn { + // position: fixed; + // left: 0; + // bottom: 0; + // width: 100%; + // height: 80px; + // display: flex; + // align-items: center; + // justify-content: center; + // background-color: #242424; + // z-index: 99999; + // } + + // .login-btn span { + // color: white; + // margin-right: 20px; + // } + + // .login-btn button { + // border: none; + // outline: none; + // background-color: #c20c0c; + // border-radius: 25px; + // color: white; + // height: 40px; + // padding: 0 20px; + // cursor: pointer; + // } + // \`; + // document.head.appendChild(style); + // const div = document.createElement('div'); + // div.className = 'login-btn'; + // div.innerHTML = \` + // 请在登录成功后点击 + // + // \`; + // div.querySelector('button').addEventListener('click', () => { + // window.electron.ipcRenderer.send("login-success"); + // }); + // document.body.appendChild(div); + // `; + // loginWin.webContents.executeJavaScript(script); + // }); + + // 监听事件 + ipcMain.on("login-success", loginFinish); + // 菜单栏 const menuTemplate: MenuItemConstructorOptions[] = [ { label: "登录完成", - click: async () => { - if (!loginWin) return; - // 获取 Cookie - const cookies = await loginWin.webContents.session.cookies.get({ name: "MUSIC_U" }); - if (!cookies?.[0]?.value) { - dialog.showMessageBox({ - type: "info", - title: "登录失败", - message: "未查找到登录信息,请重试", - }); - return; - } - const value = `MUSIC_U=${cookies[0].value};`; - // 发送回主进程 - mainWin?.webContents.send("send-cookies", value); - await loginSession?.clearStorageData(); - loginWin.close(); - }, + click: loginFinish, }, ]; const menu = Menu.buildFromTemplate(menuTemplate); diff --git a/src/components/Modal/Login/LoginCookie.vue b/src/components/Modal/Login/LoginCookie.vue index ba9915df..13626b88 100644 --- a/src/components/Modal/Login/LoginCookie.vue +++ b/src/components/Modal/Login/LoginCookie.vue @@ -35,7 +35,14 @@ const cookie = ref(); // 开启窗口 const openWeb = () => { - window.electron.ipcRenderer.send("open-login-web"); + window.$dialog.info({ + title: "使用前告知", + content: + "请知悉,该功能仍旧无法确保账号的安全性!请自行决定是否使用!如遇打开窗口后页面出现白屏或者无法点击等情况,请关闭后再试。在登录完成后,请点击菜单栏中的 “登录完成” 按钮以完成登录( 通常位于窗口的左上角,macOS 位于顶部的全局菜单栏中 )", + positiveText: "我已了解", + negativeText: "取消", + onPositiveClick: () => window.electron.ipcRenderer.send("open-login-web"), + }); }; // Cookie 登录 @@ -44,8 +51,11 @@ const login = async () => { window.$message.warning("请输入 Cookie"); return; } + cookie.value = cookie.value.trim(); + console.log(cookie.value.endsWith(";")); + // 是否为有效 Cookie - if (!cookie.value.includes("MUSIC_U") || cookie.value.endsWith(";")) { + if (!cookie.value.includes("MUSIC_U") || !cookie.value.endsWith(";")) { window.$message.warning("请输入有效的 Cookie"); return; } diff --git a/src/components/Setting/AboutSetting.vue b/src/components/Setting/AboutSetting.vue index 547f5a6b..38356837 100644 --- a/src/components/Setting/AboutSetting.vue +++ b/src/components/Setting/AboutSetting.vue @@ -10,7 +10,15 @@ {{ packageJson.version }} - 检查更新 + + {{ statusStore.updateCheck ? "检查更新中" : "检查更新" }} + @@ -73,8 +81,11 @@ import type { UpdateLogType } from "@/types/main"; import { getUpdateLog, isElectron, openLink } from "@/utils/helper"; import { debounce } from "lodash-es"; +import { useStatusStore } from "@/stores"; import packageJson from "@/../package.json"; +const statusStore = useStatusStore(); + // 社区数据 const communityData = [ { @@ -102,18 +113,18 @@ const oldVersion = computed(() => { }); // 检查更新 -const checkUpdate = debounce(() => { - if (!isElectron) { - window.open(packageJson.github + "/releases", "_blank"); - return; - } - window.$notification.info({ - title: "检查更新", - content: "正在检查更新,请稍后...", - duration: 3000, - }); - window.electron.ipcRenderer.send("check-update", true); -}, 300); +const checkUpdate = debounce( + () => { + if (!isElectron) { + window.open(packageJson.github + "/releases", "_blank"); + return; + } + statusStore.updateCheck = true; + window.electron.ipcRenderer.send("check-update", true); + }, + 300, + { leading: true, trailing: false }, +); // 获取更新日志 const getUpdateData = async () => (updateData.value = await getUpdateLog()); diff --git a/src/components/Setting/GeneralSetting.vue b/src/components/Setting/GeneralSetting.vue index ab022ae9..84e79fa1 100644 --- a/src/components/Setting/GeneralSetting.vue +++ b/src/components/Setting/GeneralSetting.vue @@ -142,7 +142,13 @@ 在线服务 是否开启软件的在线服务 - +
diff --git a/src/stores/status.ts b/src/stores/status.ts index 01adaef1..10592823 100644 --- a/src/stores/status.ts +++ b/src/stores/status.ts @@ -38,6 +38,7 @@ interface StatusState { showDesktopLyric: boolean; showPlayerComment: boolean; personalFmMode: boolean; + updateCheck: boolean; } export const useStatusStore = defineStore("status", { @@ -99,6 +100,8 @@ export const useStatusStore = defineStore("status", { showDesktopLyric: false, // 播放器评论 showPlayerComment: false, + // 更新检查 + updateCheck: false, }), getters: { // 播放音量图标 diff --git a/src/utils/initIpc.ts b/src/utils/initIpc.ts index f358f42d..d5184bb8 100644 --- a/src/utils/initIpc.ts +++ b/src/utils/initIpc.ts @@ -1,8 +1,14 @@ import { isElectron } from "./helper"; import { openUpdateApp } from "./modal"; -import { useMusicStore, useDataStore } from "@/stores"; -import player from "./player"; +import { useMusicStore, useDataStore, useStatusStore } from "@/stores"; import { toLikeSong } from "./auth"; +import player from "./player"; + +// 关闭更新状态 +const closeUpdateStatus = () => { + const statusStore = useStatusStore(); + statusStore.updateCheck = false; +}; // 全局 IPC 事件 const initIpc = () => { @@ -35,13 +41,18 @@ const initIpc = () => { window.electron.ipcRenderer.on("closeDesktopLyric", () => player.toggleDesktopLyric()); // 无更新 window.electron.ipcRenderer.on("update-not-available", () => { + closeUpdateStatus(); window.$message.success("当前已是最新版本"); }); // 有更新 - window.electron.ipcRenderer.on("update-available", (_, info) => openUpdateApp(info)); + window.electron.ipcRenderer.on("update-available", (_, info) => { + closeUpdateStatus(); + openUpdateApp(info); + }); // 更新错误 window.electron.ipcRenderer.on("update-error", (_, error) => { console.error("Error updating:", error); + closeUpdateStatus(); window.$message.error("更新过程出现错误"); }); } catch (error) {