mirror of
https://github.com/imsyy/SPlayer.git
synced 2025-11-25 03:14:57 +08:00
🐞 fix: 修复本地目录无法读取 #315
This commit is contained in:
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@@ -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
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
# SPlayer
|
||||
|
||||
> 一个简约的音乐播放器
|
||||
> A simple music player
|
||||
|
||||

|
||||

|
||||
[](https://github.com/imsyy/SPlayer/actions/workflows/release.yml)
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
</div>
|
||||
<n-switch class="set" v-model:value="settingStore.showLocalCover" :round="false" />
|
||||
</n-card>
|
||||
<n-card class="set-item">
|
||||
<div class="label">
|
||||
<n-text class="name">显示本地默认歌曲目录</n-text>
|
||||
</div>
|
||||
<n-switch class="set" v-model:value="settingStore.showDefaultLocalPath" :round="false" />
|
||||
</n-card>
|
||||
<n-card class="set-item" id="local-list-choose" content-style="flex-direction: column">
|
||||
<n-flex justify="space-between">
|
||||
<div class="label">
|
||||
|
||||
@@ -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,
|
||||
// 下载
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -106,7 +106,14 @@
|
||||
<template #prefix>
|
||||
<SvgIcon :size="20" name="FolderMusic" />
|
||||
</template>
|
||||
<n-thing :title="defaultMusicPath" description="系统默认音乐文件夹,无法更改" />
|
||||
<template #suffix>
|
||||
<n-switch
|
||||
v-model:value="settingStore.showDefaultLocalPath"
|
||||
:round="false"
|
||||
class="set"
|
||||
/>
|
||||
</template>
|
||||
<n-thing :title="defaultMusicPath" description="系统默认音乐文件夹" />
|
||||
</n-list-item>
|
||||
<n-list-item v-for="(item, index) in settingStore.localFilesPath" :key="index">
|
||||
<template #prefix>
|
||||
@@ -176,7 +183,10 @@ const listData = computed<SongType[]>(() => {
|
||||
// 获取音乐文件夹
|
||||
const getMusicFolder = async (): Promise<string[]> => {
|
||||
defaultMusicPath.value = await window.electron.ipcRenderer.invoke("get-default-dir", "music");
|
||||
return [defaultMusicPath.value, ...settingStore.localFilesPath];
|
||||
return [
|
||||
settingStore.showDefaultLocalPath ? defaultMusicPath.value : "",
|
||||
...settingStore.localFilesPath,
|
||||
];
|
||||
};
|
||||
|
||||
// 全部音乐大小
|
||||
@@ -262,7 +272,7 @@ localEventBus.on(() => getAllLocalMusic());
|
||||
|
||||
// 本地目录变化
|
||||
watch(
|
||||
() => settingStore.localFilesPath,
|
||||
() => [settingStore.localFilesPath, settingStore.showDefaultLocalPath],
|
||||
async () => await getAllLocalMusic(),
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"electron/main/index.d.ts",
|
||||
"electron/preload/index.d.ts",
|
||||
"electron/preload/index.ts"
|
||||
],
|
||||
, "dist/lastfm.ts" ],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"types": ["electron-vite/node"]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"src/**/*.vue",
|
||||
"electron/main/index.d.ts",
|
||||
"electron/preload/index.d.ts"
|
||||
],
|
||||
, "dist/lastfm.ts" ],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"maxNodeModuleJsDepth": 2,
|
||||
|
||||
Reference in New Issue
Block a user