From 96a0495a88990eb6dd37e0e2e0a9aac9f2ddc563 Mon Sep 17 00:00:00 2001 From: imsyy Date: Mon, 23 Dec 2024 11:21:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=9B=AE=E5=BD=95=E6=97=A0=E6=B3=95=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=20#315?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 1 + README.md | 8 +++++++- electron/main/ipcMain.ts | 16 ++++++++++++++-- electron/server/netease/index.ts | 2 +- src/components/Setting/LocalSetting.vue | 6 ++++++ src/stores/setting.ts | 2 ++ src/utils/helper.ts | 8 +++++--- src/views/Local/layout.vue | 16 +++++++++++++--- tsconfig.node.json | 2 +- tsconfig.web.json | 2 +- 10 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 28f768ca..0d5eacd8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -142,6 +142,7 @@ jobs: shell: bash env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }} # 上传 Snap 包到 Snapcraft 商店 - name: Publish Snap to Snap Store run: snapcraft upload dist/*.snap --release stable diff --git a/README.md b/README.md index 6b1bea2f..fe6b6c7d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # SPlayer -> 一个简约的音乐播放器 +> A simple music player + +![Stars](https://img.shields.io/github/stars/imsyy/SPlayer?style=flat) +![Version](https://img.shields.io/github/v/release/imsyy/SPlayer) +[![Build Release](https://github.com/imsyy/SPlayer/actions/workflows/release.yml/badge.svg)](https://github.com/imsyy/SPlayer/actions/workflows/release.yml) +![License](https://img.shields.io/github/license/imsyy/SPlayer) +![Issues](https://img.shields.io/github/issues/imsyy/SPlayer) ![main](/screenshots/SPlayer.jpg) diff --git a/electron/main/ipcMain.ts b/electron/main/ipcMain.ts index 276e15ca..34f9962d 100644 --- a/electron/main/ipcMain.ts +++ b/electron/main/ipcMain.ts @@ -17,7 +17,7 @@ import { Thumbar } from "./thumbar"; import { StoreType } from "./store"; import { isDev, getFileID, getFileMD5 } from "./utils"; import { isShortcutRegistered, registerShortcut, unregisterShortcuts } from "./shortcut"; -import { join, basename, resolve } from "path"; +import { join, basename, resolve, relative, isAbsolute } from "path"; import { download } from "electron-dl"; import { checkUpdate, startDownloadUpdate } from "./update"; import fs from "fs/promises"; @@ -173,8 +173,10 @@ const initWinIpcMain = ( // 遍历音乐文件 ipcMain.handle("get-music-files", async (_, dirPath: string) => { try { + // 规范化路径 + const filePath = resolve(dirPath); // 查找指定目录下的所有音乐文件 - const musicFiles = await fg("**/*.{mp3,wav,flac}", { cwd: dirPath }); + const musicFiles = await fg("**/*.{mp3,wav,flac}", { cwd: filePath }); // 解析元信息 const metadataPromises = musicFiles.map(async (file) => { const filePath = join(dirPath, file); @@ -623,6 +625,16 @@ const initLyricIpcMain = ( lyricWin.setIgnoreMouseEvents(false); } }); + + // 检查是否是子文件夹 + ipcMain.handle("check-if-subfolder", (_, localFilesPath: string[], selectedDir: string) => { + const resolvedSelectedDir = resolve(selectedDir); + const allPaths = localFilesPath.map((p) => resolve(p)); + return allPaths.some((existingPath) => { + const relativePath = relative(existingPath, resolvedSelectedDir); + return relativePath && !relativePath.startsWith("..") && !isAbsolute(relativePath); + }); + }); }; // tray diff --git a/electron/server/netease/index.ts b/electron/server/netease/index.ts index 8f79f75b..e758c83e 100644 --- a/electron/server/netease/index.ts +++ b/electron/server/netease/index.ts @@ -34,7 +34,7 @@ const initNcmAPI = async (fastify: FastifyInstance) => { fastify.get("/netease", (_, reply) => { reply.send({ name: "NeteaseCloudMusicApi", - version: "4.20.0", + version: "4.25.0", description: "网易云音乐 Node.js API service", author: "@binaryify", license: "MIT", diff --git a/src/components/Setting/LocalSetting.vue b/src/components/Setting/LocalSetting.vue index fc4d3965..3409c0d2 100644 --- a/src/components/Setting/LocalSetting.vue +++ b/src/components/Setting/LocalSetting.vue @@ -10,6 +10,12 @@ + +
+ 显示本地默认歌曲目录 +
+ +
diff --git a/src/stores/setting.ts b/src/stores/setting.ts index 0665273a..c2e0fe38 100644 --- a/src/stores/setting.ts +++ b/src/stores/setting.ts @@ -86,6 +86,7 @@ interface SettingState { dynamicCover: boolean; useKeepAlive: boolean; excludeKeywords: string[]; + showDefaultLocalPath: boolean; } export const useSettingStore = defineStore("setting", { @@ -148,6 +149,7 @@ export const useSettingStore = defineStore("setting", { excludeKeywords: keywords, // 排除歌词关键字 // 本地 localFilesPath: [], + showDefaultLocalPath: true, // 显示默认本地路径 localSeparators: ["/", "&"], showLocalCover: true, // 下载 diff --git a/src/utils/helper.ts b/src/utils/helper.ts index af11d34f..3b8002bb 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -273,9 +273,11 @@ export const changeLocalPath = async (delIndex?: number) => { // 检查是否为子文件夹 const defaultMusicPath = await window.electron.ipcRenderer.invoke("get-default-dir", "music"); const allPath = [defaultMusicPath, ...settingStore.localFilesPath]; - const isSubfolder = allPath.some((existingPath) => { - return selectedDir.startsWith(existingPath); - }); + const isSubfolder = await window.electron.ipcRenderer.invoke( + "check-if-subfolder", + allPath, + selectedDir, + ); if (!isSubfolder) { settingStore.localFilesPath.push(selectedDir); } else { diff --git a/src/views/Local/layout.vue b/src/views/Local/layout.vue index 218838dd..f38d06e9 100644 --- a/src/views/Local/layout.vue +++ b/src/views/Local/layout.vue @@ -106,7 +106,14 @@ - + +