Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a817865bd8 | ||
|
|
c4a4d26bd8 | ||
|
|
dfa36d872e | ||
|
|
995859e661 | ||
|
|
34fb0f7c2f | ||
|
|
191ba1e199 | ||
|
|
324e81c0dc | ||
|
|
7ec269e0cb | ||
|
|
6f10aae535 | ||
|
|
0c54a852ba | ||
|
|
bc53203bfa | ||
|
|
c149e5c904 | ||
|
|
d983abd3d5 | ||
|
|
f48369e1a2 | ||
|
|
2af9a4ea9f | ||
|
|
87f69fc782 | ||
|
|
59d3b0c65c | ||
|
|
e861ea8f78 |
@@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"@electron-toolkit/eslint-config-ts",
|
||||
"@electron-toolkit/eslint-config-prettier"
|
||||
],
|
||||
"extends": ["@electron-toolkit/eslint-config-ts", "@electron-toolkit/eslint-config-prettier"],
|
||||
"rules": {
|
||||
"vue/require-default-prop": "off",
|
||||
"vue/multi-word-component-names": "off",
|
||||
@@ -10,4 +7,4 @@
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"no-console": "warn"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
.github/workflows/main.yml
vendored
@@ -94,13 +94,13 @@ jobs:
|
||||
# 获取当前标签对应的 release 信息
|
||||
TAG_NAME=${GITHUB_REF#refs/tags/}
|
||||
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
# 获取 release 详细信息
|
||||
response=$(curl -s \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME")
|
||||
|
||||
|
||||
release_id=$(echo "$response" | jq -r '.id')
|
||||
echo "release_id=$release_id" >> $GITHUB_OUTPUT
|
||||
echo "找到 Release ID: $release_id"
|
||||
@@ -109,7 +109,7 @@ jobs:
|
||||
run: |
|
||||
TAG_NAME="${{ steps.get-release.outputs.tag_name }}"
|
||||
RELEASE_ID="${{ steps.get-release.outputs.release_id }}"
|
||||
|
||||
|
||||
echo "🚀 开始同步版本 $TAG_NAME 到 WebDAV..."
|
||||
echo "Release ID: $RELEASE_ID"
|
||||
echo "WebDAV 根路径: ${{ secrets.WEBDAV_BASE_URL }}/yd/ceru"
|
||||
@@ -131,7 +131,7 @@ jobs:
|
||||
# 先创建版本目录
|
||||
dir_path="/yd/ceru/$TAG_NAME"
|
||||
dir_url="${{ secrets.WEBDAV_BASE_URL }}$dir_path"
|
||||
|
||||
|
||||
echo "创建版本目录: $dir_path"
|
||||
curl -s -X MKCOL \
|
||||
-u "${{ secrets.WEBDAV_USERNAME }}:${{ secrets.WEBDAV_PASSWORD }}" \
|
||||
@@ -140,7 +140,7 @@ jobs:
|
||||
# 处理每个asset
|
||||
success_count=0
|
||||
failed_count=0
|
||||
|
||||
|
||||
for i in $(seq 0 $(($assets_count - 1))); do
|
||||
asset=$(echo "$assets_json" | jq -c ".[$i]")
|
||||
asset_name=$(echo "$asset" | jq -r '.name')
|
||||
@@ -198,7 +198,7 @@ jobs:
|
||||
failed_count=$((failed_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "========================================"
|
||||
echo "🎉 同步完成!"
|
||||
echo "成功: $success_count 个文件"
|
||||
|
||||
1
.gitignore
vendored
@@ -18,3 +18,4 @@ temp/log.txt
|
||||
/.idea/
|
||||
docs/.vitepress/dist
|
||||
docs/.vitepress/cache
|
||||
yarn.lock
|
||||
31
.vitepress/cache/deps/_metadata.json
vendored
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"hash": "23b978c5",
|
||||
"configHash": "c96c5ee9",
|
||||
"lockfileHash": "603038da",
|
||||
"browserHash": "b1457114",
|
||||
"optimized": {
|
||||
"vue": {
|
||||
"src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
|
||||
"file": "vue.js",
|
||||
"fileHash": "7c4217d1",
|
||||
"needsInterop": false
|
||||
},
|
||||
"vitepress > @vue/devtools-api": {
|
||||
"src": "../../../node_modules/vitepress/node_modules/@vue/devtools-api/dist/index.js",
|
||||
"file": "vitepress___@vue_devtools-api.js",
|
||||
"fileHash": "dc8e5ae9",
|
||||
"needsInterop": false
|
||||
},
|
||||
"vitepress > @vueuse/core": {
|
||||
"src": "../../../node_modules/@vueuse/core/index.mjs",
|
||||
"file": "vitepress___@vueuse_core.js",
|
||||
"fileHash": "74c34320",
|
||||
"needsInterop": false
|
||||
}
|
||||
},
|
||||
"chunks": {
|
||||
"chunk-TH7GRLUQ": {
|
||||
"file": "chunk-TH7GRLUQ.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
12833
.vitepress/cache/deps/chunk-TH7GRLUQ.js
vendored
7
.vitepress/cache/deps/chunk-TH7GRLUQ.js.map
vendored
3
.vitepress/cache/deps/package.json
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
4140
.vitepress/cache/deps/vitepress___@vue_devtools-api.js
vendored
9923
.vitepress/cache/deps/vitepress___@vueuse_core.js
vendored
342
.vitepress/cache/deps/vue.js
vendored
@@ -1,342 +0,0 @@
|
||||
import {
|
||||
BaseTransition,
|
||||
BaseTransitionPropsValidators,
|
||||
Comment,
|
||||
DeprecationTypes,
|
||||
EffectScope,
|
||||
ErrorCodes,
|
||||
ErrorTypeStrings,
|
||||
Fragment,
|
||||
KeepAlive,
|
||||
ReactiveEffect,
|
||||
Static,
|
||||
Suspense,
|
||||
Teleport,
|
||||
Text,
|
||||
TrackOpTypes,
|
||||
Transition,
|
||||
TransitionGroup,
|
||||
TriggerOpTypes,
|
||||
VueElement,
|
||||
assertNumber,
|
||||
callWithAsyncErrorHandling,
|
||||
callWithErrorHandling,
|
||||
camelize,
|
||||
capitalize,
|
||||
cloneVNode,
|
||||
compatUtils,
|
||||
compile,
|
||||
computed,
|
||||
createApp,
|
||||
createBaseVNode,
|
||||
createBlock,
|
||||
createCommentVNode,
|
||||
createElementBlock,
|
||||
createHydrationRenderer,
|
||||
createPropsRestProxy,
|
||||
createRenderer,
|
||||
createSSRApp,
|
||||
createSlots,
|
||||
createStaticVNode,
|
||||
createTextVNode,
|
||||
createVNode,
|
||||
customRef,
|
||||
defineAsyncComponent,
|
||||
defineComponent,
|
||||
defineCustomElement,
|
||||
defineEmits,
|
||||
defineExpose,
|
||||
defineModel,
|
||||
defineOptions,
|
||||
defineProps,
|
||||
defineSSRCustomElement,
|
||||
defineSlots,
|
||||
devtools,
|
||||
effect,
|
||||
effectScope,
|
||||
getCurrentInstance,
|
||||
getCurrentScope,
|
||||
getCurrentWatcher,
|
||||
getTransitionRawChildren,
|
||||
guardReactiveProps,
|
||||
h,
|
||||
handleError,
|
||||
hasInjectionContext,
|
||||
hydrate,
|
||||
hydrateOnIdle,
|
||||
hydrateOnInteraction,
|
||||
hydrateOnMediaQuery,
|
||||
hydrateOnVisible,
|
||||
initCustomFormatter,
|
||||
initDirectivesForSSR,
|
||||
inject,
|
||||
isMemoSame,
|
||||
isProxy,
|
||||
isReactive,
|
||||
isReadonly,
|
||||
isRef,
|
||||
isRuntimeOnly,
|
||||
isShallow,
|
||||
isVNode,
|
||||
markRaw,
|
||||
mergeDefaults,
|
||||
mergeModels,
|
||||
mergeProps,
|
||||
nextTick,
|
||||
normalizeClass,
|
||||
normalizeProps,
|
||||
normalizeStyle,
|
||||
onActivated,
|
||||
onBeforeMount,
|
||||
onBeforeUnmount,
|
||||
onBeforeUpdate,
|
||||
onDeactivated,
|
||||
onErrorCaptured,
|
||||
onMounted,
|
||||
onRenderTracked,
|
||||
onRenderTriggered,
|
||||
onScopeDispose,
|
||||
onServerPrefetch,
|
||||
onUnmounted,
|
||||
onUpdated,
|
||||
onWatcherCleanup,
|
||||
openBlock,
|
||||
popScopeId,
|
||||
provide,
|
||||
proxyRefs,
|
||||
pushScopeId,
|
||||
queuePostFlushCb,
|
||||
reactive,
|
||||
readonly,
|
||||
ref,
|
||||
registerRuntimeCompiler,
|
||||
render,
|
||||
renderList,
|
||||
renderSlot,
|
||||
resolveComponent,
|
||||
resolveDirective,
|
||||
resolveDynamicComponent,
|
||||
resolveFilter,
|
||||
resolveTransitionHooks,
|
||||
setBlockTracking,
|
||||
setDevtoolsHook,
|
||||
setTransitionHooks,
|
||||
shallowReactive,
|
||||
shallowReadonly,
|
||||
shallowRef,
|
||||
ssrContextKey,
|
||||
ssrUtils,
|
||||
stop,
|
||||
toDisplayString,
|
||||
toHandlerKey,
|
||||
toHandlers,
|
||||
toRaw,
|
||||
toRef,
|
||||
toRefs,
|
||||
toValue,
|
||||
transformVNodeArgs,
|
||||
triggerRef,
|
||||
unref,
|
||||
useAttrs,
|
||||
useCssModule,
|
||||
useCssVars,
|
||||
useHost,
|
||||
useId,
|
||||
useModel,
|
||||
useSSRContext,
|
||||
useShadowRoot,
|
||||
useSlots,
|
||||
useTemplateRef,
|
||||
useTransitionState,
|
||||
vModelCheckbox,
|
||||
vModelDynamic,
|
||||
vModelRadio,
|
||||
vModelSelect,
|
||||
vModelText,
|
||||
vShow,
|
||||
version,
|
||||
warn,
|
||||
watch,
|
||||
watchEffect,
|
||||
watchPostEffect,
|
||||
watchSyncEffect,
|
||||
withAsyncContext,
|
||||
withCtx,
|
||||
withDefaults,
|
||||
withDirectives,
|
||||
withKeys,
|
||||
withMemo,
|
||||
withModifiers,
|
||||
withScopeId
|
||||
} from './chunk-TH7GRLUQ.js'
|
||||
export {
|
||||
BaseTransition,
|
||||
BaseTransitionPropsValidators,
|
||||
Comment,
|
||||
DeprecationTypes,
|
||||
EffectScope,
|
||||
ErrorCodes,
|
||||
ErrorTypeStrings,
|
||||
Fragment,
|
||||
KeepAlive,
|
||||
ReactiveEffect,
|
||||
Static,
|
||||
Suspense,
|
||||
Teleport,
|
||||
Text,
|
||||
TrackOpTypes,
|
||||
Transition,
|
||||
TransitionGroup,
|
||||
TriggerOpTypes,
|
||||
VueElement,
|
||||
assertNumber,
|
||||
callWithAsyncErrorHandling,
|
||||
callWithErrorHandling,
|
||||
camelize,
|
||||
capitalize,
|
||||
cloneVNode,
|
||||
compatUtils,
|
||||
compile,
|
||||
computed,
|
||||
createApp,
|
||||
createBlock,
|
||||
createCommentVNode,
|
||||
createElementBlock,
|
||||
createBaseVNode as createElementVNode,
|
||||
createHydrationRenderer,
|
||||
createPropsRestProxy,
|
||||
createRenderer,
|
||||
createSSRApp,
|
||||
createSlots,
|
||||
createStaticVNode,
|
||||
createTextVNode,
|
||||
createVNode,
|
||||
customRef,
|
||||
defineAsyncComponent,
|
||||
defineComponent,
|
||||
defineCustomElement,
|
||||
defineEmits,
|
||||
defineExpose,
|
||||
defineModel,
|
||||
defineOptions,
|
||||
defineProps,
|
||||
defineSSRCustomElement,
|
||||
defineSlots,
|
||||
devtools,
|
||||
effect,
|
||||
effectScope,
|
||||
getCurrentInstance,
|
||||
getCurrentScope,
|
||||
getCurrentWatcher,
|
||||
getTransitionRawChildren,
|
||||
guardReactiveProps,
|
||||
h,
|
||||
handleError,
|
||||
hasInjectionContext,
|
||||
hydrate,
|
||||
hydrateOnIdle,
|
||||
hydrateOnInteraction,
|
||||
hydrateOnMediaQuery,
|
||||
hydrateOnVisible,
|
||||
initCustomFormatter,
|
||||
initDirectivesForSSR,
|
||||
inject,
|
||||
isMemoSame,
|
||||
isProxy,
|
||||
isReactive,
|
||||
isReadonly,
|
||||
isRef,
|
||||
isRuntimeOnly,
|
||||
isShallow,
|
||||
isVNode,
|
||||
markRaw,
|
||||
mergeDefaults,
|
||||
mergeModels,
|
||||
mergeProps,
|
||||
nextTick,
|
||||
normalizeClass,
|
||||
normalizeProps,
|
||||
normalizeStyle,
|
||||
onActivated,
|
||||
onBeforeMount,
|
||||
onBeforeUnmount,
|
||||
onBeforeUpdate,
|
||||
onDeactivated,
|
||||
onErrorCaptured,
|
||||
onMounted,
|
||||
onRenderTracked,
|
||||
onRenderTriggered,
|
||||
onScopeDispose,
|
||||
onServerPrefetch,
|
||||
onUnmounted,
|
||||
onUpdated,
|
||||
onWatcherCleanup,
|
||||
openBlock,
|
||||
popScopeId,
|
||||
provide,
|
||||
proxyRefs,
|
||||
pushScopeId,
|
||||
queuePostFlushCb,
|
||||
reactive,
|
||||
readonly,
|
||||
ref,
|
||||
registerRuntimeCompiler,
|
||||
render,
|
||||
renderList,
|
||||
renderSlot,
|
||||
resolveComponent,
|
||||
resolveDirective,
|
||||
resolveDynamicComponent,
|
||||
resolveFilter,
|
||||
resolveTransitionHooks,
|
||||
setBlockTracking,
|
||||
setDevtoolsHook,
|
||||
setTransitionHooks,
|
||||
shallowReactive,
|
||||
shallowReadonly,
|
||||
shallowRef,
|
||||
ssrContextKey,
|
||||
ssrUtils,
|
||||
stop,
|
||||
toDisplayString,
|
||||
toHandlerKey,
|
||||
toHandlers,
|
||||
toRaw,
|
||||
toRef,
|
||||
toRefs,
|
||||
toValue,
|
||||
transformVNodeArgs,
|
||||
triggerRef,
|
||||
unref,
|
||||
useAttrs,
|
||||
useCssModule,
|
||||
useCssVars,
|
||||
useHost,
|
||||
useId,
|
||||
useModel,
|
||||
useSSRContext,
|
||||
useShadowRoot,
|
||||
useSlots,
|
||||
useTemplateRef,
|
||||
useTransitionState,
|
||||
vModelCheckbox,
|
||||
vModelDynamic,
|
||||
vModelRadio,
|
||||
vModelSelect,
|
||||
vModelText,
|
||||
vShow,
|
||||
version,
|
||||
warn,
|
||||
watch,
|
||||
watchEffect,
|
||||
watchPostEffect,
|
||||
watchSyncEffect,
|
||||
withAsyncContext,
|
||||
withCtx,
|
||||
withDefaults,
|
||||
withDirectives,
|
||||
withKeys,
|
||||
withMemo,
|
||||
withModifiers,
|
||||
withScopeId
|
||||
}
|
||||
7
.vitepress/cache/deps/vue.js.map
vendored
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": [],
|
||||
"sourcesContent": [],
|
||||
"mappings": "",
|
||||
"names": []
|
||||
}
|
||||
272
README.md
@@ -8,6 +8,10 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
||||
|
||||
<img src="assets/image-20250827175023917.png" alt="image-20250827175023917" style="zoom: 33%;" /><img src="assets/image-20250827175109430.png" alt="image-20250827175109430" style="zoom:33%;" />
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://www.star-history.com/#timeshiftsauce/CeruMusic&Date)
|
||||
|
||||
## 技术栈
|
||||
|
||||
- **Electron**:用于构建跨平台桌面应用
|
||||
@@ -18,6 +22,274 @@ Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工
|
||||
- **CeruPlugins**:音乐插件运行环境(仅提供框架,不包含默认插件)
|
||||
- **AMLL**:音乐生态辅助模块(仅提供功能接口,不关联具体音乐数据源)
|
||||
|
||||
## 项目结构
|
||||
|
||||
```ast
|
||||
CeruMuisc/
|
||||
├── .github/
|
||||
│ └── workflows/
|
||||
│ ├── auto-sync-release.yml
|
||||
│ ├── deploydocs.yml
|
||||
│ ├── main.yml
|
||||
│ ├── sync-releases-to-webdav.yml
|
||||
│ └── uploadpan.yml
|
||||
├── scripts/
|
||||
│ ├── auth-test.js
|
||||
│ ├── genAst.js
|
||||
│ └── test-alist.js
|
||||
├── src/
|
||||
│ ├── common/
|
||||
│ │ ├── types/
|
||||
│ │ │ ├── playList.ts
|
||||
│ │ │ └── songList.ts
|
||||
│ │ ├── utils/
|
||||
│ │ │ ├── lyricUtils/
|
||||
│ │ │ │ ├── kg.js
|
||||
│ │ │ │ └── util.ts
|
||||
│ │ │ ├── common.ts
|
||||
│ │ │ ├── nodejs.ts
|
||||
│ │ │ └── renderer.ts
|
||||
│ │ └── index.ts
|
||||
│ ├── main/
|
||||
│ │ ├── events/
|
||||
│ │ │ ├── ai.ts
|
||||
│ │ │ ├── autoUpdate.ts
|
||||
│ │ │ ├── directorySettings.ts
|
||||
│ │ │ ├── musicCache.ts
|
||||
│ │ │ └── songList.ts
|
||||
│ │ ├── services/
|
||||
│ │ │ ├── music/
|
||||
│ │ │ │ ├── index.ts
|
||||
│ │ │ │ ├── net-ease-service.ts
|
||||
│ │ │ │ └── service-base.ts
|
||||
│ │ │ ├── musicCache/
|
||||
│ │ │ │ └── index.ts
|
||||
│ │ │ ├── musicSdk/
|
||||
│ │ │ │ ├── index.ts
|
||||
│ │ │ │ ├── service.ts
|
||||
│ │ │ │ └── type.ts
|
||||
│ │ │ ├── plugin/
|
||||
│ │ │ │ ├── manager/
|
||||
│ │ │ │ │ ├── CeruMusicPluginHost.ts
|
||||
│ │ │ │ │ └── converter-event-driven.ts
|
||||
│ │ │ │ ├── index.ts
|
||||
│ │ │ │ └── logger.ts
|
||||
│ │ │ ├── songList/
|
||||
│ │ │ │ ├── ManageSongList.ts
|
||||
│ │ │ │ └── PlayListSongs.ts
|
||||
│ │ │ └── ai-service.ts
|
||||
│ │ ├── utils/
|
||||
│ │ │ ├── musicSdk/
|
||||
│ │ │ │ ├── kg/
|
||||
│ │ │ │ │ ├── temp/
|
||||
│ │ │ │ │ │ ├── musicSearch-new.js
|
||||
│ │ │ │ │ │ └── songList-new.js
|
||||
│ │ │ │ │ ├── vendors/
|
||||
│ │ │ │ │ │ └── infSign.min.js
|
||||
│ │ │ │ │ ├── album.js
|
||||
│ │ │ │ │ ├── api-test.js
|
||||
│ │ │ │ │ ├── comment.js
|
||||
│ │ │ │ │ ├── hotSearch.js
|
||||
│ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ ├── leaderboard.js
|
||||
│ │ │ │ │ ├── lyric.js
|
||||
│ │ │ │ │ ├── musicInfo.js
|
||||
│ │ │ │ │ ├── musicSearch.js
|
||||
│ │ │ │ │ ├── pic.js
|
||||
│ │ │ │ │ ├── singer.js
|
||||
│ │ │ │ │ ├── songList.js
|
||||
│ │ │ │ │ ├── tipSearch.js
|
||||
│ │ │ │ │ └── util.js
|
||||
│ │ │ │ ├── kw/
|
||||
│ │ │ │ │ ├── album.js
|
||||
│ │ │ │ │ ├── api-temp.js
|
||||
│ │ │ │ │ ├── api-test.js
|
||||
│ │ │ │ │ ├── comment.js
|
||||
│ │ │ │ │ ├── hotSearch.js
|
||||
│ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ ├── kwdecode.ts
|
||||
│ │ │ │ │ ├── leaderboard.js
|
||||
│ │ │ │ │ ├── lyric.js
|
||||
│ │ │ │ │ ├── musicSearch.js
|
||||
│ │ │ │ │ ├── pic.js
|
||||
│ │ │ │ │ ├── songList.js
|
||||
│ │ │ │ │ ├── tipSearch.js
|
||||
│ │ │ │ │ └── util.js
|
||||
│ │ │ │ ├── mg/
|
||||
│ │ │ │ │ ├── temp/
|
||||
│ │ │ │ │ │ └── leaderboard-old.js
|
||||
│ │ │ │ │ ├── utils/
|
||||
│ │ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ │ └── mrc.js
|
||||
│ │ │ │ │ ├── album.js
|
||||
│ │ │ │ │ ├── api-test.js
|
||||
│ │ │ │ │ ├── comment.js
|
||||
│ │ │ │ │ ├── hotSearch.js
|
||||
│ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ ├── leaderboard.js
|
||||
│ │ │ │ │ ├── lyric.js
|
||||
│ │ │ │ │ ├── musicInfo.js
|
||||
│ │ │ │ │ ├── musicSearch.js
|
||||
│ │ │ │ │ ├── pic.js
|
||||
│ │ │ │ │ ├── songId.js
|
||||
│ │ │ │ │ ├── songList.js
|
||||
│ │ │ │ │ └── tipSearch.js
|
||||
│ │ │ │ ├── tx/
|
||||
│ │ │ │ │ ├── api-test.js
|
||||
│ │ │ │ │ ├── comment.js
|
||||
│ │ │ │ │ ├── hotSearch.js
|
||||
│ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ ├── leaderboard.js
|
||||
│ │ │ │ │ ├── lyric.js
|
||||
│ │ │ │ │ ├── musicInfo.js
|
||||
│ │ │ │ │ ├── musicSearch.js
|
||||
│ │ │ │ │ ├── singer.js
|
||||
│ │ │ │ │ ├── songList.js
|
||||
│ │ │ │ │ └── tipSearch.js
|
||||
│ │ │ │ ├── wy/
|
||||
│ │ │ │ │ ├── utils/
|
||||
│ │ │ │ │ │ ├── crypto.js
|
||||
│ │ │ │ │ │ └── index.js
|
||||
│ │ │ │ │ ├── api-test.js
|
||||
│ │ │ │ │ ├── comment.js
|
||||
│ │ │ │ │ ├── hotSearch.js
|
||||
│ │ │ │ │ ├── index.js
|
||||
│ │ │ │ │ ├── leaderboard.js
|
||||
│ │ │ │ │ ├── lyric.js
|
||||
│ │ │ │ │ ├── musicDetail.js
|
||||
│ │ │ │ │ ├── musicInfo.js
|
||||
│ │ │ │ │ ├── musicSearch.js
|
||||
│ │ │ │ │ ├── singer.js
|
||||
│ │ │ │ │ ├── songList.js
|
||||
│ │ │ │ │ └── tipSearch.js
|
||||
│ │ │ │ ├── api-source-info.ts
|
||||
│ │ │ │ ├── index.js
|
||||
│ │ │ │ ├── options.js
|
||||
│ │ │ │ └── utils.js
|
||||
│ │ │ ├── array.ts
|
||||
│ │ │ ├── index.ts
|
||||
│ │ │ ├── object.ts
|
||||
│ │ │ ├── path.ts
|
||||
│ │ │ ├── request.js
|
||||
│ │ │ └── utils.ts
|
||||
│ │ ├── autoUpdate.ts
|
||||
│ │ └── index.ts
|
||||
│ ├── preload/
|
||||
│ │ ├── index.d.ts
|
||||
│ │ └── index.ts
|
||||
│ ├── renderer/
|
||||
│ │ ├── public/
|
||||
│ │ │ ├── default-cover.png
|
||||
│ │ │ ├── head.jpg
|
||||
│ │ │ ├── logo.svg
|
||||
│ │ │ ├── star.png
|
||||
│ │ │ └── wldss.png
|
||||
│ │ ├── src/
|
||||
│ │ │ ├── api/
|
||||
│ │ │ │ └── songList.ts
|
||||
│ │ │ ├── components/
|
||||
│ │ │ │ ├── AI/
|
||||
│ │ │ │ │ └── FloatBall.vue
|
||||
│ │ │ │ ├── Music/
|
||||
│ │ │ │ │ └── SongVirtualList.vue
|
||||
│ │ │ │ ├── Play/
|
||||
│ │ │ │ │ ├── AudioVisualizer.vue
|
||||
│ │ │ │ │ ├── FullPlay.vue
|
||||
│ │ │ │ │ ├── GlobalAudio.vue
|
||||
│ │ │ │ │ ├── PlaylistActions.vue
|
||||
│ │ │ │ │ ├── PlaylistDrawer.vue
|
||||
│ │ │ │ │ ├── PlayMusic.vue
|
||||
│ │ │ │ │ └── ShaderBackground.vue
|
||||
│ │ │ │ ├── Search/
|
||||
│ │ │ │ │ └── SearchComponent.vue
|
||||
│ │ │ │ ├── Settings/
|
||||
│ │ │ │ │ ├── AIFloatBallSettings.vue
|
||||
│ │ │ │ │ ├── DirectorySettings.vue
|
||||
│ │ │ │ │ ├── MusicCache.vue
|
||||
│ │ │ │ │ ├── PlaylistSettings.vue
|
||||
│ │ │ │ │ └── UpdateSettings.vue
|
||||
│ │ │ │ ├── ThemeSelector.vue
|
||||
│ │ │ │ ├── TitleBarControls.vue
|
||||
│ │ │ │ ├── UpdateExample.vue
|
||||
│ │ │ │ ├── UpdateProgress.vue
|
||||
│ │ │ │ └── Versions.vue
|
||||
│ │ │ ├── composables/
|
||||
│ │ │ │ └── useAutoUpdate.ts
|
||||
│ │ │ ├── layout/
|
||||
│ │ │ │ └── index.vue
|
||||
│ │ │ ├── router/
|
||||
│ │ │ │ └── index.ts
|
||||
│ │ │ ├── services/
|
||||
│ │ │ │ ├── music/
|
||||
│ │ │ │ │ ├── index.ts
|
||||
│ │ │ │ │ └── service-base.ts
|
||||
│ │ │ │ └── autoUpdateService.ts
|
||||
│ │ │ ├── store/
|
||||
│ │ │ │ ├── ControlAudio.ts
|
||||
│ │ │ │ ├── LocalUserDetail.ts
|
||||
│ │ │ │ ├── search.ts
|
||||
│ │ │ │ └── Settings.ts
|
||||
│ │ │ ├── types/
|
||||
│ │ │ │ ├── audio.ts
|
||||
│ │ │ │ ├── Sources.ts
|
||||
│ │ │ │ └── userInfo.ts
|
||||
│ │ │ ├── utils/
|
||||
│ │ │ │ ├── audio/
|
||||
│ │ │ │ │ ├── audioManager.ts
|
||||
│ │ │ │ │ ├── download.ts
|
||||
│ │ │ │ │ ├── useSmtc.ts
|
||||
│ │ │ │ │ └── volume.ts
|
||||
│ │ │ │ ├── color/
|
||||
│ │ │ │ │ ├── colorExtractor.ts
|
||||
│ │ │ │ │ └── contrastColor.ts
|
||||
│ │ │ │ └── playlist/
|
||||
│ │ │ │ ├── playlistExportImport.ts
|
||||
│ │ │ │ └── playlistManager.ts
|
||||
│ │ │ ├── views/
|
||||
│ │ │ │ ├── home/
|
||||
│ │ │ │ │ └── index.vue
|
||||
│ │ │ │ ├── music/
|
||||
│ │ │ │ │ ├── find.vue
|
||||
│ │ │ │ │ ├── list.vue
|
||||
│ │ │ │ │ ├── local.vue
|
||||
│ │ │ │ │ ├── recent.vue
|
||||
│ │ │ │ │ └── search.vue
|
||||
│ │ │ │ ├── settings/
|
||||
│ │ │ │ │ ├── index.vue
|
||||
│ │ │ │ │ └── plugins.vue
|
||||
│ │ │ │ └── welcome/
|
||||
│ │ │ │ └── index.vue
|
||||
│ │ │ ├── App.vue
|
||||
│ │ │ ├── env.d.ts
|
||||
│ │ │ └── main.ts
|
||||
│ │ ├── auto-imports.d.ts
|
||||
│ │ ├── components.d.ts
|
||||
│ │ └── index.html
|
||||
│ └── types/
|
||||
│ ├── musicCache.ts
|
||||
│ └── songList.ts
|
||||
├── website/
|
||||
│ ├── CeruUse.html
|
||||
│ ├── design.html
|
||||
│ ├── index.html
|
||||
│ ├── pluginDev.html
|
||||
│ ├── script.js
|
||||
│ └── styles.css
|
||||
├── electron-builder.yml
|
||||
├── electron.vite.config.ts
|
||||
├── eslint.config.js
|
||||
├── LICENSE
|
||||
├── package-lock.json
|
||||
├── package.json
|
||||
├── qodana.sarif.json
|
||||
├── qodana.yaml
|
||||
├── README.md
|
||||
├── tsconfig.json
|
||||
├── tsconfig.node.json
|
||||
├── tsconfig.web.json
|
||||
└── yarn.lock
|
||||
```
|
||||
|
||||
## 主要功能
|
||||
|
||||
- 提供插件加载与管理功能,支持通过合规插件获取公开音乐信息
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
provider: generic
|
||||
url: https://update.ceru.shiqianjiang.cn
|
||||
updaterCacheDirName: ceru-music-updater
|
||||
@@ -1,13 +1,19 @@
|
||||
import { defineConfig } from 'vitepress'
|
||||
import note from 'markdown-it-footnote'
|
||||
|
||||
// https://vitepress.dev/reference/site-config
|
||||
export default defineConfig({
|
||||
lang: 'zh-CN',
|
||||
title: 'Ceru Music',
|
||||
base: '/',
|
||||
description:
|
||||
'Ceru Music 是基于 Electron 和 Vue 开发的跨平台桌面音乐播放器工具,一个跨平台的音乐播放器应用,支持基于合规插件获取公开音乐信息与播放功能。',
|
||||
markdown:{
|
||||
config(md){
|
||||
md.use(note)
|
||||
}
|
||||
},
|
||||
themeConfig: {
|
||||
returnToTopLabel: '返回顶部',
|
||||
// https://vitepress.dev/reference/default-theme-config
|
||||
logo: '/logo.svg',
|
||||
nav: [
|
||||
@@ -19,8 +25,16 @@ export default defineConfig({
|
||||
{
|
||||
text: 'CeruMusic',
|
||||
items: [
|
||||
{ text: '使用教程', link: '/guide/' },
|
||||
{ text: '软件设计文档', link: '/guide/design' }
|
||||
{ text: '安装教程', link: '/guide/' },
|
||||
{
|
||||
text: '使用教程',
|
||||
items: [
|
||||
{ text: '音乐播放列表', link: '/guide/used/playList' },
|
||||
]
|
||||
},
|
||||
{ text: '软件设计文档', link: '/guide/design' },
|
||||
{ text: '更新日志', link: '/guide/updateLog' },
|
||||
{ text: '更新计划', link: '/guide/update'}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -48,10 +62,23 @@ export default defineConfig({
|
||||
},
|
||||
search: {
|
||||
provider: 'local'
|
||||
}
|
||||
},
|
||||
outline: {
|
||||
level: [2,4],
|
||||
label: '文章导航'
|
||||
},
|
||||
docFooter: {
|
||||
next: '下一篇',
|
||||
prev: '上一篇'
|
||||
},
|
||||
lastUpdatedText: '上次更新',
|
||||
|
||||
},
|
||||
sitemap: {
|
||||
hostname: 'https://ceru.docs.shiqianjiang.cn'
|
||||
},
|
||||
lastUpdated: true,
|
||||
head: [['link', { rel: 'icon', href: '/logo.svg' }]]
|
||||
head: [['link', { rel: 'icon', href: '/logo.svg' }]],
|
||||
})
|
||||
console.log(process.env.BASE_URL_DOCS)
|
||||
// Smooth scrolling functions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
import './style.css'
|
||||
import './style.scss'
|
||||
import './dark.css'
|
||||
import MyLayout from './MyLayout.vue'
|
||||
// history.scrollRestoration = 'manual'
|
||||
|
||||
@@ -157,26 +157,26 @@ html.dark #app {
|
||||
no-repeat center;
|
||||
|
||||
/* 是否开启网格背景?1 是;0 否 */
|
||||
--bg-grid: 0;
|
||||
--bg-grid: 1;
|
||||
|
||||
/* 已完成的代办事项是否显示删除线?1 是;0 否 */
|
||||
--check-line: 1;
|
||||
|
||||
/* 自动编号格式设置 无需自动编号可全部注释掉或部分注释掉*/
|
||||
/* --autonum-h1: counter(h1) ". ";
|
||||
--autonum-h2: counter(h1) "." counter(h2) ". ";
|
||||
--autonum-h3: counter(h1) "." counter(h2) "." counter(h3) ". ";
|
||||
--autonum-h4: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". ";
|
||||
--autonum-h5: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". ";
|
||||
--autonum-h6: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "; */
|
||||
// --autonum-h1: counter(h1) ". ";
|
||||
// --autonum-h2: counter(h1) "." counter(h2) ". ";
|
||||
// --autonum-h3: counter(h1) "." counter(h2) "." counter(h3) ". ";
|
||||
// --autonum-h4: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". ";
|
||||
// --autonum-h5: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". ";
|
||||
// --autonum-h6: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". ";
|
||||
|
||||
/* 下面是文章内Toc目录自动编号,与上面一样即可 */
|
||||
/* --autonum-h1toc: counter(h1toc) ". ";
|
||||
--autonum-h2toc: counter(h1toc) "." counter(h2toc) ". ";
|
||||
--autonum-h3toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) ". ";
|
||||
--autonum-h4toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) ". ";
|
||||
--autonum-h5toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) ". ";
|
||||
--autonum-h6toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) "." counter(h6toc) ". "; */
|
||||
// --autonum-h1toc: counter(h1toc) ". ";
|
||||
// --autonum-h2toc: counter(h1toc) "." counter(h2toc) ". ";
|
||||
// --autonum-h3toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) ". ";
|
||||
// --autonum-h4toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) ". ";
|
||||
// --autonum-h5toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) ". ";
|
||||
// --autonum-h6toc: counter(h1toc) "." counter(h2toc) "." counter(h3toc) "." counter(h4toc) "." counter(h5toc) "." counter(h6toc) ". ";
|
||||
|
||||
/* 主题颜色 */
|
||||
|
||||
@@ -245,9 +245,7 @@ html.dark #app {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
li {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.vp-doc li div[class*='language-'] {
|
||||
margin: 12px;
|
||||
}
|
||||
@@ -264,3 +262,26 @@ html .vp-doc div[class*='language-'] pre {
|
||||
overflow: hidden;
|
||||
padding: 0.4em;
|
||||
}
|
||||
|
||||
.vp-doc {
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p {
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
// .VPDoc,
|
||||
// .VPDoc .container > .content {
|
||||
// padding: 0 !important;
|
||||
// }
|
||||
.vp-doc li {
|
||||
position: relative;
|
||||
}
|
||||
.VPDoc.has-aside .content-container {
|
||||
max-width: none !important;
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
# Alist 下载配置说明
|
||||
|
||||
## 概述
|
||||
|
||||
项目已从 GitHub 下载方式切换到 Alist API 下载方式,包括:
|
||||
|
||||
- 桌面应用的自动更新功能 (`src/main/autoUpdate.ts`)
|
||||
- 官方网站的下载功能 (`website/script.js`)
|
||||
|
||||
## 配置步骤
|
||||
|
||||
### 1. 修改 Alist 域名
|
||||
|
||||
#### 桌面应用配置
|
||||
|
||||
在 `src/main/autoUpdate.ts` 文件中,Alist 域名已配置为:
|
||||
|
||||
```typescript
|
||||
const ALIST_BASE_URL = 'http://47.96.72.224:5244'
|
||||
```
|
||||
|
||||
#### 网站配置
|
||||
|
||||
在 `website/script.js` 文件中,Alist 域名已配置为:
|
||||
|
||||
```javascript
|
||||
const ALIST_BASE_URL = 'http://47.96.72.224:5244'
|
||||
```
|
||||
|
||||
如需修改域名,请同时更新这两个文件中的 `ALIST_BASE_URL` 配置。
|
||||
|
||||
### 2. 认证信息
|
||||
|
||||
已配置的认证信息:
|
||||
|
||||
- 用户名: `ceruupdata`
|
||||
- 密码: `123456`
|
||||
|
||||
### 3. 文件路径格式
|
||||
|
||||
文件在 Alist 中的路径格式为:`/{version}/{文件名}`
|
||||
|
||||
例如:
|
||||
|
||||
- 版本 `v1.0.0` 的安装包 `app-setup.exe` 路径为:`/v1.0.0/app-setup.exe`
|
||||
|
||||
## 工作原理
|
||||
|
||||
### 桌面应用自动更新
|
||||
|
||||
1. **认证**: 使用配置的用户名和密码向 Alist API 获取认证 token
|
||||
2. **获取文件信息**: 使用 token 调用 `/api/fs/get` 接口获取文件信息和签名
|
||||
3. **下载**: 使用带签名的直接下载链接下载文件
|
||||
4. **备用方案**: 如果 Alist 失败,自动回退到原始 URL 下载
|
||||
|
||||
### 网站下载功能
|
||||
|
||||
1. **获取版本列表**: 调用 `/api/fs/list` 获取根目录下的版本文件夹
|
||||
2. **获取文件列表**: 获取最新版本文件夹中的所有文件
|
||||
3. **平台匹配**: 根据用户平台自动匹配对应的安装包文件
|
||||
4. **生成下载链接**: 获取文件的直接下载链接
|
||||
5. **备用方案**: 如果 Alist 失败,自动回退到 GitHub API
|
||||
|
||||
## API 接口
|
||||
|
||||
### 认证接口
|
||||
|
||||
```
|
||||
POST /api/auth/login
|
||||
{
|
||||
"username": "ceruupdata",
|
||||
"password": "123456"
|
||||
}
|
||||
```
|
||||
|
||||
### 获取文件信息接口
|
||||
|
||||
```
|
||||
POST /api/fs/get
|
||||
Headers: Authorization: {token} # 注意:直接使用 token,不需要 "Bearer " 前缀
|
||||
{
|
||||
"path": "/{version}/{fileName}"
|
||||
}
|
||||
```
|
||||
|
||||
### 获取文件列表接口
|
||||
|
||||
```
|
||||
POST /api/fs/list
|
||||
Headers: Authorization: {token} # 注意:直接使用 token,不需要 "Bearer " 前缀
|
||||
{
|
||||
"path": "/",
|
||||
"password": "",
|
||||
"page": 1,
|
||||
"per_page": 100,
|
||||
"refresh": false
|
||||
}
|
||||
```
|
||||
|
||||
### 下载链接格式
|
||||
|
||||
```
|
||||
{ALIST_BASE_URL}/d/{filePath}?sign={sign}
|
||||
```
|
||||
|
||||
## 测试方法
|
||||
|
||||
项目包含了一个测试脚本来验证 Alist 连接:
|
||||
|
||||
```bash
|
||||
node scripts/test-alist.js
|
||||
```
|
||||
|
||||
该脚本会:
|
||||
|
||||
1. 测试服务器连通性
|
||||
2. 测试用户认证
|
||||
3. 测试文件列表获取
|
||||
4. 测试文件信息获取
|
||||
|
||||
## 备用机制
|
||||
|
||||
两个组件都实现了备用机制:
|
||||
|
||||
### 桌面应用
|
||||
|
||||
- 主要:使用 Alist API 下载
|
||||
- 备用:如果 Alist 失败,使用原始 URL 下载
|
||||
|
||||
### 网站
|
||||
|
||||
- 主要:使用 Alist API 获取版本和文件信息
|
||||
- 备用:如果 Alist 失败,回退到 GitHub API
|
||||
- 最终备用:跳转到 GitHub releases 页面
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保 Alist 服务器可以正常访问
|
||||
2. 确保配置的用户名和密码有权限访问相应的文件路径
|
||||
3. 文件必须按照指定的路径格式存放在 Alist 中
|
||||
4. 网站会自动检测用户操作系统并推荐对应的下载版本
|
||||
5. 所有下载都会显示文件大小信息
|
||||
@@ -1,99 +0,0 @@
|
||||
# Alist 迁移完成总结
|
||||
|
||||
## 修改概述
|
||||
|
||||
项目已成功从 GitHub 下载方式迁移到 Alist API 下载方式。
|
||||
|
||||
## 修改的文件
|
||||
|
||||
### 1. 桌面应用自动更新 (`src/main/autoUpdate.ts`)
|
||||
|
||||
- ✅ 添加了 Alist API 配置
|
||||
- ✅ 实现了 Alist 认证功能
|
||||
- ✅ 实现了 Alist 文件下载功能
|
||||
- ✅ 添加了备用机制(Alist 失败时回退到原始 URL)
|
||||
- ✅ 修复了 Authorization 头格式(使用直接 token 而非 Bearer 格式)
|
||||
|
||||
### 2. 官方网站下载功能 (`website/script.js`)
|
||||
|
||||
- ✅ 添加了 Alist API 配置
|
||||
- ✅ 实现了 Alist 认证功能
|
||||
- ✅ 实现了版本列表获取功能
|
||||
- ✅ 实现了文件列表获取功能
|
||||
- ✅ 实现了平台文件匹配功能
|
||||
- ✅ 添加了多层备用机制(Alist → GitHub API → GitHub 页面)
|
||||
- ✅ 修复了 Authorization 头格式
|
||||
|
||||
### 3. 配置文档
|
||||
|
||||
- ✅ 创建了详细的配置说明 (`docs/alist-config.md`)
|
||||
- ✅ 创建了迁移总结文档 (`docs/alist-migration-summary.md`)
|
||||
|
||||
### 4. 测试脚本
|
||||
|
||||
- ✅ 创建了 Alist 连接测试脚本 (`scripts/test-alist.js`)
|
||||
- ✅ 创建了认证格式测试脚本 (`scripts/auth-test.js`)
|
||||
|
||||
## 配置信息
|
||||
|
||||
### Alist 服务器配置
|
||||
|
||||
- **服务器地址**: `http://47.96.72.224:5244`
|
||||
- **用户名**: `ceruupdate`
|
||||
- **密码**: `123456`
|
||||
- **文件路径格式**: `/{version}/{文件名}`
|
||||
|
||||
### Authorization 头格式
|
||||
|
||||
经过测试确认,正确的格式是:
|
||||
|
||||
```
|
||||
Authorization: {token}
|
||||
```
|
||||
|
||||
**注意**: 不需要 "Bearer " 前缀
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 桌面应用
|
||||
|
||||
1. **智能下载**: 优先使用 Alist API,失败时自动回退
|
||||
2. **进度显示**: 支持下载进度显示和节流
|
||||
3. **错误处理**: 完善的错误处理和日志记录
|
||||
|
||||
### 网站
|
||||
|
||||
1. **自动检测**: 自动检测用户操作系统并推荐对应版本
|
||||
2. **版本信息**: 自动获取最新版本信息和文件大小
|
||||
3. **多层备用**: Alist → GitHub API → GitHub 页面的三层备用机制
|
||||
4. **用户体验**: 加载状态、成功通知、错误提示
|
||||
|
||||
## 测试结果
|
||||
|
||||
✅ **Alist 连接测试**: 通过
|
||||
✅ **认证测试**: 通过
|
||||
✅ **文件列表获取**: 通过
|
||||
✅ **Authorization 头格式**: 已修复并验证
|
||||
|
||||
## 可用文件
|
||||
|
||||
测试显示 Alist 服务器当前包含以下文件:
|
||||
|
||||
- `v1.2.1/` (版本目录)
|
||||
- `1111`
|
||||
- `L3YxLjIuMS8tMS4yLjEtYXJtNjQtbWFjLnppcA==`
|
||||
- `file2.msi`
|
||||
- `file.msi`
|
||||
|
||||
## 后续维护
|
||||
|
||||
1. **添加新版本**: 在 Alist 中创建新的版本目录(如 `v1.2.2/`)
|
||||
2. **上传文件**: 将对应平台的安装包上传到版本目录中
|
||||
3. **文件命名**: 确保文件名包含平台标识(如 `windows`, `mac`, `linux` 等)
|
||||
|
||||
## 备注
|
||||
|
||||
- 所有修改都保持了向后兼容性
|
||||
- 实现了完善的错误处理和备用机制
|
||||
- 用户体验不会因为迁移而受到影响
|
||||
- 可以随时回退到 GitHub 下载方式
|
||||
@@ -1,105 +1,122 @@
|
||||
---
|
||||
layout: doc
|
||||
---
|
||||
|
||||
# CeruMusic 插件开发文档
|
||||
# CeruMusic 插件开发指南
|
||||
|
||||
## 概述
|
||||
|
||||
本文档介绍如何为 CeruMusic 开发音乐源插件。CeruMusic 插件是运行在沙箱环境中的 JavaScript 模块,用于从各种音乐平台获取音乐资源。
|
||||
CeruMusic 支持两种类型的插件:
|
||||
1. **CeruMusic 原生插件**:基于 CeruMusic API 的插件格式
|
||||
2. **LX 兼容插件**:兼容 LX Music 的事件驱动插件格式
|
||||
|
||||
## 插件结构
|
||||
本文档将详细介绍如何开发这两种类型的插件。
|
||||
|
||||
### 基本结构
|
||||
## 文件要求
|
||||
|
||||
每个 CeruMusic 插件必须导出以下三个核心组件:
|
||||
- **编码格式**:UTF-8
|
||||
- **编程语言**:JavaScript (支持 ES6+ 语法)
|
||||
- **文件扩展名**:`.js`
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
pluginInfo, // 插件信息
|
||||
sources, // 支持的音源
|
||||
musicUrl // 获取音乐链接的函数
|
||||
}
|
||||
```
|
||||
## 插件信息注释
|
||||
|
||||
# 完整示例
|
||||
所有插件文件的开头必须包含以下注释格式:
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* 示例音乐插件
|
||||
* @author 开发者名称
|
||||
* @name 插件名称
|
||||
* @description 插件描述
|
||||
* @version 1.0.0
|
||||
* @author 作者名称
|
||||
* @homepage https://example.com
|
||||
*/
|
||||
```
|
||||
|
||||
### 注释字段说明
|
||||
|
||||
- `@name`:插件名称,建议不超过 24 个字符
|
||||
- `@description`:插件描述,建议不超过 36 个字符(可选)
|
||||
- `@version`:版本号(可选)
|
||||
- `@author`:作者名称(可选)
|
||||
- `@homepage`:主页地址(可选)
|
||||
|
||||
---
|
||||
|
||||
## CeruMusic 原生插件开发
|
||||
|
||||
首先 `澜音` 插件是面向 方法的 这意味着你直接导出方法即可为播放器提供音源
|
||||
|
||||
### 基本结构
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @name 示例音乐源
|
||||
* @description CeruMusic 原生插件示例
|
||||
* @version 1.0.0
|
||||
* @author CeruMusic Team
|
||||
*/
|
||||
|
||||
// 1. 插件信息
|
||||
// 插件信息
|
||||
const pluginInfo = {
|
||||
name: '示例音源插件',
|
||||
version: '1.0.0',
|
||||
author: '开发者名称',
|
||||
description: '这是一个示例音乐源插件'
|
||||
}
|
||||
name: "示例音乐源",
|
||||
version: "1.0.0",
|
||||
author: "CeruMusic Team",
|
||||
description: "这是一个示例插件"
|
||||
};
|
||||
|
||||
// 2. 支持的音源配置
|
||||
// 支持的音源配置
|
||||
const sources = {
|
||||
demo: {
|
||||
name: '示例音源',
|
||||
type: 'music',
|
||||
qualitys: ['128k', '320k', 'flac']
|
||||
kw:{
|
||||
name: "酷我音乐",
|
||||
qualities: ['128k', '320k', 'flac', 'flac24bit']
|
||||
},
|
||||
demo2: {
|
||||
name: '示例音源2',
|
||||
type: 'music',
|
||||
qualitys: ['128k', '320k']
|
||||
tx:{
|
||||
name: "QQ音乐",
|
||||
qualities: ['128k', '320k', 'flac']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 3. 获取音乐URL的核心函数
|
||||
// 获取音乐链接的主要方法
|
||||
async function musicUrl(source, musicInfo, quality) {
|
||||
// 从 cerumusic 对象获取 API
|
||||
const { request, env, version } = cerumusic
|
||||
try {
|
||||
// 使用 cerumusic API 发送 HTTP 请求
|
||||
const result = await cerumusic.request('https://api.example.com/music', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
...你的其他参数 可以 是密钥或者其他...
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: musicInfo.id,
|
||||
quality: quality
|
||||
})
|
||||
});
|
||||
|
||||
// 构建请求参数
|
||||
const songId = musicInfo.hash ?? musicInfo.songmid
|
||||
const apiUrl = `https://api.example.com/music/${source}/${songId}/${quality}`
|
||||
|
||||
console.log(`[${pluginInfo.name}] 请求音乐链接: ${apiUrl}`)
|
||||
|
||||
// 发起网络请求
|
||||
const { body, statusCode } = await request(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': `cerumusic-${env}/${version}`
|
||||
if (result.statusCode === 200 && result.body.url) {
|
||||
return result.body.url;
|
||||
} else {
|
||||
throw new Error('获取音乐链接失败');
|
||||
}
|
||||
})
|
||||
|
||||
// 处理响应
|
||||
if (statusCode !== 200 || body.code !== 200) {
|
||||
const errorMessage = body.msg || `接口错误 (HTTP: ${statusCode})`
|
||||
console.error(`[${pluginInfo.name}] Error: ${errorMessage}`)
|
||||
throw new Error(errorMessage)
|
||||
} catch (error) {
|
||||
console.error('获取音乐链接时发生错误:', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log(`[${pluginInfo.name}] 获取成功: ${body.url}`)
|
||||
return body.url
|
||||
}
|
||||
|
||||
// 4. 可选:获取封面图片
|
||||
// 获取歌曲封面(可选)
|
||||
async function getPic(source, musicInfo) {
|
||||
const { request } = cerumusic
|
||||
const songId = musicInfo.hash ?? musicInfo.songmid
|
||||
|
||||
const { body } = await request(`https://api.example.com/pic/${source}/${songId}`)
|
||||
return body.picUrl
|
||||
try {
|
||||
const result = await cerumusic.request(`https://api.example.com/pic/${musicInfo.id}`);
|
||||
return result.body.picUrl;
|
||||
} catch (error) {
|
||||
throw new Error('获取封面失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 可选:获取歌词
|
||||
// 获取歌词(可选)
|
||||
async function getLyric(source, musicInfo) {
|
||||
const { request } = cerumusic
|
||||
const songId = musicInfo.hash ?? musicInfo.songmid
|
||||
|
||||
const { body } = await request(`https://api.example.com/lyric/${source}/${songId}`)
|
||||
return body.lyric
|
||||
try {
|
||||
const result = await cerumusic.request(`https://api.example.com/lyric/${musicInfo.id}`);
|
||||
return result.body.lyric;
|
||||
} catch (error) {
|
||||
throw new Error('获取歌词失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 导出插件
|
||||
@@ -107,279 +124,549 @@ module.exports = {
|
||||
pluginInfo,
|
||||
sources,
|
||||
musicUrl,
|
||||
getPic, // 可选
|
||||
getLyric // 可选
|
||||
getPic, // 可选
|
||||
getLyric // 可选
|
||||
};
|
||||
```
|
||||
|
||||
> #### PS:
|
||||
>
|
||||
> - `sources key` 取值
|
||||
>
|
||||
> - wy 网易云音乐 |
|
||||
> - tx QQ音乐 |
|
||||
> - kg 酷狗音乐 |
|
||||
> - mg 咪咕音乐 |
|
||||
> - kw 酷我音乐
|
||||
>
|
||||
> - 导出
|
||||
>
|
||||
> ```javascript
|
||||
> module.exports = {
|
||||
> sources, // 你的音源支持
|
||||
> };
|
||||
> ```
|
||||
>
|
||||
> - 支持的音质 ` sources.qualities: ['128k', '320k', 'flac']`
|
||||
>
|
||||
> - `128k`: 128kbps
|
||||
> - `320k`: 320kbps
|
||||
> - `flac`: FLAC 无损
|
||||
> - `flac24bit`: 24bit FLAC
|
||||
> - `hires`: Hi-Res 高解析度
|
||||
> - `atmos`: 杜比全景声
|
||||
> - `master`: 母带音质
|
||||
|
||||
|
||||
|
||||
### CeruMusic API 参考
|
||||
|
||||
#### cerumusic.request(url, options)
|
||||
|
||||
HTTP 请求方法,返回 Promise。
|
||||
|
||||
**参数:**
|
||||
- `url` (string): 请求地址
|
||||
- `options` (object): 请求选项
|
||||
- `method`: 请求方法 (GET, POST, PUT, DELETE 等)
|
||||
- `headers`: 请求头对象
|
||||
- `body`: 请求体
|
||||
- `timeout`: 超时时间(毫秒)
|
||||
|
||||
**返回值:**
|
||||
```javascript
|
||||
{
|
||||
statusCode: 200,
|
||||
headers: {...},
|
||||
body: {...} // 自动解析的响应体
|
||||
}
|
||||
```
|
||||
|
||||
## 详细说明
|
||||
#### cerumusic.utils
|
||||
|
||||
### 1. pluginInfo 对象
|
||||
|
||||
插件的基本信息,必须包含以下字段:
|
||||
工具方法集合:
|
||||
|
||||
```javascript
|
||||
const pluginInfo = {
|
||||
name: '插件名称', // 必需:插件显示名称
|
||||
version: '1.0.0', // 必需:版本号
|
||||
author: '作者名', // 必需:作者信息
|
||||
description: '插件描述' // 必需:功能描述
|
||||
}
|
||||
// Buffer 操作
|
||||
cerumusic.utils.buffer.from(data, encoding)
|
||||
cerumusic.utils.buffer.bufToString(buffer, encoding)
|
||||
|
||||
// 加密工具
|
||||
cerumusic.utils.crypto.md5(str)
|
||||
cerumusic.utils.crypto.randomBytes(size)
|
||||
cerumusic.utils.crypto.aesEncrypt(data, mode, key, iv)
|
||||
cerumusic.utils.crypto.rsaEncrypt(data, key)
|
||||
```
|
||||
|
||||
### 2. sources 对象
|
||||
#### cerumusic.NoticeCenter(type, data)
|
||||
|
||||
定义插件支持的音源,键为音源标识,值为音源配置:
|
||||
发送通知到用户界面:
|
||||
|
||||
```javascript
|
||||
const sources = {
|
||||
// 音源标识(用于API调用)
|
||||
source_id: {
|
||||
name: '音源显示名称', // 必需:用户看到的名称
|
||||
type: 'music', // 必需:固定为 'music'
|
||||
qualitys: [
|
||||
// 必需:支持的音质列表
|
||||
'128k', // 标准音质
|
||||
'320k', // 高音质
|
||||
'flac', // 无损音质
|
||||
'flac24bit', // 24位无损
|
||||
'hires' // 高解析度
|
||||
]
|
||||
cerumusic.NoticeCenter('info', {
|
||||
title: '通知标题',
|
||||
content: '通知内容',
|
||||
url: 'https://example.com', // 可选 当通知为update 版本跟新可传
|
||||
version: '版本号', // 当通知为update 版本跟新可传
|
||||
pluginInfo: {
|
||||
name: '插件名称',
|
||||
type: 'cr', // 固定唯一标识
|
||||
}// 当通知为update 版本跟新可传
|
||||
});
|
||||
```
|
||||
|
||||
**通知类型:**
|
||||
- `'info'`: 信息通知
|
||||
- `'success'`: 成功通知
|
||||
- `'warn'`: 警告通知
|
||||
- `'error'`: 错误通知
|
||||
- `'update'`: 更新通知
|
||||
|
||||
---
|
||||
|
||||
## LX 兼容插件开发 引用于落雪官网改编
|
||||
|
||||
CeruMusic 完全兼容 LX Music 的插件格式,支持事件驱动的开发模式。
|
||||
|
||||
### 基本结构
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @name 测试音乐源
|
||||
* @description 我只是一个测试音乐源哦
|
||||
* @version 1.0.0
|
||||
* @author xxx
|
||||
* @homepage http://xxx
|
||||
*/
|
||||
|
||||
const { EVENT_NAMES, request, on, send } = globalThis.lx
|
||||
|
||||
// 音质配置
|
||||
const qualitys = {
|
||||
kw: {
|
||||
'128k': '128',
|
||||
'320k': '320',
|
||||
flac: 'flac',
|
||||
flac24bit: 'flac24bit',
|
||||
},
|
||||
local: {},
|
||||
}
|
||||
|
||||
// HTTP 请求封装
|
||||
const httpRequest = (url, options) => new Promise((resolve, reject) => {
|
||||
request(url, options, (err, resp) => {
|
||||
if (err) return reject(err)
|
||||
resolve(resp.body)
|
||||
})
|
||||
})
|
||||
|
||||
// API 实现
|
||||
const apis = {
|
||||
kw: {
|
||||
musicUrl({ songmid }, quality) {
|
||||
return httpRequest('http://xxx').then(data => {
|
||||
return data.url
|
||||
})
|
||||
},
|
||||
},
|
||||
local: {
|
||||
musicUrl(info) {
|
||||
return httpRequest('http://xxx').then(data => {
|
||||
return data.url
|
||||
})
|
||||
},
|
||||
pic(info) {
|
||||
return httpRequest('http://xxx').then(data => {
|
||||
return data.url
|
||||
})
|
||||
},
|
||||
lyric(info) {
|
||||
return httpRequest('http://xxx').then(data => {
|
||||
return {
|
||||
lyric: '...', // 歌曲歌词
|
||||
tlyric: '...', // 翻译歌词,没有可为 null
|
||||
rlyric: '...', // 罗马音歌词,没有可为 null
|
||||
lxlyric: '...', // lx 逐字歌词,没有可为 null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. musicUrl 函数
|
||||
|
||||
获取音乐播放链接的核心函数:
|
||||
|
||||
```javascript
|
||||
async function musicUrl(source, musicInfo, quality) {
|
||||
// source: 音源标识(sources 对象的键)
|
||||
// musicInfo: 歌曲信息对象
|
||||
// quality: 请求的音质
|
||||
// 返回: Promise<string> - 音乐播放链接
|
||||
}
|
||||
```
|
||||
|
||||
#### musicInfo 对象结构
|
||||
|
||||
```javascript
|
||||
const musicInfo = {
|
||||
songmid: '歌曲ID', // 歌曲标识符
|
||||
hash: '歌曲哈希', // 备用标识符
|
||||
title: '歌曲标题', // 歌曲名称
|
||||
artist: '艺术家', // 演唱者
|
||||
album: '专辑名' // 专辑信息
|
||||
// ... 其他可能的字段
|
||||
}
|
||||
```
|
||||
|
||||
## 可用 API
|
||||
|
||||
### cerumusic 对象
|
||||
|
||||
插件运行时可以访问 `cerumusic` 全局对象:
|
||||
|
||||
```javascript
|
||||
const { request, env, version, utils } = cerumusic
|
||||
```
|
||||
|
||||
#### request 函数
|
||||
|
||||
用于发起 HTTP 请求:
|
||||
|
||||
```javascript
|
||||
// Promise 模式
|
||||
const response = await request(url, options)
|
||||
|
||||
// Callback 模式
|
||||
request(url, options, (error, response) => {
|
||||
if (error) {
|
||||
console.error('请求失败:', error)
|
||||
return
|
||||
// 注册 API 请求事件
|
||||
on(EVENT_NAMES.request, ({ source, action, info }) => {
|
||||
switch (action) {
|
||||
case 'musicUrl':
|
||||
return apis[source].musicUrl(info.musicInfo, qualitys[source][info.type])
|
||||
case 'lyric':
|
||||
return apis[source].lyric(info.musicInfo)
|
||||
case 'pic':
|
||||
return apis[source].pic(info.musicInfo)
|
||||
}
|
||||
console.log('响应:', response)
|
||||
})
|
||||
|
||||
// 发送初始化完成事件
|
||||
send(EVENT_NAMES.inited, {
|
||||
openDevTools: false, // 是否打开开发者工具
|
||||
sources: {
|
||||
kw: {
|
||||
name: '酷我音乐',
|
||||
type: 'music',
|
||||
actions: ['musicUrl'],
|
||||
qualitys: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
},
|
||||
local: {
|
||||
name: '本地音乐',
|
||||
type: 'music',
|
||||
actions: ['musicUrl', 'lyric', 'pic'],
|
||||
qualitys: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
**参数说明:**
|
||||
### LX API 参考
|
||||
|
||||
- `url` (string): 请求地址
|
||||
- `options` (Object): 请求选项
|
||||
- `method`: HTTP 方法 ('GET', 'POST', 等)
|
||||
- `headers`: 请求头对象
|
||||
- `body`: 请求体(POST 请求时)
|
||||
#### globalThis.lx.EVENT_NAMES
|
||||
|
||||
**响应格式:**
|
||||
事件名称常量:
|
||||
|
||||
- `inited`: 初始化完成事件
|
||||
- `request`: API 请求事件
|
||||
- `updateAlert`: 更新提示事件
|
||||
|
||||
#### globalThis.lx.on(eventName, handler)
|
||||
|
||||
注册事件监听器:
|
||||
|
||||
```javascript
|
||||
{
|
||||
body: {}, // 解析后的响应体
|
||||
statusCode: 200, // HTTP 状态码
|
||||
headers: {} // 响应头
|
||||
}
|
||||
lx.on(lx.EVENT_NAMES.request, ({ source, action, info }) => {
|
||||
// 必须返回 Promise
|
||||
return Promise.resolve(result);
|
||||
});
|
||||
```
|
||||
|
||||
#### utils 对象
|
||||
#### globalThis.lx.send(eventName, data)
|
||||
|
||||
提供实用工具函数:
|
||||
发送事件:
|
||||
|
||||
```javascript
|
||||
const { utils } = cerumusic
|
||||
// 发送初始化事件
|
||||
lx.send(lx.EVENT_NAMES.inited, {
|
||||
openDevTools: false,
|
||||
sources: {...}
|
||||
});
|
||||
|
||||
// 发送更新提示
|
||||
lx.send(lx.EVENT_NAMES.updateAlert, {
|
||||
log: '更新日志\n修复了一些问题',
|
||||
updateUrl: 'https://example.com/update'
|
||||
});
|
||||
```
|
||||
|
||||
#### globalThis.lx.request(url, options, callback)
|
||||
|
||||
HTTP 请求方法:
|
||||
|
||||
```javascript
|
||||
lx.request('https://api.example.com', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
timeout: 10000
|
||||
}, (err, resp) => {
|
||||
if (err) {
|
||||
console.error('请求失败:', err);
|
||||
return;
|
||||
}
|
||||
console.log('响应:', resp.body);
|
||||
});
|
||||
```
|
||||
|
||||
#### globalThis.lx.utils
|
||||
|
||||
工具方法:
|
||||
|
||||
```javascript
|
||||
// Buffer 操作
|
||||
const buffer = utils.buffer.from('hello', 'utf8')
|
||||
const string = utils.buffer.bufToString(buffer, 'utf8')
|
||||
lx.utils.buffer.from(data, encoding)
|
||||
lx.utils.buffer.bufToString(buffer, encoding)
|
||||
|
||||
// 加密工具
|
||||
lx.utils.crypto.md5(str)
|
||||
lx.utils.crypto.aesEncrypt(buffer, mode, key, iv)
|
||||
lx.utils.crypto.randomBytes(size)
|
||||
lx.utils.crypto.rsaEncrypt(buffer, key)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 音源配置
|
||||
|
||||
### 支持的音源 ID
|
||||
|
||||
- `kw`: 酷我音乐
|
||||
- `kg`: 酷狗音乐
|
||||
- `tx`: QQ音乐
|
||||
- `wy`: 网易云音乐
|
||||
- `mg`: 咪咕音乐
|
||||
- `local`: 本地音乐
|
||||
|
||||
### 支持的音质
|
||||
|
||||
- `128k`: 128kbps
|
||||
- `320k`: 320kbps
|
||||
- `flac`: FLAC 无损
|
||||
- `flac24bit`: 24bit FLAC
|
||||
- `hires`: Hi-Res 高解析度
|
||||
- `atmos`: 杜比全景声
|
||||
- `master`: 母带音质
|
||||
|
||||
---
|
||||
|
||||
## 错误处理
|
||||
|
||||
### 最佳实践
|
||||
|
||||
1. **总是检查 API 响应状态**
|
||||
```javascript
|
||||
async function musicUrl(source, musicInfo, quality) {
|
||||
try {
|
||||
// 参数验证
|
||||
if (!musicInfo || !musicInfo.id) {
|
||||
throw new Error('音乐信息不完整');
|
||||
}
|
||||
|
||||
```javascript
|
||||
if (statusCode !== 200 || body.code !== 200) {
|
||||
throw new Error(`请求失败: ${body.msg || '未知错误'}`)
|
||||
}
|
||||
```
|
||||
// API 调用
|
||||
const result = await cerumusic.request(url, options);
|
||||
|
||||
// 结果验证
|
||||
if (!result || result.statusCode !== 200) {
|
||||
throw new Error(`API 请求失败: ${result?.statusCode || 'Unknown'}`);
|
||||
}
|
||||
|
||||
2. **提供有意义的错误信息**
|
||||
if (!result.body || !result.body.url) {
|
||||
throw new Error('返回数据格式错误');
|
||||
}
|
||||
|
||||
```javascript
|
||||
console.error(`[${pluginInfo.name}] Error: ${errorMessage}`)
|
||||
throw new Error(errorMessage)
|
||||
```
|
||||
|
||||
3. **处理网络异常**
|
||||
```javascript
|
||||
try {
|
||||
const response = await request(url, options)
|
||||
// 处理响应
|
||||
} catch (error) {
|
||||
console.error(`[${pluginInfo.name}] 网络请求失败:`, error.message)
|
||||
throw new Error(`网络错误: ${error.message}`)
|
||||
}
|
||||
```
|
||||
return result.body.url;
|
||||
} catch (error) {
|
||||
// 记录错误日志
|
||||
console.error(`[${source}] 获取音乐链接失败:`, error.message);
|
||||
|
||||
// 重新抛出错误供上层处理
|
||||
throw new Error(`获取 ${source} 音乐链接失败: ${error.message}`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 常见错误类型
|
||||
|
||||
- **网络错误**: 无法连接到 API 服务器
|
||||
- **认证错误**: API 密钥无效或过期
|
||||
- **参数错误**: 请求参数格式不正确
|
||||
- **资源不存在**: 请求的歌曲不存在
|
||||
- **限流错误**: 请求过于频繁
|
||||
1. **网络错误**: 请求超时、连接失败
|
||||
2. **API 错误**: 接口返回错误状态码
|
||||
3. **数据错误**: 返回数据格式不正确
|
||||
4. **参数错误**: 传入参数不完整或格式错误
|
||||
|
||||
## 事件驱动插件
|
||||
|
||||
对于使用 `lx.on(EVENT_NAMES.request)` 模式的插件,可以使用转换器:
|
||||
|
||||
```javascript
|
||||
// 使用转换器转换事件驱动插件
|
||||
node converter-event-driven.js input-plugin.js output-plugin.js
|
||||
```
|
||||
|
||||
转换后的插件将兼容 CeruMusicPluginHost。
|
||||
---
|
||||
|
||||
## 调试技巧
|
||||
|
||||
### 1. 使用 console.log
|
||||
|
||||
```javascript
|
||||
console.log(`[${pluginInfo.name}] 调试信息:`, data)
|
||||
console.error(`[${pluginInfo.name}] 错误:`, error)
|
||||
console.log('[插件名] 调试信息:', data);
|
||||
console.warn('[插件名] 警告信息:', warning);
|
||||
console.error('[插件名] 错误信息:', error);
|
||||
```
|
||||
|
||||
### 2. 检查请求和响应
|
||||
### 2. LX 插件开发者工具
|
||||
|
||||
```javascript
|
||||
console.log('请求URL:', url)
|
||||
console.log('请求选项:', options)
|
||||
console.log('响应状态:', statusCode)
|
||||
console.log('响应内容:', body)
|
||||
send(EVENT_NAMES.inited, {
|
||||
openDevTools: true, // 开启开发者工具
|
||||
sources: {...}
|
||||
});
|
||||
```
|
||||
|
||||
### 3. 测试插件
|
||||
|
||||
创建测试文件:
|
||||
### 3. 错误捕获
|
||||
|
||||
```javascript
|
||||
const CeruMusicPluginHost = require('./CeruMusicPluginHost')
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('未处理的 Promise 拒绝:', reason);
|
||||
});
|
||||
```
|
||||
|
||||
async function testPlugin() {
|
||||
const host = new CeruMusicPluginHost()
|
||||
await host.loadPlugin('./my-plugin.js')
|
||||
---
|
||||
|
||||
const musicInfo = {
|
||||
songmid: 'test123',
|
||||
title: '测试歌曲'
|
||||
## 性能优化
|
||||
|
||||
### 1. 请求缓存
|
||||
|
||||
```javascript
|
||||
const cache = new Map();
|
||||
|
||||
async function getCachedData(key, fetcher, ttl = 300000) {
|
||||
const cached = cache.get(key);
|
||||
if (cached && Date.now() - cached.timestamp < ttl) {
|
||||
return cached.data;
|
||||
}
|
||||
|
||||
const data = await fetcher();
|
||||
cache.set(key, { data, timestamp: Date.now() });
|
||||
return data;
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 请求超时控制
|
||||
|
||||
```javascript
|
||||
const result = await cerumusic.request(url, {
|
||||
timeout: 10000 // 10秒超时
|
||||
});
|
||||
```
|
||||
|
||||
### 3. 并发控制
|
||||
|
||||
```javascript
|
||||
// 限制并发请求数量
|
||||
const semaphore = new Semaphore(3); // 最多3个并发请求
|
||||
|
||||
async function limitedRequest(url, options) {
|
||||
await semaphore.acquire();
|
||||
try {
|
||||
const url = await host.getMusicUrl('demo', musicInfo, '320k')
|
||||
console.log('成功获取URL:', url)
|
||||
} catch (error) {
|
||||
console.error('测试失败:', error.message)
|
||||
return await cerumusic.request(url, options);
|
||||
} finally {
|
||||
semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
testPlugin()
|
||||
```
|
||||
|
||||
## 发布和分发
|
||||
---
|
||||
|
||||
### 文件结构
|
||||
## 安全注意事项
|
||||
|
||||
```
|
||||
my-plugin/
|
||||
├── plugin.js # 主插件文件
|
||||
├── package.json # 包信息(可选)
|
||||
├── README.md # 说明文档
|
||||
└── test.js # 测试文件(可选)
|
||||
### 1. 输入验证
|
||||
|
||||
```javascript
|
||||
function validateMusicInfo(musicInfo) {
|
||||
if (!musicInfo || typeof musicInfo !== 'object') {
|
||||
throw new Error('音乐信息格式错误');
|
||||
}
|
||||
|
||||
if (!musicInfo.id || typeof musicInfo.id !== 'string') {
|
||||
throw new Error('音乐 ID 无效');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
### 版本管理
|
||||
### 2. URL 验证
|
||||
|
||||
遵循语义化版本规范:
|
||||
```javascript
|
||||
function isValidUrl(url) {
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
return urlObj.protocol === 'http:' || urlObj.protocol === 'https:';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `1.0.0` - 主版本.次版本.修订版本
|
||||
### 3. 敏感信息保护
|
||||
|
||||
```javascript
|
||||
// 不要在日志中输出敏感信息
|
||||
console.log('请求参数:', {
|
||||
...params,
|
||||
token: '***', // 隐藏敏感信息
|
||||
password: '***'
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 插件发布
|
||||
|
||||
### 1. 代码检查清单
|
||||
|
||||
- [ ] 插件信息注释完整
|
||||
- [ ] 错误处理完善
|
||||
- [ ] 性能优化合理
|
||||
- [ ] 安全验证到位
|
||||
- [ ] 测试覆盖充分
|
||||
|
||||
### 2. 测试建议
|
||||
|
||||
```javascript
|
||||
// 单元测试示例
|
||||
async function testMusicUrl() {
|
||||
const testMusicInfo = {
|
||||
id: 'test123',
|
||||
name: '测试歌曲',
|
||||
artist: '测试歌手'
|
||||
};
|
||||
|
||||
try {
|
||||
const url = await musicUrl('kw', testMusicInfo, '320k');
|
||||
console.log('测试通过:', url);
|
||||
} catch (error) {
|
||||
console.error('测试失败:', error);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 版本管理
|
||||
|
||||
使用语义化版本号:
|
||||
- `1.0.0`: 主版本.次版本.修订版本
|
||||
- 主版本:不兼容的 API 修改
|
||||
- 次版本:向下兼容的功能性新增
|
||||
- 修订版本:向下兼容的问题修正
|
||||
|
||||
## 示例插件
|
||||
|
||||
查看项目中的示例:
|
||||
|
||||
- `example-plugin.js` - 基础插件示例
|
||||
- `plugin.js` - 事件驱动插件示例
|
||||
- `fm.js` - 复杂插件示例
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
**Q: 如何处理需要登录的 API?**
|
||||
### Q: 插件加载失败怎么办?
|
||||
|
||||
A: 在请求头中添加认证信息,或使用 Cookie。
|
||||
A: 检查以下几点:
|
||||
1. 文件编码是否为 UTF-8
|
||||
2. 插件信息注释格式是否正确
|
||||
3. JavaScript 语法是否有错误
|
||||
4. 是否正确导出了必需的方法
|
||||
|
||||
**Q: 如何处理加密的 API 响应?**
|
||||
### Q: 如何处理跨域请求?
|
||||
|
||||
A: 在插件中实现解密逻辑,使用 `utils` 对象提供的工具函数。
|
||||
A: CeruMusic 的请求方法不受浏览器跨域限制,可以直接请求任何域名的 API。
|
||||
|
||||
**Q: 插件可以访问文件系统吗?**
|
||||
### Q: 插件如何更新?
|
||||
|
||||
A: 不可以,插件运行在受限的沙箱环境中,无法直接访问文件系统。
|
||||
A: 使用 `cerumusic.NoticeCenter` 事件通知用户更新:
|
||||
|
||||
**Q: 如何优化插件性能?**
|
||||
```javascript
|
||||
cerumusic.NoticeCenter('update',{
|
||||
title:'新版本更新',
|
||||
content:'xxxx',
|
||||
version: 'v1.0.3',
|
||||
url:'https://shiqianjiang.cn',
|
||||
pluginInfo:{
|
||||
type:'cr'
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
A: 减少不必要的网络请求,使用适当的缓存策略,避免阻塞操作。
|
||||
### Q: 如何调试插件?
|
||||
|
||||
## 贡献指南
|
||||
A:
|
||||
1. 使用 `console.log` 输出调试信息 可在设置—>插件管理—>日志 查看调试
|
||||
2. LX 插件可以设置 `openDevTools: true` 打开开发者工具
|
||||
3. 查看 CeruMusic 的插件日志
|
||||
|
||||
1. Fork 项目仓库
|
||||
2. 创建功能分支
|
||||
3. 编写插件代码和测试
|
||||
4. 提交 Pull Request
|
||||
5. 等待代码审查
|
||||
---
|
||||
|
||||
欢迎贡献新的音源插件!
|
||||
## 技术支持
|
||||
|
||||
如有问题或建议,请通过以下方式联系:
|
||||
- GitHub Issues: [CeruMusic Issues](https://github.com/timeshiftsauce/CeruMusic/issues)
|
||||
- Blog (最好登录,否则需要审核): [CeruMusic Blog](https://shiqianjiang.cn/blog/4966904626407280640)
|
||||
|
||||
0
docs/guide/analyze.md
Normal file
BIN
docs/guide/assets/image-20250921130607735.png
Normal file
|
After Width: | Height: | Size: 606 KiB |
12
docs/guide/update.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# 我的-更新计划-欢迎issue
|
||||
|
||||
- [ ] 搜索框可以弄对应的音乐源的排行榜 搜索联想
|
||||
- [ ] 导航上面这几个按钮可以稍微优化一下
|
||||
- [ ] 大熊好暖: 09-21 12:52:25 在搜索歌曲出来后 大熊好暖: 09-21 12:52:34 一般都是双击播放 大熊好暖: 09-21 12:54:16 这个是双击加入播放列表 可以优化 或者可以把这个双击做一个选项,让人选择
|
||||
- [ ] 播放页 样式模板选择 歌词背景律动很有沉浸感,但是黑胶唱片的专辑样式不是很喜欢,希望增加一个选项如图二一样只有圆形专辑封面
|
||||
- [x] 点击搜索框的 源图标实现快速切换
|
||||
- [ ] ai功能完善
|
||||
- [ ] 支持歌词隐藏
|
||||
- [x] 兼容多平台歌单导入
|
||||
- [ ] 软件能不能记住上次打开的窗口大小,每次都要手动拉
|
||||
|
||||
30
docs/guide/updateLog.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# 澜音版本更新日志
|
||||
|
||||
|
||||
|
||||
## 日志
|
||||
|
||||
- ###### 2025-9-17 **(V1.3.2)**
|
||||
|
||||
1. 目录结构调整
|
||||
|
||||
2. **支持插件更新提示**
|
||||
|
||||
**洛雪** 插件请手动重装适配
|
||||
|
||||
3. **debug**
|
||||
|
||||
- SMTC 问题
|
||||
|
||||
- 歌曲缓存播放多次请求和多次缓存问题
|
||||
|
||||
- ###### 2025-9-17 **(V1.3.1)**
|
||||
|
||||
1. **设置功能页**
|
||||
- 缓存路径支持自定义
|
||||
- 下载路径支持自定义
|
||||
2. **debug**
|
||||
- 播放页面唱针可以拖动问题
|
||||
- 播放按钮加载中 因为自动下一曲 导致动画变形问题
|
||||
- **SMTC** 功能 系统显示**未知应用**问题
|
||||
- 播放页歌词**字体粗细**偶现丢失问题
|
||||
BIN
docs/guide/used/assets/image-20250916132204465.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/guide/used/assets/image-20250916132248046.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
docs/guide/used/assets/image-20250916133531421.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
docs/guide/used/assets/image-20250916134406714.png
Normal file
|
After Width: | Height: | Size: 249 KiB |
BIN
docs/guide/used/assets/image-20250916134511291.png
Normal file
|
After Width: | Height: | Size: 255 KiB |
BIN
docs/guide/used/assets/image-20250916134615679.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
docs/guide/used/assets/image-20250916134820742.png
Normal file
|
After Width: | Height: | Size: 449 KiB |
28
docs/guide/used/playList.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# 音乐播放列表-机制分析
|
||||
|
||||
## 基础使用
|
||||
|
||||
1. 默认情况下,播放 **「搜索」「歌单」** 双击中的歌曲时,会自动将该歌曲添加到 **「列表」** 中的末尾后并不会播放,这与手动将歌曲添加到 **「列表」** 等价,亦或是通过点击歌曲前面小三角播放<img src="./assets/image-20250916132248046.png" alt="image-20250916132248046" style="float:right" />可以添加到歌曲开头也可进行该歌曲添加到 **「列表」** 中的开头并播放。歌曲会按照你选择的播放顺序进行播放。
|
||||
2. 对于 **「列表」** 歌曲的顺序可通过展开长按 **1.5s** 后可以进行拖拽排序,歌曲排序实时保存到本地 **LocalStorage**<img src="./assets/image-20250916133531421.png" alt="image-20250916133531421" style="zoom: 20%;" />
|
||||
|
||||
## 歌曲列表的导出和分享
|
||||
|
||||
3. 可进入设置
|
||||
|
||||

|
||||
|
||||
点击 **[播放列表]** =>
|
||||
|
||||

|
||||
|
||||
即可操作你想要的功能
|
||||
|
||||
4. 播放列表还可以导出为歌单
|
||||
|
||||

|
||||
|
||||
歌单将自动选取第一首 **有效封面**[^1] 为歌单
|
||||
|
||||
|
||||
|
||||
[^1]: url正确的歌曲封面
|
||||
84
docs/plugin-notice-test.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// 测试插件通知功能的示例插件
|
||||
// 这个文件可以用来测试 NoticeCenter 功能
|
||||
|
||||
const pluginInfo = {
|
||||
name: "测试通知插件",
|
||||
version: "1.0.0",
|
||||
author: "CeruMusic Team",
|
||||
description: "用于测试插件通知功能的示例插件",
|
||||
type: "cr"
|
||||
}
|
||||
|
||||
const sources = [
|
||||
{
|
||||
name: "test",
|
||||
qualities: ["128k", "320k"]
|
||||
}
|
||||
]
|
||||
|
||||
// 模拟音乐URL获取函数
|
||||
async function musicUrl(source, musicInfo, quality) {
|
||||
console.log('测试插件:获取音乐URL')
|
||||
|
||||
// 测试不同类型的通知
|
||||
setTimeout(() => {
|
||||
// 测试信息通知
|
||||
this.cerumusic.NoticeCenter('info', {
|
||||
title: '信息通知',
|
||||
message: '这是一个信息通知测试',
|
||||
content: '插件正在正常工作'
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
setTimeout(() => {
|
||||
// 测试警告通知
|
||||
this.cerumusic.NoticeCenter('warning', {
|
||||
title: '警告通知',
|
||||
message: '这是一个警告通知测试',
|
||||
content: '请注意某些设置'
|
||||
})
|
||||
}, 2000)
|
||||
|
||||
setTimeout(() => {
|
||||
// 测试成功通知
|
||||
this.cerumusic.NoticeCenter('success', {
|
||||
title: '成功通知',
|
||||
message: '操作已成功完成',
|
||||
content: '音乐URL获取成功'
|
||||
})
|
||||
}, 3000)
|
||||
|
||||
setTimeout(() => {
|
||||
// 测试更新通知
|
||||
this.cerumusic.NoticeCenter('update', {
|
||||
title: '插件更新',
|
||||
message: '发现新版本 v2.0.0,是否立即更新?',
|
||||
url: 'https://example.com/plugin-update.js',
|
||||
version: '2.0.0',
|
||||
pluginInfo: {
|
||||
name: '测试通知插件',
|
||||
type: 'cr',
|
||||
forcedUpdate: false
|
||||
}
|
||||
})
|
||||
}, 4000)
|
||||
|
||||
setTimeout(() => {
|
||||
// 测试错误通知
|
||||
this.cerumusic.NoticeCenter('error', {
|
||||
title: '错误通知',
|
||||
message: '这是一个错误通知测试',
|
||||
error: '模拟的错误信息'
|
||||
})
|
||||
}, 5000)
|
||||
|
||||
// 返回一个测试URL
|
||||
return 'https://example.com/test-music.mp3'
|
||||
}
|
||||
|
||||
// 导出插件
|
||||
module.exports = {
|
||||
pluginInfo,
|
||||
sources,
|
||||
musicUrl
|
||||
}
|
||||
215
docs/plugin-notice-usage.md
Normal file
@@ -0,0 +1,215 @@
|
||||
# 插件通知系统使用说明
|
||||
|
||||
## 概述
|
||||
|
||||
CeruMusic 插件通知系统允许插件向用户显示各种类型的通知对话框,包括信息、警告、错误、成功和更新通知。
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 🎯 支持的通知类型
|
||||
|
||||
1. **信息通知 (info)** - 显示一般信息
|
||||
2. **警告通知 (warning)** - 显示警告信息
|
||||
3. **错误通知 (error)** - 显示错误信息
|
||||
4. **成功通知 (success)** - 显示成功信息
|
||||
5. **更新通知 (update)** - 显示插件更新信息,支持一键更新
|
||||
|
||||
### 🎨 界面特性
|
||||
|
||||
- 使用 TDesign 组件库,界面美观统一
|
||||
- 支持深色主题适配
|
||||
- 响应式设计,移动端友好
|
||||
- 不同通知类型有对应的图标和颜色
|
||||
|
||||
### ⚡ 技术特性
|
||||
|
||||
- 基于 Electron IPC 通信
|
||||
- TypeScript 类型安全
|
||||
- 异步操作支持
|
||||
- 错误处理完善
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 在插件中调用通知
|
||||
|
||||
```javascript
|
||||
// 基本用法
|
||||
this.cerumusic.NoticeCenter(type, data)
|
||||
|
||||
// 信息通知
|
||||
this.cerumusic.NoticeCenter('info', {
|
||||
title: '插件信息',
|
||||
message: '这是一条信息通知',
|
||||
content: '详细的信息内容'
|
||||
})
|
||||
|
||||
// 警告通知
|
||||
this.cerumusic.NoticeCenter('warning', {
|
||||
title: '注意',
|
||||
message: '这是一条警告信息',
|
||||
content: '请检查相关设置'
|
||||
})
|
||||
|
||||
// 错误通知
|
||||
this.cerumusic.NoticeCenter('error', {
|
||||
title: '错误',
|
||||
message: '操作失败',
|
||||
error: '具体的错误信息'
|
||||
})
|
||||
|
||||
// 成功通知
|
||||
this.cerumusic.NoticeCenter('success', {
|
||||
title: '成功',
|
||||
message: '操作已成功完成'
|
||||
})
|
||||
|
||||
// 更新通知(特殊)
|
||||
this.cerumusic.NoticeCenter('update', {
|
||||
title: '插件更新',
|
||||
message: '发现新版本,是否立即更新?',
|
||||
url: 'https://example.com/plugin-update.js',
|
||||
version: '2.0.0',
|
||||
pluginInfo: {
|
||||
name: '插件名称',
|
||||
type: 'cr', // 'cr' 或 'lx'
|
||||
forcedUpdate: false
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### 参数说明
|
||||
|
||||
#### 通用参数 (data 对象)
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| title | string | 否 | 通知标题,不提供时使用默认标题 |
|
||||
| message | string | 否 | 通知消息内容 |
|
||||
| content | string | 否 | 详细内容(与 message 二选一) |
|
||||
|
||||
#### 更新通知特有参数
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| url | string | 是 | 插件更新下载链接 |
|
||||
| version | string | 否 | 新版本号 |
|
||||
| pluginInfo.name | string | 否 | 插件名称 |
|
||||
| pluginInfo.type | 'cr' \| 'lx' | 否 | 插件类型 |
|
||||
| pluginInfo.forcedUpdate | boolean | 否 | 是否强制更新 |
|
||||
|
||||
#### 错误通知特有参数
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| error | string | 否 | 具体错误信息 |
|
||||
|
||||
## 实现原理
|
||||
|
||||
### 架构图
|
||||
|
||||
```
|
||||
插件代码
|
||||
↓ (调用 NoticeCenter)
|
||||
CeruMusicPluginHost
|
||||
↓ (sendPluginNotice)
|
||||
pluginNotice.ts (主进程)
|
||||
↓ (IPC 通信)
|
||||
PluginNoticeDialog.vue (渲染进程)
|
||||
↓ (显示对话框)
|
||||
用户界面
|
||||
```
|
||||
|
||||
### 文件结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── main/
|
||||
│ ├── events/
|
||||
│ │ └── pluginNotice.ts # 主进程通知处理
|
||||
│ └── services/plugin/manager/
|
||||
│ └── CeruMusicPluginHost.ts # 插件主机
|
||||
├── renderer/src/
|
||||
│ ├── components/
|
||||
│ │ └── PluginNoticeDialog.vue # 通知对话框组件
|
||||
│ └── App.vue # 主应用(注册组件)
|
||||
└── preload/
|
||||
└── index.ts # IPC API 定义
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
### 使用测试插件
|
||||
|
||||
1. 将 `docs/plugin-notice-test.js` 作为插件加载
|
||||
2. 调用插件的 `musicUrl` 方法
|
||||
3. 观察不同类型的通知是否正确显示
|
||||
|
||||
### 测试场景
|
||||
|
||||
- [x] 信息通知显示
|
||||
- [x] 警告通知显示
|
||||
- [x] 错误通知显示
|
||||
- [x] 成功通知显示
|
||||
- [x] 更新通知显示(带更新按钮)
|
||||
- [x] 更新按钮功能
|
||||
- [x] 对话框关闭功能
|
||||
- [x] 响应式布局
|
||||
- [x] 深色主题适配
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **URL 验证**: 更新通知的 URL 必须是有效的 HTTP/HTTPS 链接
|
||||
2. **错误处理**: 所有通知操作都有完善的错误处理机制
|
||||
3. **性能考虑**: 避免频繁发送通知,可能影响用户体验
|
||||
4. **类型安全**: 使用 TypeScript 确保参数类型正确
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 未来可能的增强
|
||||
|
||||
- [ ] 通知历史记录
|
||||
- [ ] 通知优先级系统
|
||||
- [ ] 批量通知管理
|
||||
- [ ] 自定义通知样式
|
||||
- [ ] 通知声音提醒
|
||||
- [ ] 通知位置自定义
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **通知不显示**
|
||||
- 检查主窗口是否存在
|
||||
- 确认 IPC 通信是否正常
|
||||
- 查看控制台错误信息
|
||||
|
||||
2. **更新按钮无响应**
|
||||
- 确认更新 URL 是否有效
|
||||
- 检查网络连接
|
||||
- 查看主进程日志
|
||||
|
||||
3. **样式显示异常**
|
||||
- 确认 TDesign 组件库已正确加载
|
||||
- 检查 CSS 样式是否冲突
|
||||
- 验证主题配置
|
||||
|
||||
### 调试方法
|
||||
|
||||
```javascript
|
||||
// 在插件中添加调试日志
|
||||
console.log('[Plugin] 发送通知:', type, data)
|
||||
|
||||
// 在渲染进程中监听通知
|
||||
window.api.on('plugin-notice', (_, notice) => {
|
||||
console.log('[Renderer] 收到通知:', notice)
|
||||
})
|
||||
```
|
||||
|
||||
## 更新日志
|
||||
|
||||
### v1.0.0 (2025-09-20)
|
||||
- ✨ 初始版本发布
|
||||
- ✨ 支持 5 种通知类型
|
||||
- ✨ 完整的 TypeScript 类型定义
|
||||
- ✨ 响应式设计和深色主题支持
|
||||
- ✨ 完善的错误处理机制
|
||||
@@ -1,150 +0,0 @@
|
||||
# WebDAV 同步配置指南
|
||||
|
||||
本项目包含两个 GitHub Actions 工作流,用于自动将 GitHub Releases 同步到 alist(WebDAV 服务器)。
|
||||
|
||||
## 工作流说明
|
||||
|
||||
### 1. 手动同步工作流 (`sync-releases-to-webdav.yml`)
|
||||
|
||||
- **触发方式**: 手动触发 (workflow_dispatch)
|
||||
- **功能**: 同步现有的所有版本或指定版本到 WebDAV
|
||||
- **参数**:
|
||||
- `tag_name`: 可选,指定要同步的版本标签(如 v1.0.0),留空则同步所有版本
|
||||
|
||||
### 2. 自动同步工作流 (集成在 `main.yml` 中)
|
||||
|
||||
- **触发方式**: 在 AutoBuild 完成后自动触发
|
||||
- **功能**: 自动将新构建的版本同步到 WebDAV
|
||||
- **参数**: 无需手动设置,自动获取发布信息
|
||||
|
||||
### 3. 独立自动同步工作流 (`auto-sync-release.yml`)
|
||||
|
||||
- **触发方式**: 当新版本发布时自动触发 (on release published)
|
||||
- **功能**: 备用的自动同步机制
|
||||
- **参数**: 无需手动设置,自动获取发布信息
|
||||
|
||||
## 配置要求
|
||||
|
||||
在 GitHub 仓库的 Settings > Secrets and variables > Actions 中添加以下密钥:
|
||||
|
||||
### 必需的 Secrets
|
||||
|
||||
1. **WEBDAV_BASE_URL**
|
||||
- 描述: WebDAV 服务器的基础 URL
|
||||
- 示例: `https://your-alist-domain.com/dav`
|
||||
- 注意: 不要在末尾添加斜杠
|
||||
|
||||
2. **WEBDAV_USERNAME**
|
||||
- 描述: WebDAV 服务器的用户名
|
||||
- 示例: `admin`
|
||||
|
||||
3. **WEBDAV_PASSWORD**
|
||||
- 描述: WebDAV 服务器的密码
|
||||
- 示例: `your-password`
|
||||
|
||||
4. **GITHUB_TOKEN**
|
||||
- 描述: GitHub 访问令牌(通常自动提供)
|
||||
- 注意: 如果默认的 `GITHUB_TOKEN` 权限不足,可能需要创建个人访问令牌
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 手动同步现有版本
|
||||
|
||||
1. 进入 GitHub 仓库的 Actions 页面
|
||||
2. 选择 "Sync Existing Releases to WebDAV" 工作流
|
||||
3. 点击 "Run workflow"
|
||||
4. 可选择指定版本标签或留空同步所有版本
|
||||
5. 点击 "Run workflow" 开始执行
|
||||
|
||||
### 自动同步新版本
|
||||
|
||||
现在有两种自动同步方式:
|
||||
|
||||
1. **集成同步** (推荐): 在主构建工作流 (`main.yml`) 中集成了 WebDAV 同步,当您推送 `v*` 标签时,会自动执行:
|
||||
- 构建应用 → 创建 Release → 同步到 WebDAV
|
||||
2. **独立同步**: 当您手动发布 Release 时,`auto-sync-release.yml` 工作流会自动触发
|
||||
|
||||
推荐使用集成同步方式,因为它确保了构建和同步的一致性。
|
||||
|
||||
## 文件结构
|
||||
|
||||
同步后的文件将按以下结构存储在 alist 中:
|
||||
|
||||
```
|
||||
/yd/ceru/
|
||||
├── v1.0.0/
|
||||
│ ├── app-setup.exe
|
||||
│ ├── app.dmg
|
||||
│ └── app.AppImage
|
||||
├── v1.1.0/
|
||||
│ ├── app-setup.exe
|
||||
│ ├── app.dmg
|
||||
│ └── app.AppImage
|
||||
└── ...
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **上传失败**
|
||||
- 检查 WebDAV 服务器是否正常运行
|
||||
- 验证用户名和密码是否正确
|
||||
- 确认 WebDAV URL 格式正确
|
||||
|
||||
2. **权限错误**
|
||||
- 确保 WebDAV 用户有写入权限
|
||||
- 检查目标目录是否存在且可写
|
||||
|
||||
3. **文件大小不匹配**
|
||||
- 网络问题导致下载不完整
|
||||
- GitHub API 限制或临时故障
|
||||
|
||||
4. **目录创建失败**
|
||||
- WebDAV 服务器不支持 MKCOL 方法
|
||||
- 权限不足或路径错误
|
||||
|
||||
### 调试步骤
|
||||
|
||||
1. 查看 Actions 运行日志
|
||||
2. 检查 WebDAV 服务器日志
|
||||
3. 验证所有 Secrets 配置正确
|
||||
4. 测试 WebDAV 连接是否正常
|
||||
|
||||
## 安全注意事项
|
||||
|
||||
1. **密钥管理**
|
||||
- 不要在代码中硬编码密码
|
||||
- 定期更换 WebDAV 密码
|
||||
- 使用强密码
|
||||
|
||||
2. **权限控制**
|
||||
- 为 WebDAV 用户设置最小必要权限
|
||||
- 考虑使用专用的同步账户
|
||||
|
||||
3. **网络安全**
|
||||
- 建议使用 HTTPS 连接
|
||||
- 考虑 IP 白名单限制
|
||||
|
||||
## 自定义配置
|
||||
|
||||
如需修改同步路径或其他配置,请编辑对应的工作流文件:
|
||||
|
||||
- 修改存储路径: 更改 `remote_path` 变量
|
||||
- 调整重试逻辑: 修改错误处理部分
|
||||
- 添加通知: 集成 Slack、邮件等通知服务
|
||||
|
||||
## 支持的文件类型
|
||||
|
||||
工作流支持同步所有类型的 Release 资源文件,包括但不限于:
|
||||
|
||||
- 可执行文件 (.exe, .dmg, .AppImage)
|
||||
- 压缩包 (.zip, .tar.gz, .7z)
|
||||
- 安装包 (.msi, .deb, .rpm)
|
||||
- 其他二进制文件
|
||||
|
||||
## 版本兼容性
|
||||
|
||||
- GitHub Actions: 支持最新版本
|
||||
- alist: 支持 WebDAV 协议的版本
|
||||
- 操作系统: Ubuntu Latest (工作流运行环境)
|
||||
@@ -36,14 +36,16 @@ export default defineConfig({
|
||||
TDesignResolver({
|
||||
library: 'vue-next'
|
||||
})
|
||||
]
|
||||
],
|
||||
dts: true
|
||||
}),
|
||||
Components({
|
||||
resolvers: [
|
||||
TDesignResolver({
|
||||
library: 'vue-next'
|
||||
})
|
||||
]
|
||||
],
|
||||
dts: true
|
||||
})
|
||||
],
|
||||
base: './',
|
||||
|
||||
5228
package-lock.json
generated
12
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ceru-music",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.5",
|
||||
"description": "一款简洁优雅的音乐播放器",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "sqj,wldss,star",
|
||||
@@ -8,7 +8,7 @@
|
||||
"homepage": "https://ceru.docs.shiqianjiang.cn",
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint --cache . --fix",
|
||||
"lint": "eslint --cache . --fix && yarn typecheck",
|
||||
"typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
|
||||
"typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false",
|
||||
"typecheck": "yarn run typecheck:node && yarn run typecheck:web",
|
||||
@@ -58,6 +58,7 @@
|
||||
"jss": "^10.10.0",
|
||||
"jss-preset-default": "^10.10.0",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-it-footnote": "^4.0.0",
|
||||
"marked": "^16.1.2",
|
||||
"mitt": "^3.0.1",
|
||||
"needle": "^3.3.1",
|
||||
@@ -75,10 +76,11 @@
|
||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||
"@tdesign-vue-next/auto-import-resolver": "^0.1.1",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/markdown-it-footnote": "^3.0.4",
|
||||
"@types/node": "^22.16.5",
|
||||
"@types/node-fetch": "^2.6.13",
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"electron": "^37.3.1",
|
||||
"electron": "^38.1.0",
|
||||
"electron-builder": "^25.1.8",
|
||||
"electron-icon-builder": "^2.0.1",
|
||||
"electron-vite": "^4.0.0",
|
||||
@@ -95,9 +97,9 @@
|
||||
"vite-plugin-top-level-await": "^1.6.0",
|
||||
"vite-plugin-vue-devtools": "^8.0.0",
|
||||
"vite-plugin-wasm": "^3.5.0",
|
||||
"vitepress": "^2.0.0-alpha.12",
|
||||
"vitepress": "^1.6.4",
|
||||
"vue": "^3.5.21",
|
||||
"vue-eslint-parser": "^10.2.0",
|
||||
"vue-tsc": "^3.0.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
10491
pnpm-lock.yaml
generated
76922
qodana.sarif.json
Normal file
3
qodana.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
version: "1.0"
|
||||
profile:
|
||||
name: qodana.starter
|
||||
55
scripts/genAst.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function generateTree(dir, prefix = '', isLast = true, excludeDirs = ['node_modules', 'dist', 'out', '.git','.kiro','.idea','.codebuddy','.vscode','.workflow','assets','resources','docs']) {
|
||||
const basename = path.basename(dir);
|
||||
|
||||
// 跳过排除的目录和隐藏文件
|
||||
if (basename.startsWith('.') && basename !== '.' && basename !== '..' && !['.github', '.workflow'].includes(basename)) {
|
||||
return;
|
||||
}
|
||||
if (excludeDirs.includes(basename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 当前项目显示
|
||||
if (prefix === '') {
|
||||
console.log(`${basename}/`);
|
||||
} else {
|
||||
const connector = isLast ? '└── ' : '├── ';
|
||||
const displayName = fs.statSync(dir).isDirectory() ? `${basename}/` : basename;
|
||||
console.log(prefix + connector + displayName);
|
||||
}
|
||||
|
||||
if (!fs.statSync(dir).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const items = fs.readdirSync(dir)
|
||||
.filter(item => !item.startsWith('.') || ['.github', '.workflow'].includes(item))
|
||||
.filter(item => !excludeDirs.includes(item))
|
||||
.sort((a, b) => {
|
||||
// 目录排在前面,文件排在后面
|
||||
const aIsDir = fs.statSync(path.join(dir, a)).isDirectory();
|
||||
const bIsDir = fs.statSync(path.join(dir, b)).isDirectory();
|
||||
if (aIsDir && !bIsDir) return -1;
|
||||
if (!aIsDir && bIsDir) return 1;
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
const newPrefix = prefix + (isLast ? ' ' : '│ ');
|
||||
|
||||
items.forEach((item, index) => {
|
||||
const isLastItem = index === items.length - 1;
|
||||
generateTree(path.join(dir, item), newPrefix, isLastItem, excludeDirs);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error reading directory: ${dir}`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
const targetDir = process.argv[2] || '.';
|
||||
console.log('项目文件结构:');
|
||||
generateTree(targetDir);
|
||||
@@ -1,150 +0,0 @@
|
||||
// 业务工具方法
|
||||
|
||||
import { LX } from '../../types/global'
|
||||
|
||||
export const toNewMusicInfo = (oldMusicInfo: any): LX.Music.MusicInfo => {
|
||||
const meta: Record<string, any> = {
|
||||
songId: oldMusicInfo.songmid, // 歌曲ID,local为文件路径
|
||||
albumName: oldMusicInfo.albumName, // 歌曲专辑名称
|
||||
picUrl: oldMusicInfo.img // 歌曲图片链接
|
||||
}
|
||||
const newInfo = {
|
||||
id: `${oldMusicInfo.source}_${oldMusicInfo.songmid}`,
|
||||
name: oldMusicInfo.name,
|
||||
singer: oldMusicInfo.singer,
|
||||
source: oldMusicInfo.source,
|
||||
interval: oldMusicInfo.interval,
|
||||
meta: meta as LX.Music.MusicInfoOnline['meta']
|
||||
}
|
||||
|
||||
if (oldMusicInfo.source == 'local') {
|
||||
meta.filePath = oldMusicInfo.filePath ?? oldMusicInfo.songmid ?? ''
|
||||
meta.ext = oldMusicInfo.ext ?? /\.(\w+)$/.exec(meta.filePath)?.[1] ?? ''
|
||||
} else {
|
||||
meta.qualitys = oldMusicInfo.types
|
||||
meta._qualitys = oldMusicInfo._types
|
||||
meta.albumId = oldMusicInfo.albumId
|
||||
if (meta._qualitys.flac32bit && !meta._qualitys.flac24bit) {
|
||||
meta._qualitys.flac24bit = meta._qualitys.flac32bit
|
||||
delete meta._qualitys.flac32bit
|
||||
|
||||
meta.qualitys = (meta.qualitys as any[]).map((quality) => {
|
||||
if (quality.type == 'flac32bit') quality.type = 'flac24bit'
|
||||
return quality
|
||||
})
|
||||
}
|
||||
|
||||
switch (oldMusicInfo.source) {
|
||||
case 'kg':
|
||||
meta.hash = oldMusicInfo.hash
|
||||
newInfo.id = oldMusicInfo.songmid + '_' + oldMusicInfo.hash
|
||||
break
|
||||
case 'tx':
|
||||
meta.strMediaMid = oldMusicInfo.strMediaMid
|
||||
meta.id = oldMusicInfo.songId
|
||||
meta.albumMid = oldMusicInfo.albumMid
|
||||
break
|
||||
case 'mg':
|
||||
meta.copyrightId = oldMusicInfo.copyrightId
|
||||
meta.lrcUrl = oldMusicInfo.lrcUrl
|
||||
meta.mrcUrl = oldMusicInfo.mrcUrl
|
||||
meta.trcUrl = oldMusicInfo.trcUrl
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return newInfo
|
||||
}
|
||||
|
||||
export const toOldMusicInfo = (minfo: LX.Music.MusicInfo) => {
|
||||
const oInfo: Record<string, any> = {
|
||||
name: minfo.name,
|
||||
singer: minfo.singer,
|
||||
source: minfo.source,
|
||||
songmid: minfo.meta.songId,
|
||||
interval: minfo.interval,
|
||||
albumName: minfo.meta.albumName,
|
||||
img: minfo.meta.picUrl ?? '',
|
||||
typeUrl: {}
|
||||
}
|
||||
if (minfo.source == 'local') {
|
||||
oInfo.filePath = minfo.meta.filePath
|
||||
oInfo.ext = minfo.meta.ext
|
||||
oInfo.albumId = ''
|
||||
oInfo.types = []
|
||||
oInfo._types = {}
|
||||
} else {
|
||||
oInfo.albumId = minfo.meta.albumId
|
||||
oInfo.types = minfo.meta.qualitys
|
||||
oInfo._types = minfo.meta._qualitys
|
||||
|
||||
switch (minfo.source) {
|
||||
case 'kg':
|
||||
oInfo.hash = minfo.meta.hash
|
||||
break
|
||||
case 'tx':
|
||||
oInfo.strMediaMid = minfo.meta.strMediaMid
|
||||
oInfo.albumMid = minfo.meta.albumMid
|
||||
oInfo.songId = minfo.meta.id
|
||||
break
|
||||
case 'mg':
|
||||
oInfo.copyrightId = minfo.meta.copyrightId
|
||||
oInfo.lrcUrl = minfo.meta.lrcUrl
|
||||
oInfo.mrcUrl = minfo.meta.mrcUrl
|
||||
oInfo.trcUrl = minfo.meta.trcUrl
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return oInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复2.0.0-dev.8之前的新列表数据音质
|
||||
* @param musicInfo
|
||||
*/
|
||||
export const fixNewMusicInfoQuality = (musicInfo: LX.Music.MusicInfo) => {
|
||||
if (musicInfo.source == 'local') return musicInfo
|
||||
|
||||
// @ts-expect-error
|
||||
if (musicInfo.meta._qualitys.flac32bit && !musicInfo.meta._qualitys.flac24bit) {
|
||||
// @ts-expect-error
|
||||
musicInfo.meta._qualitys.flac24bit = musicInfo.meta._qualitys.flac32bit
|
||||
// @ts-expect-error
|
||||
delete musicInfo.meta._qualitys.flac32bit
|
||||
|
||||
musicInfo.meta.qualitys = musicInfo.meta.qualitys.map((quality) => {
|
||||
// @ts-expect-error
|
||||
if (quality.type == 'flac32bit') quality.type = 'flac24bit'
|
||||
return quality
|
||||
})
|
||||
}
|
||||
|
||||
return musicInfo
|
||||
}
|
||||
|
||||
export const filterMusicList = <T extends LX.Music.MusicInfo>(list: T[]): T[] => {
|
||||
const ids = new Set<string>()
|
||||
return list.filter((s) => {
|
||||
if (!s.id || ids.has(s.id) || !s.name) return false
|
||||
if (s.singer == null) s.singer = ''
|
||||
ids.add(s.id)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
const MAX_NAME_LENGTH = 80
|
||||
const MAX_FILE_NAME_LENGTH = 150
|
||||
export const clipNameLength = (name: string) => {
|
||||
if (name.length <= MAX_NAME_LENGTH || !name.includes('、')) return name
|
||||
const names = name.split('、')
|
||||
let newName = names.shift()!
|
||||
for (const name of names) {
|
||||
if (newName.length + name.length > MAX_NAME_LENGTH) break
|
||||
newName = newName + '、' + name
|
||||
}
|
||||
return newName
|
||||
}
|
||||
export const clipFileNameLength = (name: string) => {
|
||||
return name.length > MAX_FILE_NAME_LENGTH ? name.substring(0, MAX_FILE_NAME_LENGTH) : name
|
||||
}
|
||||
@@ -22,7 +22,7 @@ const UPDATE_API_URL = `${UPDATE_SERVER}/update/${process.platform}/${app.getVer
|
||||
// Alist API 配置
|
||||
const ALIST_BASE_URL = 'https://alist.shiqianjiang.cn' // 请替换为实际的 alist 域名
|
||||
const ALIST_USERNAME = 'ceruupdate'
|
||||
const ALIST_PASSWORD = '123456'
|
||||
const ALIST_PASSWORD = '123456' //登录公开的账号密码
|
||||
|
||||
// Alist 认证 token
|
||||
let alistToken: string | null = null
|
||||
|
||||
157
src/main/events/directorySettings.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
import { ipcMain, dialog } from 'electron'
|
||||
import { configManager } from '../services/ConfigManager'
|
||||
|
||||
// 获取当前目录配置
|
||||
ipcMain.handle('directory-settings:get-directories', async () => {
|
||||
try {
|
||||
const directories = configManager.getDirectories()
|
||||
|
||||
// 确保目录存在
|
||||
await configManager.ensureDirectoryExists(directories.cacheDir)
|
||||
await configManager.ensureDirectoryExists(directories.downloadDir)
|
||||
|
||||
return directories
|
||||
} catch (error) {
|
||||
console.error('获取目录配置失败:', error)
|
||||
return configManager.getDirectories() // 返回默认配置
|
||||
}
|
||||
})
|
||||
|
||||
// 选择缓存目录
|
||||
ipcMain.handle('directory-settings:select-cache-dir', async () => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
title: '选择缓存目录',
|
||||
properties: ['openDirectory', 'createDirectory'],
|
||||
buttonLabel: '选择目录'
|
||||
})
|
||||
|
||||
if (!result.canceled && result.filePaths.length > 0) {
|
||||
const selectedPath = result.filePaths[0]
|
||||
await configManager.ensureDirectoryExists(selectedPath)
|
||||
return { success: true, path: selectedPath }
|
||||
}
|
||||
|
||||
return { success: false, message: '用户取消选择' }
|
||||
} catch (error) {
|
||||
console.error('选择缓存目录失败:', error)
|
||||
return { success: false, message: '选择目录失败' }
|
||||
}
|
||||
})
|
||||
|
||||
// 选择下载目录
|
||||
ipcMain.handle('directory-settings:select-download-dir', async () => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
title: '选择下载目录',
|
||||
properties: ['openDirectory', 'createDirectory'],
|
||||
buttonLabel: '选择目录'
|
||||
})
|
||||
|
||||
if (!result.canceled && result.filePaths.length > 0) {
|
||||
const selectedPath = result.filePaths[0]
|
||||
await configManager.ensureDirectoryExists(selectedPath)
|
||||
return { success: true, path: selectedPath }
|
||||
}
|
||||
|
||||
return { success: false, message: '用户取消选择' }
|
||||
} catch (error) {
|
||||
console.error('选择下载目录失败:', error)
|
||||
return { success: false, message: '选择目录失败' }
|
||||
}
|
||||
})
|
||||
|
||||
// 保存目录配置
|
||||
ipcMain.handle('directory-settings:save-directories', async (_, directories) => {
|
||||
try {
|
||||
const success = await configManager.saveDirectories(directories)
|
||||
return { success, message: success ? '目录配置已保存' : '保存配置失败' }
|
||||
} catch (error) {
|
||||
console.error('保存目录配置失败:', error)
|
||||
return { success: false, message: '保存配置失败' }
|
||||
}
|
||||
})
|
||||
|
||||
// 重置为默认目录
|
||||
ipcMain.handle('directory-settings:reset-directories', async () => {
|
||||
try {
|
||||
// 重置目录配置
|
||||
configManager.delete('cacheDir')
|
||||
configManager.delete('downloadDir')
|
||||
configManager.saveConfig()
|
||||
|
||||
// 获取默认目录
|
||||
const directories = configManager.getDirectories()
|
||||
|
||||
// 确保默认目录存在
|
||||
await configManager.ensureDirectoryExists(directories.cacheDir)
|
||||
await configManager.ensureDirectoryExists(directories.downloadDir)
|
||||
|
||||
return { success: true, directories }
|
||||
} catch (error) {
|
||||
console.error('重置目录配置失败:', error)
|
||||
return { success: false, message: '重置配置失败' }
|
||||
}
|
||||
})
|
||||
|
||||
// 打开目录
|
||||
ipcMain.handle('directory-settings:open-directory', async (_, dirPath) => {
|
||||
try {
|
||||
const { shell } = require('electron')
|
||||
await shell.openPath(dirPath)
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
console.error('打开目录失败:', error)
|
||||
return { success: false, message: '打开目录失败' }
|
||||
}
|
||||
})
|
||||
|
||||
// 获取目录大小
|
||||
ipcMain.handle('directory-settings:get-directory-size', async (_, dirPath) => {
|
||||
try {
|
||||
const fs = require('fs')
|
||||
const { join } = require('path')
|
||||
|
||||
const getDirectorySize = (dirPath: string): number => {
|
||||
let totalSize = 0
|
||||
|
||||
try {
|
||||
const items = fs.readdirSync(dirPath)
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = join(dirPath, item)
|
||||
const stats = fs.statSync(itemPath)
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
totalSize += getDirectorySize(itemPath)
|
||||
} else {
|
||||
totalSize += stats.size
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 忽略无法访问的文件/目录
|
||||
}
|
||||
|
||||
return totalSize
|
||||
}
|
||||
|
||||
const size = getDirectorySize(dirPath)
|
||||
|
||||
// 格式化大小
|
||||
const formatSize = (bytes: number): string => {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
return {
|
||||
size,
|
||||
formatted: formatSize(size)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取目录大小失败:', error)
|
||||
return { size: 0, formatted: '0 B' }
|
||||
}
|
||||
})
|
||||
@@ -14,18 +14,21 @@ ipcMain.handle('music-cache:get-info', async () => {
|
||||
// 清空缓存
|
||||
ipcMain.handle('music-cache:clear', async () => {
|
||||
try {
|
||||
console.log('收到清空缓存请求')
|
||||
await musicCacheService.clearCache()
|
||||
console.log('缓存清空完成')
|
||||
return { success: true, message: '缓存已清空' }
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('清空缓存失败:', error)
|
||||
return { success: false, message: '清空缓存失败' }
|
||||
return { success: false, message: `清空缓存失败: ${error.message}` }
|
||||
}
|
||||
})
|
||||
|
||||
// 获取缓存大小
|
||||
ipcMain.handle('music-cache:get-size', async () => {
|
||||
try {
|
||||
return await musicCacheService.getCacheSize()
|
||||
const info = await musicCacheService.getCacheInfo()
|
||||
return info.size
|
||||
} catch (error) {
|
||||
console.error('获取缓存大小失败:', error)
|
||||
return 0
|
||||
|
||||
161
src/main/events/pluginNotice.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2025. 时迁酱 Inc. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of 时迁酱.
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* @author 时迁酱,无聊的霜霜,Star
|
||||
* @since 2025-9-20
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
import { BrowserWindow } from 'electron'
|
||||
|
||||
export interface PluginNoticeData {
|
||||
type: 'error' | 'info' | 'success' | 'warn' | 'update'
|
||||
data: {
|
||||
title?: string
|
||||
content?: string
|
||||
message?: string
|
||||
url?: string
|
||||
version?: string
|
||||
pluginInfo?: {
|
||||
name?: string
|
||||
type?: 'lx' | 'cr'
|
||||
forcedUpdate?: boolean
|
||||
}
|
||||
}
|
||||
currentVersion?: string
|
||||
timestamp?: number
|
||||
pluginName?: string
|
||||
}
|
||||
|
||||
export interface DialogNotice {
|
||||
type: string
|
||||
data: any
|
||||
timestamp: number
|
||||
pluginName: string
|
||||
dialogType: 'update' | 'info' | 'error' | 'warning' | 'success'
|
||||
title: string
|
||||
message: string
|
||||
updateUrl?: string
|
||||
pluginType?: 'lx' | 'cr'
|
||||
currentVersion?: string
|
||||
newVersion?: string
|
||||
actions: Array<{
|
||||
text: string
|
||||
type: 'cancel' | 'update' | 'confirm'
|
||||
primary?: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 URL 是否有效
|
||||
*/
|
||||
function isValidUrl(url: string): boolean {
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
return urlObj.protocol === 'http:' || urlObj.protocol === 'https:'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知类型获取标题
|
||||
*/
|
||||
function getNoticeTitle(type: string): string {
|
||||
const titleMap: Record<string, string> = {
|
||||
update: '插件更新',
|
||||
error: '插件错误',
|
||||
warning: '插件警告',
|
||||
info: '插件信息',
|
||||
success: '操作成功'
|
||||
}
|
||||
return titleMap[type] || '插件通知'
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知类型获取默认消息
|
||||
*/
|
||||
function getDefaultMessage(type: string, data: any, pluginName: string): string {
|
||||
switch (type) {
|
||||
case 'error':
|
||||
return `插件 "${pluginName}" 发生错误: ${data?.error || data?.message || '未知错误'}`
|
||||
case 'warning':
|
||||
return `插件 "${pluginName}" 警告: ${data?.warning || data?.message || '需要注意'}`
|
||||
case 'success':
|
||||
return `插件 "${pluginName}" 操作成功: ${data?.message || ''}`
|
||||
case 'info':
|
||||
default:
|
||||
return data?.message || `插件 "${pluginName}" 信息: ${JSON.stringify(data)}`
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送插件通知到渲染进程
|
||||
*/
|
||||
export function sendPluginNotice(noticeData: PluginNoticeData, pluginName?: string): void {
|
||||
try {
|
||||
console.log(`[CeruMusic] 插件通知: ${noticeData.type}`, noticeData.data)
|
||||
|
||||
// 获取主窗口实例
|
||||
const mainWindow = BrowserWindow.getAllWindows().find((win) => !win.isDestroyed())
|
||||
if (!mainWindow) {
|
||||
console.warn('[CeruMusic] 未找到主窗口,无法发送通知')
|
||||
return
|
||||
}
|
||||
|
||||
// 构建通知数据
|
||||
const baseNoticeData = {
|
||||
type: noticeData.type,
|
||||
data: noticeData.data,
|
||||
timestamp: noticeData.timestamp || Date.now(),
|
||||
pluginName: pluginName || noticeData.pluginName || 'Unknown Plugin'
|
||||
}
|
||||
|
||||
// 根据通知类型处理不同的逻辑
|
||||
if (noticeData.type === 'update' && noticeData.data?.url && isValidUrl(noticeData.data.url)) {
|
||||
// 更新通知 - 显示带更新按钮的对话框
|
||||
const updateNotice: DialogNotice = {
|
||||
...baseNoticeData,
|
||||
dialogType: 'update',
|
||||
title: noticeData.data.title || '插件更新',
|
||||
message: noticeData.data.content || `插件 "${baseNoticeData.pluginName}" 有新版本可用`,
|
||||
updateUrl: noticeData.data.url,
|
||||
pluginType: noticeData.data.pluginInfo?.type,
|
||||
currentVersion: noticeData.currentVersion || '未知', // 这个需要从插件实例获取
|
||||
newVersion: noticeData.data.version,
|
||||
actions: [
|
||||
{ text: '稍后更新', type: 'cancel' },
|
||||
{ text: '立即更新', type: 'update', primary: true }
|
||||
]
|
||||
}
|
||||
|
||||
mainWindow.webContents.send('plugin-notice', updateNotice)
|
||||
} else {
|
||||
// 普通通知 - 显示信息对话框
|
||||
const infoNotice: DialogNotice = {
|
||||
...baseNoticeData,
|
||||
dialogType:
|
||||
noticeData.type === 'error'
|
||||
? 'error'
|
||||
: noticeData.type === 'warn'
|
||||
? 'warning'
|
||||
: noticeData.type === 'success'
|
||||
? 'success'
|
||||
: 'info',
|
||||
title: noticeData.data.title || getNoticeTitle(noticeData.type),
|
||||
message:
|
||||
noticeData.data.message ||
|
||||
noticeData.data.content ||
|
||||
getDefaultMessage(noticeData.type, noticeData.data, baseNoticeData.pluginName),
|
||||
actions: [{ text: '我知道了', type: 'confirm', primary: true }]
|
||||
}
|
||||
|
||||
mainWindow.webContents.send('plugin-notice', infoNotice)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[CeruMusic] 发送插件通知失败:', error.message)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { app, shell, BrowserWindow, ipcMain, Tray, Menu } from 'electron'
|
||||
import { app, shell, BrowserWindow, ipcMain, Tray, Menu, screen } from 'electron'
|
||||
import { configManager } from './services/ConfigManager'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/logo.png?asset'
|
||||
@@ -7,7 +8,6 @@ import musicService from './services/music'
|
||||
import pluginService from './services/plugin'
|
||||
import aiEvents from './events/ai'
|
||||
import './services/musicSdk/index'
|
||||
|
||||
// 获取单实例锁
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
||||
@@ -90,20 +90,27 @@ function createTray(): void {
|
||||
|
||||
function createWindow(): void {
|
||||
// return
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
// 获取保存的窗口位置和大小
|
||||
const savedBounds = configManager.getWindowBounds()
|
||||
|
||||
// 获取屏幕尺寸
|
||||
const primaryDisplay = screen.getPrimaryDisplay()
|
||||
// 使用完整屏幕尺寸而不是工作区域,以支持真正的全屏模式
|
||||
const { width: screenWidth, height: screenHeight } = primaryDisplay.size
|
||||
|
||||
// 默认窗口配置
|
||||
const defaultOptions = {
|
||||
width: 1100,
|
||||
height: 750,
|
||||
minWidth: 1100,
|
||||
minHeight: 670,
|
||||
maxWidth: screenWidth,
|
||||
maxHeight: screenHeight,
|
||||
show: false,
|
||||
center: true,
|
||||
center: !savedBounds, // 如果有保存的位置,则不居中
|
||||
autoHideMenuBar: true,
|
||||
// alwaysOnTop: true,
|
||||
// 移除最大宽高限制,以便全屏模式能够铺满整个屏幕
|
||||
titleBarStyle: 'hidden',
|
||||
titleBarStyle: 'hidden' as const,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
// ...(process.platform !== 'darwin' ? { titleBarOverlay: true } : {}),
|
||||
icon: path.join(__dirname, '../../resources/logo.ico'),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
@@ -113,9 +120,57 @@ function createWindow(): void {
|
||||
contextIsolation: false,
|
||||
backgroundThrottling: false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 如果有保存的窗口位置和大小,则使用保存的值
|
||||
if (savedBounds) {
|
||||
Object.assign(defaultOptions, savedBounds)
|
||||
}
|
||||
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow(defaultOptions)
|
||||
if (process.platform == 'darwin') mainWindow.setWindowButtonVisibility(false)
|
||||
|
||||
// 监听窗口移动和调整大小事件,保存窗口位置和大小
|
||||
mainWindow.on('moved', () => {
|
||||
if (mainWindow && !mainWindow.isMaximized() && !mainWindow.isFullScreen()) {
|
||||
const bounds = mainWindow.getBounds()
|
||||
configManager.saveWindowBounds(bounds)
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.on('resized', () => {
|
||||
if (mainWindow && !mainWindow.isMaximized() && !mainWindow.isFullScreen()) {
|
||||
const bounds = mainWindow.getBounds()
|
||||
|
||||
// 获取当前屏幕尺寸
|
||||
const { screen } = require('electron')
|
||||
const currentDisplay = screen.getDisplayMatching(bounds)
|
||||
const { width: screenWidth, height: screenHeight } = currentDisplay.workAreaSize
|
||||
|
||||
// 确保窗口不超过屏幕尺寸
|
||||
let needResize = false
|
||||
const newBounds = { ...bounds }
|
||||
|
||||
if (bounds.width > screenWidth) {
|
||||
newBounds.width = screenWidth
|
||||
needResize = true
|
||||
}
|
||||
|
||||
if (bounds.height > screenHeight) {
|
||||
newBounds.height = screenHeight
|
||||
needResize = true
|
||||
}
|
||||
|
||||
// 如果需要调整大小,应用新的尺寸
|
||||
if (needResize) {
|
||||
mainWindow.setBounds(newBounds)
|
||||
}
|
||||
|
||||
configManager.saveWindowBounds(newBounds)
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
mainWindow?.show()
|
||||
})
|
||||
@@ -218,15 +273,23 @@ ipcMain.handle('get-app-version', () => {
|
||||
aiEvents(mainWindow)
|
||||
import './events/musicCache'
|
||||
import './events/songList'
|
||||
import './events/directorySettings'
|
||||
import './events/pluginNotice'
|
||||
import { registerAutoUpdateEvents, initAutoUpdateForWindow } from './events/autoUpdate'
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
// Set app user model id for windows
|
||||
// Set app user model id for windows - 确保与 electron-builder.yml 中的 appId 一致
|
||||
electronApp.setAppUserModelId('com.cerumusic.app')
|
||||
|
||||
electronApp.setAppUserModelId('com.cerulean.music')
|
||||
// 在 Windows 上设置应用程序名称,帮助 SMTC 识别
|
||||
if (process.platform === 'win32') {
|
||||
app.setAppUserModelId('com.cerumusic.app')
|
||||
// 设置应用程序名称
|
||||
app.setName('澜音')
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
// 初始化插件系统
|
||||
|
||||
162
src/main/services/ConfigManager.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
import { app } from 'electron'
|
||||
import { join } from 'path'
|
||||
import fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const mkdir = promisify(fs.mkdir)
|
||||
const access = promisify(fs.access)
|
||||
|
||||
export const CONFIG_NAME = 'sqj_config.json'
|
||||
|
||||
// 配置管理器类
|
||||
export class ConfigManager {
|
||||
private static instance: ConfigManager
|
||||
private configPath: string
|
||||
private config: Record<string, any> = {}
|
||||
|
||||
private constructor() {
|
||||
this.configPath = join(app.getPath('userData'), CONFIG_NAME)
|
||||
this.loadConfig()
|
||||
}
|
||||
|
||||
// 单例模式获取实例
|
||||
public static getInstance(): ConfigManager {
|
||||
if (!ConfigManager.instance) {
|
||||
ConfigManager.instance = new ConfigManager()
|
||||
}
|
||||
return ConfigManager.instance
|
||||
}
|
||||
|
||||
// 加载配置
|
||||
private loadConfig(): void {
|
||||
try {
|
||||
if (fs.existsSync(this.configPath)) {
|
||||
const configData = fs.readFileSync(this.configPath, 'utf-8')
|
||||
this.config = JSON.parse(configData)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载配置失败:', error)
|
||||
this.config = {}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
public saveConfig(): boolean {
|
||||
try {
|
||||
fs.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2))
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('保存配置失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 获取配置项
|
||||
public get<T>(key: string, defaultValue?: T): T {
|
||||
const value = this.config[key]
|
||||
return value !== undefined ? value : (defaultValue as T)
|
||||
}
|
||||
|
||||
// 设置配置项
|
||||
public set<T>(key: string, value: T): void {
|
||||
this.config[key] = value
|
||||
}
|
||||
|
||||
// 删除配置项
|
||||
public delete(key: string): void {
|
||||
delete this.config[key]
|
||||
}
|
||||
|
||||
// 重置所有配置
|
||||
public reset(): void {
|
||||
this.config = {}
|
||||
this.saveConfig()
|
||||
}
|
||||
|
||||
// 获取所有配置
|
||||
public getAll(): Record<string, any> {
|
||||
return { ...this.config }
|
||||
}
|
||||
|
||||
// 确保目录存在
|
||||
public async ensureDirectoryExists(dirPath: string): Promise<void> {
|
||||
try {
|
||||
await access(dirPath)
|
||||
} catch {
|
||||
await mkdir(dirPath, { recursive: true })
|
||||
}
|
||||
}
|
||||
|
||||
// 获取目录配置
|
||||
public getDirectories() {
|
||||
const userDataPath = app.getPath('userData')
|
||||
const defaults = {
|
||||
cacheDir: join(userDataPath, 'music-cache'),
|
||||
downloadDir: join(app.getPath('music'), 'CeruMusic/songs')
|
||||
}
|
||||
|
||||
return {
|
||||
cacheDir: this.get('cacheDir', defaults.cacheDir),
|
||||
downloadDir: this.get('downloadDir', defaults.downloadDir)
|
||||
}
|
||||
}
|
||||
|
||||
// 保存目录配置
|
||||
public async saveDirectories(directories: {
|
||||
cacheDir: string
|
||||
downloadDir: string
|
||||
}): Promise<boolean> {
|
||||
try {
|
||||
await this.ensureDirectoryExists(directories.cacheDir)
|
||||
await this.ensureDirectoryExists(directories.downloadDir)
|
||||
|
||||
this.set('cacheDir', directories.cacheDir)
|
||||
this.set('downloadDir', directories.downloadDir)
|
||||
return this.saveConfig()
|
||||
} catch (error) {
|
||||
console.error('保存目录配置失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存窗口位置和大小
|
||||
public saveWindowBounds(bounds: { x: number; y: number; width: number; height: number }): void {
|
||||
this.set('windowBounds', bounds)
|
||||
this.saveConfig()
|
||||
}
|
||||
|
||||
// 获取窗口位置和大小,确保窗口完全在屏幕内
|
||||
public getWindowBounds(): { x: number; y: number; width: number; height: number } | null {
|
||||
const bounds = this.get<{ x: number; y: number; width: number; height: number } | null>(
|
||||
'windowBounds',
|
||||
null
|
||||
)
|
||||
|
||||
if (bounds) {
|
||||
const { screen } = require('electron')
|
||||
|
||||
// 获取主显示器
|
||||
const primaryDisplay = screen.getPrimaryDisplay()
|
||||
const { width: screenWidth, height: screenHeight } = primaryDisplay.workAreaSize
|
||||
|
||||
// 确保窗口在屏幕内
|
||||
if (bounds.x < 0) bounds.x = 0
|
||||
if (bounds.y < 0) bounds.y = 0
|
||||
|
||||
// 确保窗口右侧不超出屏幕
|
||||
if (bounds.x + bounds.width > screenWidth) {
|
||||
bounds.x = Math.max(0, screenWidth - bounds.width)
|
||||
}
|
||||
|
||||
// 确保窗口底部不超出屏幕
|
||||
if (bounds.y + bounds.height > screenHeight) {
|
||||
bounds.y = Math.max(0, screenHeight - bounds.height)
|
||||
}
|
||||
}
|
||||
|
||||
return bounds
|
||||
}
|
||||
}
|
||||
|
||||
// 导出单例实例
|
||||
export const configManager = ConfigManager.getInstance()
|
||||
@@ -1,20 +1,32 @@
|
||||
import { app } from 'electron'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs/promises'
|
||||
import * as crypto from 'crypto'
|
||||
import axios from 'axios'
|
||||
import { configManager } from '../ConfigManager'
|
||||
|
||||
export class MusicCacheService {
|
||||
private cacheDir: string
|
||||
private cacheIndex: Map<string, string> = new Map()
|
||||
private indexFilePath: string
|
||||
|
||||
constructor() {
|
||||
this.cacheDir = path.join(app.getPath('userData'), 'music-cache')
|
||||
this.indexFilePath = path.join(this.cacheDir, 'cache-index.json')
|
||||
this.initCache()
|
||||
}
|
||||
|
||||
private getCacheDirectory(): string {
|
||||
// 使用配置管理服务获取缓存目录
|
||||
const directories = configManager.getDirectories()
|
||||
return directories.cacheDir
|
||||
}
|
||||
|
||||
// 动态获取缓存目录
|
||||
public get cacheDir(): string {
|
||||
return this.getCacheDirectory()
|
||||
}
|
||||
|
||||
// 动态获取索引文件路径
|
||||
public get indexFilePath(): string {
|
||||
return path.join(this.cacheDir, 'cache-index.json')
|
||||
}
|
||||
|
||||
private async initCache() {
|
||||
try {
|
||||
// 确保缓存目录存在
|
||||
@@ -57,9 +69,9 @@ export class MusicCacheService {
|
||||
return path.join(this.cacheDir, `${cacheKey}${ext}`)
|
||||
}
|
||||
|
||||
async getCachedMusicUrl(songId: string, originalUrlPromise: Promise<string>): Promise<string> {
|
||||
async getCachedMusicUrl(songId: string): Promise<string | null> {
|
||||
const cacheKey = this.generateCacheKey(songId)
|
||||
console.log('hash', cacheKey)
|
||||
console.log('检查缓存 hash:', cacheKey)
|
||||
|
||||
// 检查是否已缓存
|
||||
if (this.cacheIndex.has(cacheKey)) {
|
||||
@@ -72,14 +84,29 @@ export class MusicCacheService {
|
||||
return `file://${cachedFilePath}`
|
||||
} catch (error) {
|
||||
// 文件不存在,从缓存索引中移除
|
||||
console.warn(`缓存文件不存在,移除索引: ${cachedFilePath}`)
|
||||
this.cacheIndex.delete(cacheKey)
|
||||
await this.saveCacheIndex()
|
||||
}
|
||||
}
|
||||
|
||||
// 下载并缓存文件 先返回源链接不等待结果优化体验
|
||||
this.downloadAndCache(songId, await originalUrlPromise, cacheKey)
|
||||
return await originalUrlPromise
|
||||
return null
|
||||
}
|
||||
|
||||
async cacheMusic(songId: string, url: string): Promise<void> {
|
||||
const cacheKey = this.generateCacheKey(songId)
|
||||
|
||||
// 如果已经缓存,跳过
|
||||
if (this.cacheIndex.has(cacheKey)) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await this.downloadAndCache(songId, url, cacheKey)
|
||||
} catch (error) {
|
||||
console.error(`缓存歌曲失败: ${songId}`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private async downloadAndCache(songId: string, url: string, cacheKey: string): Promise<string> {
|
||||
@@ -130,43 +157,117 @@ export class MusicCacheService {
|
||||
|
||||
async clearCache(): Promise<void> {
|
||||
try {
|
||||
// 删除所有缓存文件
|
||||
console.log('开始清空缓存目录:', this.cacheDir)
|
||||
|
||||
// 先重新加载缓存索引,确保获取最新的文件列表
|
||||
await this.loadCacheIndex()
|
||||
|
||||
// 删除索引中记录的所有缓存文件
|
||||
let deletedFromIndex = 0
|
||||
for (const filePath of this.cacheIndex.values()) {
|
||||
try {
|
||||
await fs.unlink(filePath)
|
||||
} catch (error) {
|
||||
// 忽略文件不存在的错误
|
||||
deletedFromIndex++
|
||||
console.log('删除缓存文件:', filePath)
|
||||
} catch (error: any) {
|
||||
console.warn('删除文件失败:', filePath, error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// 删除缓存目录中的所有其他文件(包括可能遗漏的文件)
|
||||
let deletedFromDir = 0
|
||||
try {
|
||||
const files = await fs.readdir(this.cacheDir)
|
||||
for (const file of files) {
|
||||
const filePath = path.join(this.cacheDir, file)
|
||||
try {
|
||||
const stats = await fs.stat(filePath)
|
||||
if (stats.isFile() && file !== 'cache-index.json') {
|
||||
await fs.unlink(filePath)
|
||||
deletedFromDir++
|
||||
console.log('删除目录文件:', filePath)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.warn('删除目录文件失败:', filePath, error.message)
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.warn('读取缓存目录失败:', error.message)
|
||||
}
|
||||
|
||||
// 清空缓存索引
|
||||
this.cacheIndex.clear()
|
||||
await this.saveCacheIndex()
|
||||
|
||||
console.log('音乐缓存已清空')
|
||||
console.log(
|
||||
`音乐缓存已清空 - 从索引删除: ${deletedFromIndex}个文件, 从目录删除: ${deletedFromDir}个文件`
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('清空缓存失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async getCacheSize(): Promise<number> {
|
||||
getDirectorySize = async (dirPath: string): Promise<number> => {
|
||||
let totalSize = 0
|
||||
|
||||
for (const filePath of this.cacheIndex.values()) {
|
||||
try {
|
||||
const stats = await fs.stat(filePath)
|
||||
totalSize += stats.size
|
||||
} catch (error) {
|
||||
// 文件不存在,忽略
|
||||
try {
|
||||
const items = await fs.readdir(dirPath)
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = path.join(dirPath, item)
|
||||
const stats = await fs.stat(itemPath)
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
totalSize += await this.getDirectorySize(itemPath)
|
||||
} else {
|
||||
totalSize += stats.size
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 忽略无法访问的文件/目录
|
||||
}
|
||||
|
||||
return totalSize
|
||||
}
|
||||
|
||||
async getCacheInfo(): Promise<{ count: number; size: number; sizeFormatted: string }> {
|
||||
const size = await this.getCacheSize()
|
||||
const count = this.cacheIndex.size
|
||||
// 重新加载缓存索引以确保数据准确
|
||||
await this.loadCacheIndex()
|
||||
|
||||
// 统计实际的缓存文件数量和大小
|
||||
let actualCount = 0
|
||||
let totalSize = 0
|
||||
|
||||
try {
|
||||
const items = await fs.readdir(this.cacheDir)
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = path.join(this.cacheDir, item)
|
||||
try {
|
||||
const stats = await fs.stat(itemPath)
|
||||
|
||||
if (stats.isFile() && item !== 'cache-index.json') {
|
||||
// 检查是否是音频文件
|
||||
const ext = path.extname(item).toLowerCase()
|
||||
const audioExts = ['.mp3', '.flac', '.wav', '.aac', '.ogg', '.m4a', '.wma']
|
||||
|
||||
if (audioExts.includes(ext)) {
|
||||
actualCount++
|
||||
totalSize += stats.size
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
// 忽略无法访问的文件
|
||||
console.warn('无法访问文件:', itemPath, error.message)
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.warn('读取缓存目录失败:', error.message)
|
||||
// 如果无法读取目录,使用索引数据作为备选
|
||||
totalSize = await this.getDirectorySize(this.cacheDir)
|
||||
actualCount = this.cacheIndex.size
|
||||
}
|
||||
|
||||
const formatSize = (bytes: number): string => {
|
||||
if (bytes === 0) return '0 B'
|
||||
@@ -176,10 +277,12 @@ export class MusicCacheService {
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
console.log(`缓存信息 - 文件数量: ${actualCount}, 总大小: ${totalSize} bytes`)
|
||||
|
||||
return {
|
||||
count,
|
||||
size,
|
||||
sizeFormatted: formatSize(size)
|
||||
count: actualCount,
|
||||
size: totalSize,
|
||||
sizeFormatted: formatSize(totalSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
} from './type'
|
||||
import pluginService from '../plugin/index'
|
||||
import musicSdk from '../../utils/musicSdk/index'
|
||||
import { getAppDirPath } from '../../utils/path'
|
||||
import { musicCacheService } from '../musicCache'
|
||||
import path from 'node:path'
|
||||
import fs from 'fs'
|
||||
@@ -19,6 +18,7 @@ import fsPromise from 'fs/promises'
|
||||
import axios from 'axios'
|
||||
import { pipeline } from 'node:stream/promises'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { configManager } from '../ConfigManager'
|
||||
|
||||
const fileLock: Record<string, boolean> = {}
|
||||
|
||||
@@ -34,21 +34,23 @@ function main(source: string) {
|
||||
const usePlugin = pluginService.getPluginById(pluginId)
|
||||
if (!pluginId || !usePlugin) return { error: '请配置音源来播放歌曲' }
|
||||
|
||||
// 获取原始URL
|
||||
const originalUrlPromise = usePlugin.getMusicUrl(source, songInfo, quality)
|
||||
|
||||
// 生成歌曲唯一标识
|
||||
const songId = `${songInfo.name}-${songInfo.singer}-${source}-${quality}`
|
||||
|
||||
// 尝试获取缓存的URL
|
||||
try {
|
||||
const cachedUrl = await musicCacheService.getCachedMusicUrl(songId, originalUrlPromise)
|
||||
// 先检查缓存
|
||||
const cachedUrl = await musicCacheService.getCachedMusicUrl(songId)
|
||||
if (cachedUrl) {
|
||||
return cachedUrl
|
||||
} catch (cacheError) {
|
||||
console.warn('缓存获取失败,使用原始URL:', cacheError)
|
||||
const originalUrl = await originalUrlPromise
|
||||
return originalUrl
|
||||
}
|
||||
|
||||
// 没有缓存时才发起网络请求
|
||||
const originalUrl = await usePlugin.getMusicUrl(source, songInfo, quality)
|
||||
// 异步缓存,不阻塞返回
|
||||
musicCacheService.cacheMusic(songId, originalUrl).catch((error) => {
|
||||
console.warn('缓存歌曲失败:', error)
|
||||
})
|
||||
|
||||
return originalUrl
|
||||
} catch (e: any) {
|
||||
return {
|
||||
error: '获取歌曲失败 ' + e.error || e
|
||||
@@ -82,6 +84,10 @@ function main(source: string) {
|
||||
},
|
||||
|
||||
async getPlaylistDetail({ id, page }: GetSongListDetailsArg) {
|
||||
// 酷狗音乐特殊处理:直接调用getUserListDetail
|
||||
if (source === 'kg' && /https?:\/\//.test(id)) {
|
||||
return (await Api.songList.getUserListDetail(id, page)) as PlaylistDetailResult
|
||||
}
|
||||
return (await Api.songList.getListDetail(id, page)) as PlaylistDetailResult
|
||||
},
|
||||
|
||||
@@ -89,6 +95,13 @@ function main(source: string) {
|
||||
const url = await this.getMusicUrl({ pluginId, songInfo, quality })
|
||||
if (typeof url === 'object') throw new Error('无法获取歌曲链接')
|
||||
|
||||
// 获取自定义下载目录
|
||||
const getDownloadDirectory = (): string => {
|
||||
// 使用配置管理服务获取下载目录
|
||||
const directories = configManager.getDirectories()
|
||||
return directories.downloadDir
|
||||
}
|
||||
|
||||
// 从URL中提取文件扩展名,如果没有则默认为mp3
|
||||
const getFileExtension = (url: string): string => {
|
||||
try {
|
||||
@@ -110,11 +123,10 @@ function main(source: string) {
|
||||
}
|
||||
|
||||
const fileExtension = getFileExtension(url)
|
||||
const downloadDir = getDownloadDirectory()
|
||||
const songPath = path.join(
|
||||
getAppDirPath('music'),
|
||||
'CeruMusic',
|
||||
'songs',
|
||||
`${songInfo.name}-${songInfo.singer}-${source}.${fileExtension}`
|
||||
downloadDir,
|
||||
`${songInfo.name}-${songInfo.singer}-${songInfo.source}.${fileExtension}`
|
||||
.replace(/[/\\:*?"<>|]/g, '')
|
||||
.replace(/^\.+/, '')
|
||||
.replace(/\.+$/, '')
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2025. 时迁酱 Inc. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of 时迁酱.
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* @author 时迁酱,无聊的霜霜,Star
|
||||
* @since 2025-9-19
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
import * as vm from 'vm'
|
||||
import fetch from 'node-fetch'
|
||||
import * as fs from 'fs'
|
||||
import { MusicItem } from '../../musicSdk/type'
|
||||
import { sendPluginNotice } from '../../../events/pluginNotice'
|
||||
|
||||
// 定义插件结构接口
|
||||
// ==================== 常量定义 ====================
|
||||
const CONSTANTS = {
|
||||
DEFAULT_TIMEOUT: 10000, // 10秒超时
|
||||
API_VERSION: '1.0.3',
|
||||
ENVIRONMENT: 'nodejs',
|
||||
NOTICE_DELAY: 100, // 通知延迟时间
|
||||
LOG_PREFIX: '[CeruMusic]'
|
||||
} as const
|
||||
|
||||
// ==================== 类型定义 ====================
|
||||
export interface PluginInfo {
|
||||
name: string
|
||||
version: string
|
||||
@@ -33,7 +54,7 @@ interface MusicInfo extends MusicItem {
|
||||
interface RequestResult {
|
||||
body: any
|
||||
statusCode: number
|
||||
headers: Record<string, string[]>
|
||||
headers: Record<string, string>
|
||||
}
|
||||
|
||||
interface CeruMusicApiUtils {
|
||||
@@ -52,12 +73,26 @@ interface CeruMusicApi {
|
||||
options?: RequestOptions | RequestCallback,
|
||||
callback?: RequestCallback
|
||||
) => Promise<RequestResult> | void
|
||||
NoticeCenter: (
|
||||
type: 'error' | 'info' | 'success' | 'warn' | 'update',
|
||||
data: {
|
||||
title: string
|
||||
content?: string
|
||||
url?: string
|
||||
version?: string
|
||||
pluginInfo: {
|
||||
name?: string // 插件名
|
||||
type: 'lx' | 'cr' //插件类型
|
||||
}
|
||||
}
|
||||
) => void
|
||||
}
|
||||
|
||||
type RequestOptions = {
|
||||
method?: string
|
||||
headers?: Record<string, string>
|
||||
body?: any
|
||||
timeout?: number
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@@ -66,8 +101,21 @@ type RequestCallback = (error: Error | null, result: RequestResult | null) => vo
|
||||
type Logger = {
|
||||
log: (...args: any[]) => void
|
||||
error: (...args: any[]) => void
|
||||
warn?: (...args: any[]) => void
|
||||
info?: (...args: any[]) => void
|
||||
warn: (...args: any[]) => void
|
||||
info: (...args: any[]) => void
|
||||
}
|
||||
|
||||
type PluginMethodName = 'musicUrl' | 'getPic' | 'getLyric'
|
||||
|
||||
// ==================== 错误类定义 ====================
|
||||
class PluginError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly method?: string
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'PluginError'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,160 +133,27 @@ class CeruMusicPluginHost {
|
||||
*/
|
||||
constructor(pluginCode: string | null = null, logger: Logger = console) {
|
||||
this.pluginCode = pluginCode
|
||||
this.plugin = null // 存储插件导出的对象
|
||||
this.plugin = null
|
||||
|
||||
if (pluginCode) {
|
||||
this._initialize(logger)
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 公共方法 ====================
|
||||
|
||||
/**
|
||||
* 从文件加载插件
|
||||
* @param pluginPath 插件文件路径
|
||||
* @param logger 日志记录器
|
||||
*/
|
||||
async loadPlugin(pluginPath: string, logger: Logger = console): Promise<CeruMusicPlugin> {
|
||||
this.pluginCode = fs.readFileSync(pluginPath, 'utf-8')
|
||||
this._initialize(logger)
|
||||
return this.plugin as CeruMusicPlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化沙箱环境,加载并验证插件
|
||||
* @private
|
||||
*/
|
||||
_initialize(console: Logger): void {
|
||||
// 提供给插件的API
|
||||
const cerumusicApi: CeruMusicApi = {
|
||||
env: 'nodejs',
|
||||
version: '1.0.0',
|
||||
utils: {
|
||||
buffer: {
|
||||
from: (data: string | Buffer | ArrayBuffer, encoding?: BufferEncoding) => {
|
||||
if (typeof data === 'string') {
|
||||
return Buffer.from(data, encoding)
|
||||
} else if (data instanceof Buffer) {
|
||||
return data
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
return Buffer.from(new Uint8Array(data))
|
||||
} else {
|
||||
return Buffer.from(data as any)
|
||||
}
|
||||
},
|
||||
bufToString: (buffer: Buffer, encoding?: BufferEncoding) => buffer.toString(encoding)
|
||||
}
|
||||
},
|
||||
request: (url, options, callback) => {
|
||||
// 支持 Promise 和 callback 两种调用方式
|
||||
if (typeof options === 'function') {
|
||||
callback = options as RequestCallback
|
||||
options = { method: 'GET' }
|
||||
}
|
||||
|
||||
const makeRequest = async (): Promise<RequestResult> => {
|
||||
try {
|
||||
console.log(`[CeruMusic] 发起请求: ${url}`)
|
||||
|
||||
// 添加超时设置
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10000) // 10秒超时
|
||||
|
||||
const requestOptions = {
|
||||
method: 'GET',
|
||||
...(options as RequestOptions),
|
||||
signal: controller.signal
|
||||
}
|
||||
|
||||
const response = await fetch(url, requestOptions)
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
console.log(`[CeruMusic] 请求响应状态: ${response.status}`)
|
||||
|
||||
// 尝试解析JSON,如果失败则返回文本
|
||||
let body: any
|
||||
try {
|
||||
body = await response.json()
|
||||
} catch (parseError: any) {
|
||||
console.error(`[CeruMusic] 解析响应失败: ${parseError.message}`)
|
||||
// 解析失败时创建错误body
|
||||
body = {
|
||||
code: response.status,
|
||||
msg: `Failed to parse response: ${parseError.message}`
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[CeruMusic] 请求响应内容:`, body)
|
||||
|
||||
const result: RequestResult = {
|
||||
body,
|
||||
statusCode: response.status,
|
||||
headers: response.headers.raw()
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(null, result)
|
||||
}
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[CeruMusic] Request failed: ${error.message}`)
|
||||
|
||||
if (callback) {
|
||||
// 网络错误时,调用 callback(error, null)
|
||||
callback(error, null)
|
||||
// 需要返回一个值以满足 Promise<RequestResult> 类型
|
||||
return {
|
||||
body: { error: error.message },
|
||||
statusCode: 500,
|
||||
headers: {}
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
makeRequest().catch((error) => {
|
||||
console.error(`[CeruMusic] Unhandled request error in callback mode: ${error.message}`)
|
||||
}) // 确保错误被正确处理
|
||||
return undefined
|
||||
} else {
|
||||
return makeRequest()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sandbox = {
|
||||
module: { exports: {} },
|
||||
cerumusic: cerumusicApi,
|
||||
console: console,
|
||||
setTimeout: setTimeout,
|
||||
clearTimeout: clearTimeout,
|
||||
setInterval: setInterval,
|
||||
clearInterval: clearInterval,
|
||||
Buffer: Buffer,
|
||||
JSON: JSON,
|
||||
require: () => ({}),
|
||||
global: {},
|
||||
process: { env: {} }
|
||||
}
|
||||
|
||||
try {
|
||||
// 在沙箱中执行插件代码
|
||||
if (this.pluginCode) {
|
||||
vm.runInNewContext(this.pluginCode, sandbox)
|
||||
this.plugin = sandbox.module.exports as CeruMusicPlugin
|
||||
console.log(`[CeruMusic] Plugin "${this.plugin.pluginInfo.name}" loaded successfully.`)
|
||||
} else {
|
||||
throw new Error('No plugin code provided.')
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('[CeruMusic] Error executing plugin code:', e)
|
||||
throw new Error('Failed to initialize plugin.')
|
||||
}
|
||||
|
||||
// 验证插件结构
|
||||
if (!this.plugin?.pluginInfo || !this.plugin.sources || !this.plugin.musicUrl) {
|
||||
throw new Error('Invalid plugin structure. Required fields: pluginInfo, sources, musicUrl.')
|
||||
this.pluginCode = fs.readFileSync(pluginPath, 'utf-8')
|
||||
this._initialize(logger)
|
||||
return this.plugin as CeruMusicPlugin
|
||||
} catch (error: any) {
|
||||
throw new PluginError(`无法加载插件 ${pluginPath}: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,10 +161,8 @@ class CeruMusicPluginHost {
|
||||
* 获取插件信息
|
||||
*/
|
||||
getPluginInfo(): PluginInfo {
|
||||
if (!this.plugin) {
|
||||
throw new Error('Plugin not initialized')
|
||||
}
|
||||
return this.plugin.pluginInfo
|
||||
this._ensurePluginInitialized()
|
||||
return this.plugin!.pluginInfo
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,10 +176,8 @@ class CeruMusicPluginHost {
|
||||
* 获取支持的音源和音质信息
|
||||
*/
|
||||
getSupportedSources(): PluginSource[] {
|
||||
if (!this.plugin) {
|
||||
throw new Error('Plugin not initialized')
|
||||
}
|
||||
return this.plugin.sources
|
||||
this._ensurePluginInitialized()
|
||||
return this.plugin!.sources
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,148 +187,7 @@ class CeruMusicPluginHost {
|
||||
* @param quality 音质
|
||||
*/
|
||||
async getMusicUrl(source: string, musicInfo: MusicInfo, quality: string): Promise<string> {
|
||||
try {
|
||||
if (!this.plugin || typeof this.plugin.musicUrl !== 'function') {
|
||||
throw new Error(`Action "musicUrl" is not implemented in plugin.`)
|
||||
}
|
||||
|
||||
console.log(`[CeruMusic] 开始调用插件的 musicUrl 方法...`)
|
||||
|
||||
// 将 cerumusic API 绑定到函数调用的 this 上下文
|
||||
const result = await this.plugin.musicUrl.call(
|
||||
{ cerumusic: this._getCerumusicApi() },
|
||||
source,
|
||||
musicInfo,
|
||||
quality
|
||||
)
|
||||
|
||||
console.log(`[CeruMusic] 插件 musicUrl 方法调用成功`)
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[CeruMusic] getMusicUrl 方法执行失败:`, error.message)
|
||||
console.error(`[CeruMusic] 错误堆栈:`, error.stack)
|
||||
|
||||
// 重新抛出错误,确保外部可以捕获
|
||||
throw new Error(`Plugin getMusicUrl failed: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 cerumusic API 对象
|
||||
* @private
|
||||
*/
|
||||
_getCerumusicApi(): CeruMusicApi {
|
||||
return {
|
||||
env: 'nodejs',
|
||||
version: '1.0.0',
|
||||
utils: {
|
||||
buffer: {
|
||||
from: (data: string | Buffer | ArrayBuffer, encoding?: BufferEncoding) => {
|
||||
if (typeof data === 'string') {
|
||||
return Buffer.from(data, encoding)
|
||||
} else if (data instanceof Buffer) {
|
||||
return data
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
return Buffer.from(new Uint8Array(data))
|
||||
} else {
|
||||
return Buffer.from(data as any)
|
||||
}
|
||||
},
|
||||
bufToString: (buffer: Buffer, encoding?: BufferEncoding) => buffer.toString(encoding)
|
||||
}
|
||||
},
|
||||
request: (url, options, callback) => {
|
||||
// 支持 Promise 和 callback 两种调用方式
|
||||
if (typeof options === 'function') {
|
||||
callback = options as RequestCallback
|
||||
options = { method: 'GET' }
|
||||
}
|
||||
|
||||
const makeRequest = async (): Promise<RequestResult> => {
|
||||
try {
|
||||
console.log(`[CeruMusic] 发起请求: ${url}`)
|
||||
|
||||
// 添加超时设置
|
||||
const controller = new AbortController()
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10000) // 10秒超时
|
||||
|
||||
const requestOptions = {
|
||||
method: 'GET',
|
||||
...(options as RequestOptions),
|
||||
signal: controller.signal
|
||||
}
|
||||
|
||||
const response = await fetch(url, requestOptions)
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
console.log(`[CeruMusic] 请求响应状态: ${response.status}`)
|
||||
|
||||
// 尝试解析JSON,如果失败则返回文本
|
||||
let body: any
|
||||
const contentType = response.headers.get('content-type')
|
||||
|
||||
try {
|
||||
if (contentType && contentType.includes('application/json')) {
|
||||
body = await response.json()
|
||||
} else {
|
||||
const text = await response.text()
|
||||
console.log(`[CeruMusic] 响应不是JSON格式,内容: ${text.substring(0, 200)}...`)
|
||||
// 对于非JSON响应,创建一个错误状态的body
|
||||
body = {
|
||||
code: response.status,
|
||||
msg: `Expected JSON response but got: ${contentType || 'unknown content type'}`,
|
||||
data: text
|
||||
}
|
||||
}
|
||||
} catch (parseError: any) {
|
||||
console.error(`[CeruMusic] 解析响应失败: ${parseError.message}`)
|
||||
// 解析失败时创建错误body
|
||||
body = {
|
||||
code: response.status,
|
||||
msg: `Failed to parse response: ${parseError.message}`
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[CeruMusic] 请求响应内容:`, body)
|
||||
|
||||
const result: RequestResult = {
|
||||
body,
|
||||
statusCode: response.status,
|
||||
headers: response.headers.raw()
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(null, result)
|
||||
}
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[CeruMusic] Request failed: ${error.message}`)
|
||||
|
||||
if (callback) {
|
||||
// 网络错误时,调用 callback(error, null)
|
||||
callback(error, null)
|
||||
// 需要返回一个值以满足 Promise<RequestResult> 类型
|
||||
return {
|
||||
body: { error: error.message },
|
||||
statusCode: 500,
|
||||
headers: {}
|
||||
}
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
makeRequest().catch((error) => {
|
||||
console.error(`[CeruMusic] Unhandled request error in callback mode: ${error.message}`)
|
||||
}) // 确保错误被正确处理
|
||||
return undefined
|
||||
} else {
|
||||
return makeRequest()
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._callPluginMethod('musicUrl', source, musicInfo, quality)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,25 +196,7 @@ class CeruMusicPluginHost {
|
||||
* @param musicInfo 音乐信息
|
||||
*/
|
||||
async getPic(source: string, musicInfo: MusicInfo): Promise<string> {
|
||||
try {
|
||||
if (!this.plugin || typeof this.plugin.getPic !== 'function') {
|
||||
throw new Error(`Action "getPic" is not implemented in plugin.`)
|
||||
}
|
||||
|
||||
console.log(`[CeruMusic] 开始调用插件的 getPic 方法...`)
|
||||
|
||||
const result = await this.plugin.getPic.call(
|
||||
{ cerumusic: this._getCerumusicApi() },
|
||||
source,
|
||||
musicInfo
|
||||
)
|
||||
|
||||
console.log(`[CeruMusic] 插件 getPic 方法调用成功`)
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[CeruMusic] getPic 方法执行失败:`, error.message)
|
||||
throw new Error(`Plugin getPic failed: ${error.message}`)
|
||||
}
|
||||
return this._callPluginMethod('getPic', source, musicInfo)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,24 +205,364 @@ class CeruMusicPluginHost {
|
||||
* @param musicInfo 音乐信息
|
||||
*/
|
||||
async getLyric(source: string, musicInfo: MusicInfo): Promise<string> {
|
||||
return this._callPluginMethod('getLyric', source, musicInfo)
|
||||
}
|
||||
|
||||
// ==================== 私有方法 ====================
|
||||
|
||||
/**
|
||||
* 初始化沙箱环境,加载并验证插件
|
||||
* @private
|
||||
*/
|
||||
private _initialize(logger: Logger): void {
|
||||
if (!this.pluginCode) {
|
||||
throw new PluginError('No plugin code provided.')
|
||||
}
|
||||
|
||||
const sandbox = this._createSandbox(logger)
|
||||
|
||||
try {
|
||||
if (!this.plugin || typeof this.plugin.getLyric !== 'function') {
|
||||
throw new Error(`Action "getLyric" is not implemented in plugin.`)
|
||||
}
|
||||
vm.runInNewContext(this.pluginCode, sandbox)
|
||||
this.plugin = sandbox.module.exports as CeruMusicPlugin
|
||||
|
||||
console.log(`[CeruMusic] 开始调用插件的 getLyric 方法...`)
|
||||
this._validatePlugin()
|
||||
|
||||
const result = await this.plugin.getLyric.call(
|
||||
{ cerumusic: this._getCerumusicApi() },
|
||||
source,
|
||||
musicInfo
|
||||
logger.log(
|
||||
`${CONSTANTS.LOG_PREFIX} Plugin "${this.plugin.pluginInfo.name}" loaded successfully.`
|
||||
)
|
||||
} catch (error: any) {
|
||||
logger.error(`${CONSTANTS.LOG_PREFIX} Error executing plugin code:`, error)
|
||||
throw new PluginError('Failed to initialize plugin.')
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[CeruMusic] 插件 getLyric 方法调用成功`)
|
||||
/**
|
||||
* 创建沙箱环境
|
||||
* @private
|
||||
*/
|
||||
private _createSandbox(logger: Logger): any {
|
||||
return {
|
||||
module: { exports: {} },
|
||||
cerumusic: this._getCerumusicApi(),
|
||||
console: logger,
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
setInterval,
|
||||
clearInterval,
|
||||
Buffer,
|
||||
JSON,
|
||||
require: () => ({}),
|
||||
global: {},
|
||||
process: { env: {} }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证插件结构
|
||||
* @private
|
||||
*/
|
||||
private _validatePlugin(): void {
|
||||
if (!this.plugin?.pluginInfo || !this.plugin.sources || !this.plugin.musicUrl) {
|
||||
throw new PluginError(
|
||||
'Invalid plugin structure. Required fields: pluginInfo, sources, musicUrl.'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保插件已初始化
|
||||
* @private
|
||||
*/
|
||||
private _ensurePluginInitialized(): void {
|
||||
if (!this.plugin) {
|
||||
throw new PluginError('Plugin not initialized')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的插件方法调用逻辑
|
||||
* @private
|
||||
*/
|
||||
private async _callPluginMethod(
|
||||
methodName: PluginMethodName,
|
||||
...args: readonly any[]
|
||||
): Promise<string> {
|
||||
this._ensurePluginInitialized()
|
||||
const method = this.plugin![methodName] as any
|
||||
if (typeof method !== 'function') {
|
||||
throw new PluginError(`Action "${methodName}" is not implemented in plugin.`, methodName)
|
||||
}
|
||||
try {
|
||||
console.log(`${CONSTANTS.LOG_PREFIX} 开始调用插件的 ${methodName} 方法...`)
|
||||
|
||||
const result = await method.call(...[{ cerumusic: this._getCerumusicApi() }], ...args)
|
||||
|
||||
console.log(`${CONSTANTS.LOG_PREFIX} 插件 ${methodName} 方法调用成功`)
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[CeruMusic] getLyric 方法执行失败:`, error.message)
|
||||
throw new Error(`Plugin getLyric failed: ${error.message}`)
|
||||
console.error(`${CONSTANTS.LOG_PREFIX} ${methodName} 方法执行失败:`, error.message)
|
||||
if (methodName === 'musicUrl') {
|
||||
console.error(`${CONSTANTS.LOG_PREFIX} 错误堆栈:`, error.stack)
|
||||
}
|
||||
throw new PluginError(`Plugin ${methodName} failed: ${error.message}`, methodName)
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 工具方法 ====================
|
||||
|
||||
// /**
|
||||
// * 验证 URL 是否有效
|
||||
// * @private
|
||||
// */
|
||||
// private _isValidUrl(url: string): boolean {
|
||||
// try {
|
||||
// const urlObj = new URL(url)
|
||||
// return urlObj.protocol === 'http:' || urlObj.protocol === 'https:'
|
||||
// } catch {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 根据通知类型获取标题
|
||||
// * @private
|
||||
// */
|
||||
// private _getNoticeTitle(type: string): string {
|
||||
// const titleMap: Record<string, string> = {
|
||||
// update: '插件更新',
|
||||
// error: '插件错误',
|
||||
// warning: '插件警告',
|
||||
// info: '插件信息',
|
||||
// success: '操作成功'
|
||||
// }
|
||||
// return titleMap[type] || '插件通知'
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 根据通知类型获取默认消息
|
||||
// * @private
|
||||
// */
|
||||
// private _getDefaultMessage(type: string, data: any): string {
|
||||
// const pluginName = this.plugin?.pluginInfo?.name || '未知插件'
|
||||
|
||||
// switch (type) {
|
||||
// case 'error':
|
||||
// return `插件 "${pluginName}" 发生错误: ${data?.error || '未知错误'}`
|
||||
// case 'warning':
|
||||
// return `插件 "${pluginName}" 警告: ${data?.warning || '需要注意'}`
|
||||
// case 'success':
|
||||
// return `插件 "${pluginName}" 操作成功`
|
||||
// case 'info':
|
||||
// default:
|
||||
// return `插件 "${pluginName}" 信息: ${JSON.stringify(data)}`
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 解析响应体
|
||||
* @private
|
||||
*/
|
||||
private async _parseResponseBody(response: any): Promise<any> {
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
|
||||
try {
|
||||
if (contentType.includes('application/json')) {
|
||||
return await response.json()
|
||||
} else if (contentType.includes('text/')) {
|
||||
return await response.text()
|
||||
} else {
|
||||
// 对于其他类型,尝试解析为 JSON,失败则返回文本
|
||||
const text = await response.text()
|
||||
try {
|
||||
return JSON.parse(text)
|
||||
} catch {
|
||||
return text
|
||||
}
|
||||
}
|
||||
} catch (parseError: any) {
|
||||
console.error(`${CONSTANTS.LOG_PREFIX} 解析响应失败: ${parseError.message}`)
|
||||
return {
|
||||
error: 'Parse failed',
|
||||
message: parseError.message,
|
||||
statusCode: response.status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建错误结果
|
||||
* @private
|
||||
*/
|
||||
private _createErrorResult(error: any, url: string): RequestResult {
|
||||
const isTimeout = error.name === 'AbortError'
|
||||
return {
|
||||
body: {
|
||||
error: error.name || 'RequestError',
|
||||
message: error.message,
|
||||
url
|
||||
},
|
||||
statusCode: isTimeout ? 408 : 500,
|
||||
headers: {}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== API 构建方法 ====================
|
||||
|
||||
/**
|
||||
* 获取 cerumusic API 对象
|
||||
* @private
|
||||
*/
|
||||
private _getCerumusicApi(): CeruMusicApi {
|
||||
return {
|
||||
env: CONSTANTS.ENVIRONMENT,
|
||||
version: CONSTANTS.API_VERSION,
|
||||
utils: this._createApiUtils(),
|
||||
request: this._createRequestFunction(),
|
||||
NoticeCenter: this._createNoticeCenter()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 API 工具对象
|
||||
* @private
|
||||
*/
|
||||
private _createApiUtils(): CeruMusicApiUtils {
|
||||
return {
|
||||
buffer: {
|
||||
from: (data: string | Buffer | ArrayBuffer, encoding?: BufferEncoding) => {
|
||||
if (typeof data === 'string') {
|
||||
return Buffer.from(data, encoding)
|
||||
} else if (data instanceof Buffer) {
|
||||
return data
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
return Buffer.from(new Uint8Array(data))
|
||||
} else {
|
||||
return Buffer.from(data as any)
|
||||
}
|
||||
},
|
||||
bufToString: (buffer: Buffer, encoding?: BufferEncoding) => buffer.toString(encoding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建请求函数
|
||||
* @private
|
||||
*/
|
||||
private _createRequestFunction() {
|
||||
return (
|
||||
url: string,
|
||||
options?: RequestOptions | RequestCallback,
|
||||
callback?: RequestCallback
|
||||
) => {
|
||||
// 支持 Promise 和 callback 两种调用方式
|
||||
if (typeof options === 'function') {
|
||||
callback = options as RequestCallback
|
||||
options = { method: 'GET' }
|
||||
}
|
||||
|
||||
const requestOptions = options as RequestOptions
|
||||
const makeRequest = () => this._makeHttpRequest(url, requestOptions)
|
||||
|
||||
// 执行请求
|
||||
if (callback) {
|
||||
makeRequest()
|
||||
.then((result) => callback(null, result))
|
||||
.catch((error) => {
|
||||
const errorResult = this._createErrorResult(error, url)
|
||||
callback(error, errorResult)
|
||||
})
|
||||
return undefined
|
||||
} else {
|
||||
return makeRequest()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行 HTTP 请求
|
||||
* @private
|
||||
*/
|
||||
private async _makeHttpRequest(url: string, options: RequestOptions): Promise<RequestResult> {
|
||||
const controller = new AbortController()
|
||||
const timeout = options.timeout || CONSTANTS.DEFAULT_TIMEOUT
|
||||
|
||||
const timeoutId = setTimeout(() => {
|
||||
controller.abort()
|
||||
console.warn(`${CONSTANTS.LOG_PREFIX} 请求超时: ${url}`)
|
||||
}, timeout)
|
||||
|
||||
try {
|
||||
console.log(`${CONSTANTS.LOG_PREFIX} 发起请求: ${options.method || 'GET'} ${url}`)
|
||||
|
||||
const fetchOptions = {
|
||||
method: 'GET',
|
||||
...options,
|
||||
signal: controller.signal
|
||||
}
|
||||
|
||||
const response = await fetch(url, fetchOptions)
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
console.log(`${CONSTANTS.LOG_PREFIX} 请求响应: ${response.status} ${response.statusText}`)
|
||||
|
||||
const body = await this._parseResponseBody(response)
|
||||
const headers = this._extractHeaders(response)
|
||||
|
||||
const result: RequestResult = {
|
||||
body,
|
||||
statusCode: response.status,
|
||||
headers
|
||||
}
|
||||
|
||||
console.log(`${CONSTANTS.LOG_PREFIX} 请求完成:`, {
|
||||
url,
|
||||
status: response.status,
|
||||
bodyType: typeof body
|
||||
})
|
||||
|
||||
return result
|
||||
} catch (error: any) {
|
||||
clearTimeout(timeoutId)
|
||||
|
||||
const errorMessage =
|
||||
error.name === 'AbortError' ? `请求超时: ${url}` : `请求失败: ${error.message}`
|
||||
|
||||
console.error(`${CONSTANTS.LOG_PREFIX} ${errorMessage}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取响应头
|
||||
* @private
|
||||
*/
|
||||
private _extractHeaders(response: any): Record<string, string> {
|
||||
const headers: Record<string, string> = {}
|
||||
response.headers.forEach((value: string, key: string) => {
|
||||
headers[key] = value
|
||||
})
|
||||
return headers
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建通知中心
|
||||
* @private
|
||||
*/
|
||||
private _createNoticeCenter() {
|
||||
return (type: string, data: any) => {
|
||||
const sendNotice = () => {
|
||||
if (this.plugin?.pluginInfo) {
|
||||
sendPluginNotice(
|
||||
{ type: type as any, data, currentVersion: this.plugin.pluginInfo.version },
|
||||
this.plugin.pluginInfo.name
|
||||
)
|
||||
} else {
|
||||
// 如果插件还未初始化,延迟执行
|
||||
setTimeout(sendNotice, CONSTANTS.NOTICE_DELAY)
|
||||
}
|
||||
}
|
||||
sendNotice()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ function extractDefaultSources() {
|
||||
};
|
||||
});
|
||||
|
||||
console.log('提取的音源配置:', extractedSources);
|
||||
return extractedSources;
|
||||
} catch (e) {
|
||||
console.log('解析 MUSIC_QUALITY 失败:', e.message);
|
||||
@@ -94,6 +93,70 @@ sources = extractDefaultSources();
|
||||
let isInitialized = false;
|
||||
let pluginSources = {};
|
||||
let requestHandler = null;
|
||||
let updateAlertSent = false; // 防止重复发送更新提示
|
||||
|
||||
// 处理更新提示事件
|
||||
function handleUpdateAlert(data, cerumusicApi) {
|
||||
// 每次运行脚本只能调用一次
|
||||
if (updateAlertSent) {
|
||||
console.warn(\`[${pluginName}] updateAlert 事件每次运行脚本只能调用一次,忽略重复调用\`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data || !data.log) {
|
||||
console.error(\`[${pluginName}] updateAlert 事件缺少必需的 log 参数\`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证和处理参数
|
||||
let log = String(data.log);
|
||||
let updateUrl = data.updateUrl ? String(data.updateUrl) : undefined;
|
||||
|
||||
// 限制 log 长度为 1024 字符
|
||||
if (log.length > 1024) {
|
||||
log = log.substring(0, 1024);
|
||||
console.warn(\`[${pluginName}] 更新日志超过 1024 字符,已截断\`);
|
||||
}
|
||||
|
||||
// 验证 updateUrl 格式
|
||||
if (updateUrl) {
|
||||
if (updateUrl.length > 1024) {
|
||||
updateUrl = updateUrl.substring(0, 1024);
|
||||
console.warn(\`[${pluginName}] 更新地址超过 1024 字符,已截断\`);
|
||||
}
|
||||
|
||||
if (!updateUrl.startsWith('http://') && !updateUrl.startsWith('https://')) {
|
||||
console.error(\`[${pluginName}] updateUrl 必须是 HTTP 协议的 URL 地址\`);
|
||||
updateUrl = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// 标记已发送
|
||||
updateAlertSent = true;
|
||||
|
||||
// 通过 CeruMusic 的通知系统发送更新提示
|
||||
try {
|
||||
// 使用传入的 cerumusic API 对象发送通知
|
||||
if (cerumusicApi && cerumusicApi.NoticeCenter) {
|
||||
cerumusicApi.NoticeCenter('update', {
|
||||
title: \`${pluginName} 有新版本可用\`,
|
||||
content: log,
|
||||
url: updateUrl,
|
||||
pluginInfo: {
|
||||
name: '${pluginName}',
|
||||
type: 'lx',
|
||||
forcedUpdate: false
|
||||
}
|
||||
});
|
||||
|
||||
console.log(\`[${pluginName}] 更新提示已发送\`, { log: log.substring(0, 100) + '...', updateUrl });
|
||||
} else {
|
||||
console.error(\`[${pluginName}] CeruMusic API 不可用,无法发送更新提示\`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(\`[${pluginName}] 发送更新提示失败:\`, error.message);
|
||||
}
|
||||
}
|
||||
initializePlugin()
|
||||
function initializePlugin() {
|
||||
if (isInitialized) return;
|
||||
@@ -133,9 +196,9 @@ function initializePlugin() {
|
||||
qualitys: sourceInfo.qualitys || originalQualitys || ['128k', '320k']
|
||||
};
|
||||
});
|
||||
|
||||
console.log('[${pluginName + ' by Ceru插件' || 'ceru插件'}] 音源注册完成:', Object.keys(pluginSources));
|
||||
console.log('[${pluginName + ' by Ceru插件' || 'ceru插件'}] 动态音源信息已更新:', sources);
|
||||
} else if (event === 'updateAlert' && data) {
|
||||
// 处理更新提示事件,传入 cerumusic API
|
||||
handleUpdateAlert(data, cerumusic);
|
||||
}
|
||||
},
|
||||
request: request,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// 导入通用工具函数
|
||||
import { dateFormat } from '../../common/utils/common'
|
||||
import { dateFormat } from '@common/utils/common'
|
||||
|
||||
// 导出通用工具函数
|
||||
export * from '../../common/utils/nodejs'
|
||||
export * from '../../common/utils/common'
|
||||
export * from '../../common/utils/tools'
|
||||
|
||||
/**
|
||||
* 格式化播放数量
|
||||
|
||||
@@ -24,5 +24,4 @@ const kg = {
|
||||
return `https://www.kugou.com/song/#hash=${songInfo.hash}&album_id=${songInfo.albumId}`
|
||||
}
|
||||
}
|
||||
|
||||
export default kg
|
||||
|
||||
BIN
src/main/utils/musicSdk/tx/__pycache__/des.cpython-313.pyc
Normal file
@@ -21,5 +21,4 @@ const tx = {
|
||||
return `https://y.qq.com/n/yqq/song/${songInfo.songmid}.html`
|
||||
}
|
||||
}
|
||||
|
||||
export default tx
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
import qrcDecrypt from './qrc-decrypt'
|
||||
import { httpFetch } from '../../request'
|
||||
import getMusicInfo from './musicInfo'
|
||||
|
||||
const songIdMap = new Map()
|
||||
const promises = new Map()
|
||||
const decode = qrcDecrypt()
|
||||
|
||||
export default {
|
||||
rxps: {
|
||||
info: /^{"/,
|
||||
lineTime: /^\[(\d+),\d+\]/,
|
||||
lineTime2: /^\[([\d:.]+)\]/,
|
||||
wordTime: /\(\d+,\d+,\d+\)/,
|
||||
wordTimeAll: /(\(\d+,\d+,\d+\))/g,
|
||||
timeLabelFixRxp: /(?:\.0+|0+)$/,
|
||||
},
|
||||
msFormat(timeMs) {
|
||||
if (Number.isNaN(timeMs)) return ''
|
||||
let ms = timeMs % 1000
|
||||
timeMs /= 1000
|
||||
let m = parseInt(timeMs / 60).toString().padStart(2, '0')
|
||||
timeMs %= 60
|
||||
let s = parseInt(timeMs).toString().padStart(2, '0')
|
||||
return `[${m}:${s}.${String(ms).padStart(3, '0')}]`
|
||||
},
|
||||
successCode: 0,
|
||||
async getSongId({ songId, songmid }) {
|
||||
if (songId) return songId
|
||||
@@ -17,6 +36,184 @@ export default {
|
||||
promises.delete(songmid)
|
||||
return info.songId
|
||||
},
|
||||
removeTag(str) {
|
||||
return str.replace(/^[\S\s]*?LyricContent="/, '').replace(/"\/>[\S\s]*?$/, '')
|
||||
},
|
||||
parseCeru(lrc) {
|
||||
lrc = lrc.trim()
|
||||
lrc = lrc.replace(/\r/g, '')
|
||||
if (!lrc) return { lyric: '', lxlyric: '' }
|
||||
const lines = lrc.split('\n')
|
||||
|
||||
const lxlrcLines = []
|
||||
const lrcLines = []
|
||||
|
||||
for (let line of lines) {
|
||||
line = line.trim()
|
||||
let result = this.rxps.lineTime.exec(line)
|
||||
if (!result) {
|
||||
if (line.startsWith('[offset')) {
|
||||
lxlrcLines.push(line)
|
||||
lrcLines.push(line)
|
||||
continue
|
||||
}
|
||||
if (this.rxps.lineTime2.test(line)) {
|
||||
// lxlrcLines.push(line)
|
||||
lrcLines.push(line)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
const startMsTime = parseInt(result[1])
|
||||
const startTimeStr = this.msFormat(startMsTime)
|
||||
if (!startTimeStr) continue
|
||||
|
||||
let words = line.replace(this.rxps.lineTime, '')
|
||||
|
||||
lrcLines.push(`${startTimeStr}${words.replace(this.rxps.wordTimeAll, '')}`)
|
||||
|
||||
let times = words.match(this.rxps.wordTimeAll)
|
||||
if (!times) continue
|
||||
|
||||
let currentStart = startMsTime
|
||||
const processedTimes = []
|
||||
|
||||
times.forEach(time => {
|
||||
const result = /\((\d+),(\d+),(\d+)\)/.exec(time)
|
||||
const duration = parseInt(result[2])
|
||||
processedTimes.push(`(${currentStart},${duration},0)`)
|
||||
currentStart += duration
|
||||
})
|
||||
|
||||
const wordArr = words.split(this.rxps.wordTime)
|
||||
const newWords = processedTimes.map((time, index) => `${time}${wordArr[index]}`).join('')
|
||||
lxlrcLines.push(`${startTimeStr}${newWords}`)
|
||||
}
|
||||
return {
|
||||
lyric: lrcLines.join('\n'),
|
||||
lxlyric: lxlrcLines.join('\n'),
|
||||
}
|
||||
},
|
||||
getIntv(interval) {
|
||||
if (!interval) return 0
|
||||
if (!interval.includes('.')) interval += '.0'
|
||||
let arr = interval.split(/:|\./)
|
||||
while (arr.length < 3) arr.unshift('0')
|
||||
const [m, s, ms] = arr
|
||||
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
|
||||
},
|
||||
fixRlrcTimeTag(rlrc, lrc) {
|
||||
// console.log(lrc)
|
||||
// console.log(rlrc)
|
||||
const rlrcLines = rlrc.split('\n')
|
||||
let lrcLines = lrc.split('\n')
|
||||
// let temp = []
|
||||
let newLrc = []
|
||||
rlrcLines.forEach((line) => {
|
||||
const result = this.rxps.lineTime2.exec(line)
|
||||
if (!result) return
|
||||
const words = line.replace(this.rxps.lineTime2, '')
|
||||
if (!words.trim()) return
|
||||
const t1 = this.getIntv(result[1])
|
||||
|
||||
while (lrcLines.length) {
|
||||
const lrcLine = lrcLines.shift()
|
||||
const lrcLineResult = this.rxps.lineTime2.exec(lrcLine)
|
||||
if (!lrcLineResult) continue
|
||||
const t2 = this.getIntv(lrcLineResult[1])
|
||||
if (Math.abs(t1 - t2) < 100) {
|
||||
newLrc.push(line.replace(this.rxps.lineTime2, lrcLineResult[0]))
|
||||
break
|
||||
}
|
||||
// temp.push(line)
|
||||
}
|
||||
// lrcLines = [...temp, ...lrcLines]
|
||||
// temp = []
|
||||
})
|
||||
return newLrc.join('\n')
|
||||
},
|
||||
fixTlrcTimeTag(tlrc, lrc) {
|
||||
// console.log(lrc)
|
||||
// console.log(tlrc)
|
||||
const tlrcLines = tlrc.split('\n')
|
||||
let lrcLines = lrc.split('\n')
|
||||
// let temp = []
|
||||
let newLrc = []
|
||||
tlrcLines.forEach((line) => {
|
||||
const result = this.rxps.lineTime2.exec(line)
|
||||
if (!result) return
|
||||
const words = line.replace(this.rxps.lineTime2, '')
|
||||
if (!words.trim()) return
|
||||
let time = result[1]
|
||||
if (time.includes('.')) {
|
||||
time += ''.padStart(3 - time.split('.')[1].length, '0')
|
||||
}
|
||||
const t1 = this.getIntv(time)
|
||||
|
||||
while (lrcLines.length) {
|
||||
const lrcLine = lrcLines.shift()
|
||||
const lrcLineResult = this.rxps.lineTime2.exec(lrcLine)
|
||||
if (!lrcLineResult) continue
|
||||
const t2 = this.getIntv(lrcLineResult[1])
|
||||
if (Math.abs(t1 - t2) < 100) {
|
||||
newLrc.push(line.replace(this.rxps.lineTime2, lrcLineResult[0]))
|
||||
break
|
||||
}
|
||||
// temp.push(line)
|
||||
}
|
||||
// lrcLines = [...temp, ...lrcLines]
|
||||
// temp = []
|
||||
})
|
||||
return newLrc.join('\n')
|
||||
},
|
||||
parse(lrc, tlrc, rlrc) {
|
||||
const info = {
|
||||
lyric: '',
|
||||
tlyric: '',
|
||||
rlyric: '',
|
||||
crlyric: '',
|
||||
|
||||
}
|
||||
if (lrc) {
|
||||
let { lyric } = this.parseCeru(this.removeTag(lrc))
|
||||
info.lyric = lyric
|
||||
info.crlyric = lrc
|
||||
}
|
||||
if (rlrc) info.rlyric = this.fixRlrcTimeTag(this.parseRlyric(this.removeTag(rlrc)), info.lyric)
|
||||
if (tlrc) info.tlyric = this.fixTlrcTimeTag(tlrc, info.lyric)
|
||||
|
||||
return info
|
||||
},
|
||||
parseRlyric(lrc) {
|
||||
lrc = lrc.trim()
|
||||
lrc = lrc.replace(/\r/g, '')
|
||||
if (!lrc) return { lyric: '', lxlyric: '' }
|
||||
const lines = lrc.split('\n')
|
||||
|
||||
const lrcLines = []
|
||||
|
||||
for (let line of lines) {
|
||||
line = line.trim()
|
||||
let result = this.rxps.lineTime.exec(line)
|
||||
if (!result) continue
|
||||
|
||||
const startMsTime = parseInt(result[1])
|
||||
const startTimeStr = this.msFormat(startMsTime)
|
||||
if (!startTimeStr) continue
|
||||
|
||||
let words = line.replace(this.rxps.lineTime, '')
|
||||
|
||||
lrcLines.push(`${startTimeStr}${words.replace(this.rxps.wordTimeAll, '')}`)
|
||||
}
|
||||
return lrcLines.join('\n')
|
||||
},
|
||||
parseLyric(lrc, tlrc, rlrc) {
|
||||
return this.parse(
|
||||
decode(lrc),
|
||||
decode(tlrc),
|
||||
decode(rlrc)
|
||||
)
|
||||
},
|
||||
getLyric(mInfo, retryNum = 0) {
|
||||
if (retryNum > 3) return Promise.reject(new Error('Get lyric failed'))
|
||||
|
||||
|
||||
522
src/main/utils/musicSdk/tx/qrc-decrypt.js
Normal file
@@ -0,0 +1,522 @@
|
||||
|
||||
import zlib from 'zlib'
|
||||
|
||||
export default () => {
|
||||
const ENCRYPT = 1
|
||||
const DECRYPT = 0
|
||||
|
||||
const sbox = [
|
||||
// sbox1
|
||||
[
|
||||
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12,
|
||||
11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1,
|
||||
7, 5, 11, 3, 14, 10, 0, 6, 13
|
||||
],
|
||||
// sbox2
|
||||
[
|
||||
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 15, 12, 0, 1, 10,
|
||||
6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2,
|
||||
11, 6, 7, 12, 0, 5, 14, 9
|
||||
],
|
||||
// sbox3
|
||||
[
|
||||
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14,
|
||||
12, 11, 15, 1, 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, 1, 10, 13, 0, 6, 9, 8, 7,
|
||||
4, 15, 14, 3, 11, 5, 2, 12
|
||||
],
|
||||
// sbox4
|
||||
[
|
||||
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12,
|
||||
1, 10, 14, 9, 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, 3, 15, 0, 6, 10, 10, 13,
|
||||
8, 9, 4, 5, 11, 12, 7, 2, 14
|
||||
],
|
||||
// sbox5
|
||||
[
|
||||
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15,
|
||||
10, 3, 9, 8, 6, 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, 11, 8, 12, 7, 1, 14, 2,
|
||||
13, 6, 15, 0, 9, 10, 4, 5, 3
|
||||
],
|
||||
// sbox6
|
||||
[
|
||||
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14,
|
||||
0, 11, 3, 8, 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, 4, 3, 2, 12, 9, 5, 15, 10,
|
||||
11, 14, 1, 7, 6, 0, 8, 13
|
||||
],
|
||||
// sbox7
|
||||
[
|
||||
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12,
|
||||
2, 15, 8, 6, 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, 6, 11, 13, 8, 1, 4, 10, 7,
|
||||
9, 5, 0, 15, 14, 2, 3, 12
|
||||
],
|
||||
// sbox8
|
||||
[
|
||||
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11,
|
||||
0, 14, 9, 2, 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, 2, 1, 14, 7, 4, 10, 8, 13,
|
||||
15, 12, 9, 0, 3, 5, 6, 11
|
||||
]
|
||||
]
|
||||
|
||||
/**
|
||||
* 从 Buffer 中提取指定位置的位,并左移指定偏移量
|
||||
* @param {Buffer} a - Buffer
|
||||
* @param {number} b - 要提取的位索引
|
||||
* @param {number} c - 位提取后的偏移量
|
||||
* @returns {number} 提取后的位
|
||||
*/
|
||||
function bitnum(a, b, c) {
|
||||
const byteIndex = Math.floor(b / 32) * 4 + 3 - Math.floor((b % 32) / 8)
|
||||
const bitInByte = 7 - (b % 8)
|
||||
const bit = (a[byteIndex] >> bitInByte) & 1
|
||||
return bit << c
|
||||
}
|
||||
|
||||
/**
|
||||
* 从整数中提取指定位置的位,并左移指定偏移量
|
||||
* @param {number} a - 整数
|
||||
* @param {number} b - 要提取的位索引
|
||||
* @param {number} c - 位提取后的偏移量
|
||||
* @returns {number} 提取后的位
|
||||
*/
|
||||
function bitnum_intr(a, b, c) {
|
||||
return (((a >>> (31 - b)) & 1) << c) | 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 从整数中提取指定位置的位,并右移指定偏移量
|
||||
* @param {number} a - 整数
|
||||
* @param {number} b - 要提取的位索引
|
||||
* @param {number} c - 位提取后的偏移量
|
||||
* @returns {number} 提取后的位
|
||||
*/
|
||||
function bitnum_intl(a, b, c) {
|
||||
return (((a << b) & 0x80000000) >>> c) | 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 对输入整数进行位运算,重新组合位
|
||||
* @param {number} a - 整数
|
||||
* @returns {number} 重新组合后的位
|
||||
*/
|
||||
function sbox_bit(a) {
|
||||
return (a & 32) | ((a & 31) >> 1) | ((a & 1) << 4) | 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始置换
|
||||
* @param {Buffer} input_data - 输入 Buffer
|
||||
* @returns {[number, number]} 初始置换后的两个32位整数
|
||||
*/
|
||||
function initial_permutation(input_data) {
|
||||
const s0 =
|
||||
bitnum(input_data, 57, 31) |
|
||||
bitnum(input_data, 49, 30) |
|
||||
bitnum(input_data, 41, 29) |
|
||||
bitnum(input_data, 33, 28) |
|
||||
bitnum(input_data, 25, 27) |
|
||||
bitnum(input_data, 17, 26) |
|
||||
bitnum(input_data, 9, 25) |
|
||||
bitnum(input_data, 1, 24) |
|
||||
bitnum(input_data, 59, 23) |
|
||||
bitnum(input_data, 51, 22) |
|
||||
bitnum(input_data, 43, 21) |
|
||||
bitnum(input_data, 35, 20) |
|
||||
bitnum(input_data, 27, 19) |
|
||||
bitnum(input_data, 19, 18) |
|
||||
bitnum(input_data, 11, 17) |
|
||||
bitnum(input_data, 3, 16) |
|
||||
bitnum(input_data, 61, 15) |
|
||||
bitnum(input_data, 53, 14) |
|
||||
bitnum(input_data, 45, 13) |
|
||||
bitnum(input_data, 37, 12) |
|
||||
bitnum(input_data, 29, 11) |
|
||||
bitnum(input_data, 21, 10) |
|
||||
bitnum(input_data, 13, 9) |
|
||||
bitnum(input_data, 5, 8) |
|
||||
bitnum(input_data, 63, 7) |
|
||||
bitnum(input_data, 55, 6) |
|
||||
bitnum(input_data, 47, 5) |
|
||||
bitnum(input_data, 39, 4) |
|
||||
bitnum(input_data, 31, 3) |
|
||||
bitnum(input_data, 23, 2) |
|
||||
bitnum(input_data, 15, 1) |
|
||||
bitnum(input_data, 7, 0) |
|
||||
0
|
||||
|
||||
const s1 =
|
||||
bitnum(input_data, 56, 31) |
|
||||
bitnum(input_data, 48, 30) |
|
||||
bitnum(input_data, 40, 29) |
|
||||
bitnum(input_data, 32, 28) |
|
||||
bitnum(input_data, 24, 27) |
|
||||
bitnum(input_data, 16, 26) |
|
||||
bitnum(input_data, 8, 25) |
|
||||
bitnum(input_data, 0, 24) |
|
||||
bitnum(input_data, 58, 23) |
|
||||
bitnum(input_data, 50, 22) |
|
||||
bitnum(input_data, 42, 21) |
|
||||
bitnum(input_data, 34, 20) |
|
||||
bitnum(input_data, 26, 19) |
|
||||
bitnum(input_data, 18, 18) |
|
||||
bitnum(input_data, 10, 17) |
|
||||
bitnum(input_data, 2, 16) |
|
||||
bitnum(input_data, 60, 15) |
|
||||
bitnum(input_data, 52, 14) |
|
||||
bitnum(input_data, 44, 13) |
|
||||
bitnum(input_data, 36, 12) |
|
||||
bitnum(input_data, 28, 11) |
|
||||
bitnum(input_data, 20, 10) |
|
||||
bitnum(input_data, 12, 9) |
|
||||
bitnum(input_data, 4, 8) |
|
||||
bitnum(input_data, 62, 7) |
|
||||
bitnum(input_data, 54, 6) |
|
||||
bitnum(input_data, 46, 5) |
|
||||
bitnum(input_data, 38, 4) |
|
||||
bitnum(input_data, 30, 3) |
|
||||
bitnum(input_data, 22, 2) |
|
||||
bitnum(input_data, 14, 1) |
|
||||
bitnum(input_data, 6, 0) |
|
||||
0
|
||||
|
||||
return [s0, s1]
|
||||
}
|
||||
|
||||
/**
|
||||
* 逆初始置换
|
||||
* @param {number} s0 - 32位整数
|
||||
* @param {number} s1 - 32位整数
|
||||
* @returns {Buffer} 逆初始置换后的 Buffer
|
||||
*/
|
||||
function inverse_permutation(s0, s1) {
|
||||
const data = Buffer.alloc(8)
|
||||
data[3] =
|
||||
bitnum_intr(s1, 7, 7) |
|
||||
bitnum_intr(s0, 7, 6) |
|
||||
bitnum_intr(s1, 15, 5) |
|
||||
bitnum_intr(s0, 15, 4) |
|
||||
bitnum_intr(s1, 23, 3) |
|
||||
bitnum_intr(s0, 23, 2) |
|
||||
bitnum_intr(s1, 31, 1) |
|
||||
bitnum_intr(s0, 31, 0) |
|
||||
0
|
||||
data[2] =
|
||||
bitnum_intr(s1, 6, 7) |
|
||||
bitnum_intr(s0, 6, 6) |
|
||||
bitnum_intr(s1, 14, 5) |
|
||||
bitnum_intr(s0, 14, 4) |
|
||||
bitnum_intr(s1, 22, 3) |
|
||||
bitnum_intr(s0, 22, 2) |
|
||||
bitnum_intr(s1, 30, 1) |
|
||||
bitnum_intr(s0, 30, 0) |
|
||||
0
|
||||
data[1] =
|
||||
bitnum_intr(s1, 5, 7) |
|
||||
bitnum_intr(s0, 5, 6) |
|
||||
bitnum_intr(s1, 13, 5) |
|
||||
bitnum_intr(s0, 13, 4) |
|
||||
bitnum_intr(s1, 21, 3) |
|
||||
bitnum_intr(s0, 21, 2) |
|
||||
bitnum_intr(s1, 29, 1) |
|
||||
bitnum_intr(s0, 29, 0) |
|
||||
0
|
||||
data[0] =
|
||||
bitnum_intr(s1, 4, 7) |
|
||||
bitnum_intr(s0, 4, 6) |
|
||||
bitnum_intr(s1, 12, 5) |
|
||||
bitnum_intr(s0, 12, 4) |
|
||||
bitnum_intr(s1, 20, 3) |
|
||||
bitnum_intr(s0, 20, 2) |
|
||||
bitnum_intr(s1, 28, 1) |
|
||||
bitnum_intr(s0, 28, 0) |
|
||||
0
|
||||
data[7] =
|
||||
bitnum_intr(s1, 3, 7) |
|
||||
bitnum_intr(s0, 3, 6) |
|
||||
bitnum_intr(s1, 11, 5) |
|
||||
bitnum_intr(s0, 11, 4) |
|
||||
bitnum_intr(s1, 19, 3) |
|
||||
bitnum_intr(s0, 19, 2) |
|
||||
bitnum_intr(s1, 27, 1) |
|
||||
bitnum_intr(s0, 27, 0) |
|
||||
0
|
||||
data[6] =
|
||||
bitnum_intr(s1, 2, 7) |
|
||||
bitnum_intr(s0, 2, 6) |
|
||||
bitnum_intr(s1, 10, 5) |
|
||||
bitnum_intr(s0, 10, 4) |
|
||||
bitnum_intr(s1, 18, 3) |
|
||||
bitnum_intr(s0, 18, 2) |
|
||||
bitnum_intr(s1, 26, 1) |
|
||||
bitnum_intr(s0, 26, 0) |
|
||||
0
|
||||
data[5] =
|
||||
bitnum_intr(s1, 1, 7) |
|
||||
bitnum_intr(s0, 1, 6) |
|
||||
bitnum_intr(s1, 9, 5) |
|
||||
bitnum_intr(s0, 9, 4) |
|
||||
bitnum_intr(s1, 17, 3) |
|
||||
bitnum_intr(s0, 17, 2) |
|
||||
bitnum_intr(s1, 25, 1) |
|
||||
bitnum_intr(s0, 25, 0) |
|
||||
0
|
||||
data[4] =
|
||||
bitnum_intr(s1, 0, 7) |
|
||||
bitnum_intr(s0, 0, 6) |
|
||||
bitnum_intr(s1, 8, 5) |
|
||||
bitnum_intr(s0, 8, 4) |
|
||||
bitnum_intr(s1, 16, 3) |
|
||||
bitnum_intr(s0, 16, 2) |
|
||||
bitnum_intr(s1, 24, 1) |
|
||||
bitnum_intr(s0, 24, 0) |
|
||||
0
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Triple-DES F函数
|
||||
* @param {number} state - 输入
|
||||
* @param {number[]} key - 密钥
|
||||
* @returns {number} 输出
|
||||
*/
|
||||
function f(state, key) {
|
||||
state = state | 0
|
||||
const t1 =
|
||||
bitnum_intl(state, 31, 0) |
|
||||
(((state & 0xf0000000) >>> 1) | 0) |
|
||||
bitnum_intl(state, 4, 5) |
|
||||
bitnum_intl(state, 3, 6) |
|
||||
(((state & 0x0f000000) >>> 3) | 0) |
|
||||
bitnum_intl(state, 8, 11) |
|
||||
bitnum_intl(state, 7, 12) |
|
||||
(((state & 0x00f00000) >>> 5) | 0) |
|
||||
bitnum_intl(state, 12, 17) |
|
||||
bitnum_intl(state, 11, 18) |
|
||||
(((state & 0x000f0000) >>> 7) | 0) |
|
||||
bitnum_intl(state, 16, 23) |
|
||||
0
|
||||
|
||||
const t2 =
|
||||
bitnum_intl(state, 15, 0) |
|
||||
(((state & 0x0000f000) << 15) | 0) |
|
||||
bitnum_intl(state, 20, 5) |
|
||||
bitnum_intl(state, 19, 6) |
|
||||
(((state & 0x00000f00) << 13) | 0) |
|
||||
bitnum_intl(state, 24, 11) |
|
||||
bitnum_intl(state, 23, 12) |
|
||||
(((state & 0x000000f0) << 11) | 0) |
|
||||
bitnum_intl(state, 28, 17) |
|
||||
bitnum_intl(state, 27, 18) |
|
||||
(((state & 0x0000000f) << 9) | 0) |
|
||||
bitnum_intl(state, 0, 23) |
|
||||
0
|
||||
|
||||
const _lrgstate = [
|
||||
(t1 >>> 24) & 0xff,
|
||||
(t1 >>> 16) & 0xff,
|
||||
(t1 >>> 8) & 0xff,
|
||||
(t2 >>> 24) & 0xff,
|
||||
(t2 >>> 16) & 0xff,
|
||||
(t2 >>> 8) & 0xff
|
||||
]
|
||||
|
||||
const lrgstate = _lrgstate.map((val, i) => val ^ key[i])
|
||||
|
||||
const newState =
|
||||
(sbox[0][sbox_bit(lrgstate[0] >>> 2)] << 28) |
|
||||
(sbox[1][sbox_bit(((lrgstate[0] & 0x03) << 4) | (lrgstate[1] >>> 4))] << 24) |
|
||||
(sbox[2][sbox_bit(((lrgstate[1] & 0x0f) << 2) | (lrgstate[2] >>> 6))] << 20) |
|
||||
(sbox[3][sbox_bit(lrgstate[2] & 0x3f)] << 16) |
|
||||
(sbox[4][sbox_bit(lrgstate[3] >>> 2)] << 12) |
|
||||
(sbox[5][sbox_bit(((lrgstate[3] & 0x03) << 4) | (lrgstate[4] >>> 4))] << 8) |
|
||||
(sbox[6][sbox_bit(((lrgstate[4] & 0x0f) << 2) | (lrgstate[5] >>> 6))] << 4) |
|
||||
sbox[7][sbox_bit(lrgstate[5] & 0x3f)] |
|
||||
0
|
||||
|
||||
return (
|
||||
bitnum_intl(newState, 15, 0) |
|
||||
bitnum_intl(newState, 6, 1) |
|
||||
bitnum_intl(newState, 19, 2) |
|
||||
bitnum_intl(newState, 20, 3) |
|
||||
bitnum_intl(newState, 28, 4) |
|
||||
bitnum_intl(newState, 11, 5) |
|
||||
bitnum_intl(newState, 27, 6) |
|
||||
bitnum_intl(newState, 16, 7) |
|
||||
bitnum_intl(newState, 0, 8) |
|
||||
bitnum_intl(newState, 14, 9) |
|
||||
bitnum_intl(newState, 22, 10) |
|
||||
bitnum_intl(newState, 25, 11) |
|
||||
bitnum_intl(newState, 4, 12) |
|
||||
bitnum_intl(newState, 17, 13) |
|
||||
bitnum_intl(newState, 30, 14) |
|
||||
bitnum_intl(newState, 9, 15) |
|
||||
bitnum_intl(newState, 1, 16) |
|
||||
bitnum_intl(newState, 7, 17) |
|
||||
bitnum_intl(newState, 23, 18) |
|
||||
bitnum_intl(newState, 13, 19) |
|
||||
bitnum_intl(newState, 31, 20) |
|
||||
bitnum_intl(newState, 26, 21) |
|
||||
bitnum_intl(newState, 2, 22) |
|
||||
bitnum_intl(newState, 8, 23) |
|
||||
bitnum_intl(newState, 18, 24) |
|
||||
bitnum_intl(newState, 12, 25) |
|
||||
bitnum_intl(newState, 29, 26) |
|
||||
bitnum_intl(newState, 5, 27) |
|
||||
bitnum_intl(newState, 21, 28) |
|
||||
bitnum_intl(newState, 10, 29) |
|
||||
bitnum_intl(newState, 3, 30) |
|
||||
bitnum_intl(newState, 24, 31) |
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* TripleDES 加密/解密算法 (单块)
|
||||
* @param {Buffer} input_data - 输入 Buffer
|
||||
* @param {number[][]} key - 密钥
|
||||
* @returns {Buffer} 加/解密后的 Buffer
|
||||
*/
|
||||
function crypt(input_data, key) {
|
||||
let [s0, s1] = initial_permutation(input_data)
|
||||
|
||||
for (let idx = 0; idx < 15; idx++) {
|
||||
const previous_s1 = s1
|
||||
s1 = (f(s1, key[idx]) ^ s0) | 0
|
||||
s0 = previous_s1
|
||||
}
|
||||
s0 = (f(s1, key[15]) ^ s0) | 0
|
||||
|
||||
return inverse_permutation(s0, s1)
|
||||
}
|
||||
|
||||
/**
|
||||
* TripleDES 密钥扩展算法
|
||||
* @param {Buffer} key - 密钥
|
||||
* @param {number} mode - 模式 (ENCRYPT/DECRYPT)
|
||||
* @returns {number[][]} 密钥扩展
|
||||
*/
|
||||
function key_schedule(key, mode) {
|
||||
const schedule = Array.from({ length: 16 }, () => Array(6).fill(0))
|
||||
const key_rnd_shift = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]
|
||||
const key_perm_c = [
|
||||
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59,
|
||||
51, 43, 35
|
||||
]
|
||||
const key_perm_d = [
|
||||
62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4,
|
||||
27, 19, 11, 3
|
||||
]
|
||||
const key_compression = [
|
||||
13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51,
|
||||
30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31
|
||||
]
|
||||
|
||||
let c = 0,
|
||||
d = 0
|
||||
for (let i = 0; i < 28; i++) {
|
||||
c |= bitnum(key, key_perm_c[i], 31 - i)
|
||||
d |= bitnum(key, key_perm_d[i], 31 - i)
|
||||
}
|
||||
c = c | 0
|
||||
d = d | 0
|
||||
|
||||
for (let i = 0; i < 16; i++) {
|
||||
const shift = key_rnd_shift[i]
|
||||
c = (((c << shift) | (c >>> (28 - shift))) & 0xfffffff0) | 0
|
||||
d = (((d << shift) | (d >>> (28 - shift))) & 0xfffffff0) | 0
|
||||
|
||||
const togen = mode === DECRYPT ? 15 - i : i
|
||||
|
||||
schedule[togen] = Array(6).fill(0)
|
||||
|
||||
for (let j = 0; j < 24; j++) {
|
||||
schedule[togen][Math.floor(j / 8)] |= bitnum_intr(c, key_compression[j], 7 - (j % 8))
|
||||
}
|
||||
|
||||
for (let j = 24; j < 48; j++) {
|
||||
schedule[togen][Math.floor(j / 8)] |= bitnum_intr(d, key_compression[j] - 27, 7 - (j % 8))
|
||||
}
|
||||
}
|
||||
return schedule
|
||||
}
|
||||
|
||||
/**
|
||||
* TripleDES 密钥设置
|
||||
* @param {Buffer} key - 密钥
|
||||
* @param {number} mode - 模式
|
||||
* @returns {number[][][]} 密钥设置
|
||||
*/
|
||||
function tripledes_key_setup(key, mode) {
|
||||
if (mode === ENCRYPT) {
|
||||
return [
|
||||
key_schedule(key.slice(0, 8), ENCRYPT),
|
||||
key_schedule(key.slice(8, 16), DECRYPT),
|
||||
key_schedule(key.slice(16, 24), ENCRYPT)
|
||||
]
|
||||
}
|
||||
return [
|
||||
key_schedule(key.slice(16, 24), DECRYPT),
|
||||
key_schedule(key.slice(8, 16), ENCRYPT),
|
||||
key_schedule(key.slice(0, 8), DECRYPT)
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* TripleDES 加密/解密算法 (完整)
|
||||
* @param {Buffer} data - 输入 Buffer
|
||||
* @param {number[][][]} key - 密钥
|
||||
* @returns {Buffer} 加/解密后的 Buffer
|
||||
*/
|
||||
function tripledes_crypt(data, key) {
|
||||
let result = data
|
||||
for (let i = 0; i < 3; i++) {
|
||||
result = crypt(result, key[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* QRC解密主函数
|
||||
* @param {string | Buffer} encrypted_qrc - 加密的QRC内容 (十六进制字符串或Buffer)
|
||||
* @returns {string} 解密后的UTF-8字符串
|
||||
*/
|
||||
function qrc_decrypt(encrypted_qrc) {
|
||||
if (!encrypted_qrc) {
|
||||
return ''
|
||||
}
|
||||
|
||||
let input_buffer
|
||||
if (typeof encrypted_qrc === 'string') {
|
||||
input_buffer = Buffer.from(encrypted_qrc, 'hex')
|
||||
} else if (Buffer.isBuffer(encrypted_qrc)) {
|
||||
input_buffer = encrypted_qrc
|
||||
} else {
|
||||
throw new Error('无效的加密数据类型')
|
||||
}
|
||||
|
||||
try {
|
||||
const decrypted_chunks = []
|
||||
const key = Buffer.from('!@#)(*$%123ZXC!@!@#)(NHL')
|
||||
const schedule = tripledes_key_setup(key, DECRYPT)
|
||||
|
||||
for (let i = 0; i < input_buffer.length; i += 8) {
|
||||
const chunk = input_buffer.slice(i, i + 8)
|
||||
if (chunk.length < 8) {
|
||||
// 如果最后一块不足8字节,DES无法处理,但QRC格式应该是8的倍数
|
||||
// 这里可以根据实际情况决定如何处理,例如抛出错误或填充
|
||||
// 根据原始代码行为,这里假设输入总是8字节的倍数
|
||||
console.warn('警告: 数据末尾存在不足8字节的块,可能导致解密不完整。')
|
||||
continue
|
||||
}
|
||||
decrypted_chunks.push(tripledes_crypt(chunk, schedule))
|
||||
}
|
||||
|
||||
const data = Buffer.concat(decrypted_chunks)
|
||||
const decompressed = zlib.unzipSync(data)
|
||||
return decompressed.toString('utf-8')
|
||||
} catch (e) {
|
||||
throw new Error(`解密失败: ${e.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 导出主函数
|
||||
return qrc_decrypt
|
||||
}
|
||||
@@ -20,8 +20,7 @@ function getAppDirPath(
|
||||
| 'logs'
|
||||
| 'crashDumps'
|
||||
) {
|
||||
const dirPath: string = electron.app.getPath(name ?? 'userData')
|
||||
return dirPath
|
||||
return electron.app.getPath(name ?? 'userData')
|
||||
}
|
||||
|
||||
export { getAppDirPath }
|
||||
|
||||
@@ -4,7 +4,6 @@ import { dateFormat } from '../../common/utils/common'
|
||||
// 导出通用工具函数
|
||||
export * from '../../common/utils/nodejs'
|
||||
export * from '../../common/utils/common'
|
||||
export * from '../../common/utils/tools'
|
||||
|
||||
/**
|
||||
* 格式化播放数量
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
import { Tray, Menu, BrowserWindow } from 'electron'
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
import path from 'node:path'
|
||||
// 使用传入的 tray 对象
|
||||
export default function useWindow(
|
||||
createWindow: { (): void; (): void },
|
||||
ipcMain: Electron.IpcMain,
|
||||
app: Electron.App,
|
||||
mainWindow: BrowserWindow | null,
|
||||
isQuitting: { value: boolean },
|
||||
trayObj: { value: Tray | null }
|
||||
) {
|
||||
function createTray(): void {
|
||||
// 创建系统托盘
|
||||
const trayIconPath = path.join(__dirname, '../../resources/logo.png')
|
||||
trayObj.value = new Tray(trayIconPath)
|
||||
|
||||
// 创建托盘菜单
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '显示窗口',
|
||||
click: () => {
|
||||
if (mainWindow) {
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '播放/暂停',
|
||||
click: () => {
|
||||
// 这里可以添加播放控制逻辑
|
||||
mainWindow?.webContents.send('music-control')
|
||||
}
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: '退出',
|
||||
click: () => {
|
||||
isQuitting.value = true
|
||||
app.quit()
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
trayObj.value.setContextMenu(contextMenu)
|
||||
trayObj.value.setToolTip('Ceru Music')
|
||||
|
||||
// 双击托盘图标显示窗口
|
||||
trayObj.value.on('click', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide()
|
||||
} else {
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId('com.cerulean.music')
|
||||
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
// 窗口控制 IPC 处理
|
||||
ipcMain.on('window-minimize', () => {
|
||||
console.log('收到 window-minimize 事件')
|
||||
if (mainWindow) {
|
||||
console.log('正在最小化窗口...')
|
||||
mainWindow.minimize()
|
||||
} else {
|
||||
console.log('mainWindow 不存在')
|
||||
const window = BrowserWindow.getFocusedWindow()
|
||||
if (window) {
|
||||
console.log('使用 getFocusedWindow 最小化窗口...')
|
||||
window.minimize()
|
||||
} else {
|
||||
console.log('没有找到可用的窗口')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('window-maximize', () => {
|
||||
console.log('收到 window-maximize 事件')
|
||||
if (mainWindow) {
|
||||
console.log('正在最大化/还原窗口...')
|
||||
if (mainWindow.isMaximized()) {
|
||||
mainWindow.unmaximize()
|
||||
} else {
|
||||
mainWindow.maximize()
|
||||
}
|
||||
} else {
|
||||
console.log('mainWindow 不存在')
|
||||
const window = BrowserWindow.getFocusedWindow()
|
||||
if (window) {
|
||||
console.log('使用 getFocusedWindow 最大化/还原窗口...')
|
||||
if (window.isMaximized()) {
|
||||
window.unmaximize()
|
||||
} else {
|
||||
window.maximize()
|
||||
}
|
||||
} else {
|
||||
console.log('没有找到可用的窗口')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('window-close', () => {
|
||||
console.log('收到 window-close 事件')
|
||||
if (mainWindow) {
|
||||
console.log('正在关闭窗口...')
|
||||
mainWindow.close()
|
||||
} else {
|
||||
console.log('mainWindow 不存在')
|
||||
const window = BrowserWindow.getFocusedWindow()
|
||||
if (window) {
|
||||
console.log('使用 getFocusedWindow 关闭窗口...')
|
||||
window.close()
|
||||
} else {
|
||||
console.log('没有找到可用的窗口')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Mini 模式 IPC 处理 - 最小化到系统托盘
|
||||
ipcMain.on('window-mini-mode', (_, isMini) => {
|
||||
console.log('收到 window-mini-mode 事件,isMini:', isMini)
|
||||
if (mainWindow) {
|
||||
if (isMini) {
|
||||
// 进入 Mini 模式:隐藏窗口到系统托盘
|
||||
console.log('正在隐藏窗口...')
|
||||
mainWindow.hide()
|
||||
// 显示托盘通知(可选)
|
||||
if (trayObj.value) {
|
||||
console.log('显示托盘通知...')
|
||||
trayObj.value.displayBalloon({
|
||||
title: '澜音 Music',
|
||||
content: '已最小化到系统托盘啦,点击托盘图标可重新打开~'
|
||||
})
|
||||
} else {
|
||||
console.log('托盘对象不存在!trayObj.value:', trayObj.value)
|
||||
}
|
||||
} else {
|
||||
// 退出 Mini 模式:显示窗口
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 全屏模式 IPC 处理
|
||||
ipcMain.on('window-toggle-fullscreen', () => {
|
||||
if (mainWindow) {
|
||||
const isFullScreen = mainWindow.isFullScreen()
|
||||
mainWindow.setFullScreen(!isFullScreen)
|
||||
}
|
||||
})
|
||||
|
||||
createWindow()
|
||||
createTray()
|
||||
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
}
|
||||
47
src/preload/index.d.ts
vendored
@@ -79,8 +79,55 @@ interface CustomAPI {
|
||||
start: () => undefined
|
||||
stop: () => undefined
|
||||
}
|
||||
|
||||
// 目录设置API
|
||||
directorySettings: {
|
||||
getDirectories: () => Promise<{
|
||||
cacheDir: string
|
||||
downloadDir: string
|
||||
}>
|
||||
selectCacheDir: () => Promise<{
|
||||
success: boolean
|
||||
path?: string
|
||||
message?: string
|
||||
}>
|
||||
selectDownloadDir: () => Promise<{
|
||||
success: boolean
|
||||
path?: string
|
||||
message?: string
|
||||
}>
|
||||
saveDirectories: (directories: {
|
||||
cacheDir: string
|
||||
downloadDir: string
|
||||
}) => Promise<{
|
||||
success: boolean
|
||||
message: string
|
||||
}>
|
||||
resetDirectories: () => Promise<{
|
||||
success: boolean
|
||||
directories?: {
|
||||
cacheDir: string
|
||||
downloadDir: string
|
||||
}
|
||||
message?: string
|
||||
}>
|
||||
openDirectory: (dirPath: string) => Promise<{
|
||||
success: boolean
|
||||
message?: string
|
||||
}>
|
||||
getDirectorySize: (dirPath: string) => Promise<{
|
||||
size: number
|
||||
formatted: string
|
||||
}>
|
||||
|
||||
}
|
||||
|
||||
// 用户配置API
|
||||
getUserConfig: () => Promise<any>
|
||||
|
||||
pluginNotice: {
|
||||
onPluginNotice: (listener: (...args: any[]) => void) => ()=>void
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -22,16 +22,18 @@ const api = {
|
||||
},
|
||||
toggleFullscreen: () => ipcRenderer.send('window-toggle-fullscreen'),
|
||||
onMusicCtrl: (callback: (event: Electron.IpcRendererEvent, ...args: any[]) => void) => {
|
||||
// 音乐控制
|
||||
const handler = (event: Electron.IpcRendererEvent) => callback(event)
|
||||
ipcRenderer.on('music-control', handler)
|
||||
return () => ipcRenderer.removeListener('music-control', handler)
|
||||
},
|
||||
|
||||
// 音乐相关方法
|
||||
music: {
|
||||
request: (api: string, args: any) => ipcRenderer.invoke('service-music-request', api, args),
|
||||
requestSdk: (api: string, args: any) =>
|
||||
ipcRenderer.invoke('service-music-sdk-request', api, args)
|
||||
},
|
||||
//音源插件
|
||||
plugins: {
|
||||
selectAndAddPlugin: (type: 'lx' | 'cr') =>
|
||||
ipcRenderer.invoke('service-plugin-selectAndAddPlugin', type),
|
||||
@@ -43,7 +45,7 @@ const api = {
|
||||
ipcRenderer.invoke('service-plugin-uninstallPlugin', pluginId),
|
||||
getPluginLog: (pluginId: string) => ipcRenderer.invoke('service-plugin-getPluginLog', pluginId)
|
||||
},
|
||||
|
||||
// ai助手
|
||||
ai: {
|
||||
ask: (prompt: string) => ipcRenderer.invoke('ai-ask', prompt),
|
||||
askStream: (prompt: string, streamId: string) =>
|
||||
@@ -63,7 +65,7 @@ const api = {
|
||||
ipcRenderer.removeAllListeners('ai-stream-error')
|
||||
}
|
||||
},
|
||||
|
||||
// 音频缓存管理
|
||||
musicCache: {
|
||||
getInfo: () => ipcRenderer.invoke('music-cache:get-info'),
|
||||
clear: () => ipcRenderer.invoke('music-cache:clear'),
|
||||
@@ -162,6 +164,31 @@ const api = {
|
||||
stop: () => {
|
||||
ipcRenderer.send('stopPing')
|
||||
}
|
||||
},
|
||||
|
||||
// 目录设置相关
|
||||
directorySettings: {
|
||||
getDirectories: () => ipcRenderer.invoke('directory-settings:get-directories'),
|
||||
selectCacheDir: () => ipcRenderer.invoke('directory-settings:select-cache-dir'),
|
||||
selectDownloadDir: () => ipcRenderer.invoke('directory-settings:select-download-dir'),
|
||||
saveDirectories: (directories: any) =>
|
||||
ipcRenderer.invoke('directory-settings:save-directories', directories),
|
||||
resetDirectories: () => ipcRenderer.invoke('directory-settings:reset-directories'),
|
||||
openDirectory: (dirPath: string) =>
|
||||
ipcRenderer.invoke('directory-settings:open-directory', dirPath),
|
||||
getDirectorySize: (dirPath: string) =>
|
||||
ipcRenderer.invoke('directory-settings:get-directory-size', dirPath)
|
||||
},
|
||||
|
||||
// 插件通知相关
|
||||
pluginNotice: {
|
||||
onPluginNotice(callback: (data: string) => any) {
|
||||
function listener(_: any, data: any) {
|
||||
callback(data)
|
||||
}
|
||||
ipcRenderer.on('plugin-notice', listener)
|
||||
return () => ipcRenderer.removeListener('plugin-notice', listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
58
src/renderer/components.d.ts
vendored
@@ -0,0 +1,58 @@
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
// Generated by unplugin-vue-components
|
||||
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
// biome-ignore lint: disable
|
||||
export {}
|
||||
|
||||
/* prettier-ignore */
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AIFloatBallSettings: typeof import('./src/components/Settings/AIFloatBallSettings.vue')['default']
|
||||
AudioVisualizer: typeof import('./src/components/Play/AudioVisualizer.vue')['default']
|
||||
DirectorySettings: typeof import('./src/components/Settings/DirectorySettings.vue')['default']
|
||||
FloatBall: typeof import('./src/components/AI/FloatBall.vue')['default']
|
||||
FullPlay: typeof import('./src/components/Play/FullPlay.vue')['default']
|
||||
GlobalAudio: typeof import('./src/components/Play/GlobalAudio.vue')['default']
|
||||
HomeLayout: typeof import('./src/components/layout/HomeLayout.vue')['default']
|
||||
MusicCache: typeof import('./src/components/Settings/MusicCache.vue')['default']
|
||||
PlaylistActions: typeof import('./src/components/Play/PlaylistActions.vue')['default']
|
||||
PlaylistDrawer: typeof import('./src/components/Play/PlaylistDrawer.vue')['default']
|
||||
PlaylistSettings: typeof import('./src/components/Settings/PlaylistSettings.vue')['default']
|
||||
PlayMusic: typeof import('./src/components/Play/PlayMusic.vue')['default']
|
||||
PluginNoticeDialog: typeof import('./src/components/PluginNoticeDialog.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
ShaderBackground: typeof import('./src/components/Play/ShaderBackground.vue')['default']
|
||||
SongVirtualList: typeof import('./src/components/Music/SongVirtualList.vue')['default']
|
||||
TAlert: typeof import('tdesign-vue-next')['Alert']
|
||||
TAside: typeof import('tdesign-vue-next')['Aside']
|
||||
TBadge: typeof import('tdesign-vue-next')['Badge']
|
||||
TButton: typeof import('tdesign-vue-next')['Button']
|
||||
TCard: typeof import('tdesign-vue-next')['Card']
|
||||
TContent: typeof import('tdesign-vue-next')['Content']
|
||||
TDialog: typeof import('tdesign-vue-next')['Dialog']
|
||||
TDivider: typeof import('tdesign-vue-next')['Divider']
|
||||
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
|
||||
TForm: typeof import('tdesign-vue-next')['Form']
|
||||
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
||||
ThemeSelector: typeof import('./src/components/ThemeSelector.vue')['default']
|
||||
TIcon: typeof import('tdesign-vue-next')['Icon']
|
||||
TImage: typeof import('tdesign-vue-next')['Image']
|
||||
TInput: typeof import('tdesign-vue-next')['Input']
|
||||
TitleBarControls: typeof import('./src/components/TitleBarControls.vue')['default']
|
||||
TLayout: typeof import('tdesign-vue-next')['Layout']
|
||||
TLoading: typeof import('tdesign-vue-next')['Loading']
|
||||
TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
|
||||
TRadioGroup: typeof import('tdesign-vue-next')['RadioGroup']
|
||||
TSlider: typeof import('tdesign-vue-next')['Slider']
|
||||
TSwitch: typeof import('tdesign-vue-next')['Switch']
|
||||
TTag: typeof import('tdesign-vue-next')['Tag']
|
||||
TTextarea: typeof import('tdesign-vue-next')['Textarea']
|
||||
TTooltip: typeof import('tdesign-vue-next')['Tooltip']
|
||||
UpdateExample: typeof import('./src/components/UpdateExample.vue')['default']
|
||||
UpdateProgress: typeof import('./src/components/UpdateProgress.vue')['default']
|
||||
UpdateSettings: typeof import('./src/components/Settings/UpdateSettings.vue')['default']
|
||||
Versions: typeof import('./src/components/Versions.vue')['default']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
<head lang="zh-CN">
|
||||
<meta charset="UTF-8" />
|
||||
<title>澜音 Music</title>
|
||||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||
<!-- <meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self' *.gtimg.com; style-src 'self' 'unsafe-inline'; img-src *; connect-src 'self' https://music.163.com https://*.music.163.com *.bikonoo.com/ ; media-src 'self' data: https://* http://*;"
|
||||
/> -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
<!--
|
||||
- Copyright (c) 2025. 时迁酱 Inc. All rights reserved.
|
||||
-
|
||||
- This software is the confidential and proprietary information of 时迁酱.
|
||||
- Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
-
|
||||
- @author 时迁酱,无聊的霜霜,Star
|
||||
- @since 2025-9-19
|
||||
- @version 1.0
|
||||
-->
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import GlobalAudio from './components/Play/GlobalAudio.vue'
|
||||
import FloatBall from './components/AI/FloatBall.vue'
|
||||
import { LocalUserDetailStore } from '@renderer/store/LocalUserDetail'
|
||||
import { useAutoUpdate } from './composables/useAutoUpdate'
|
||||
|
||||
@@ -68,6 +77,7 @@ const applyTheme = (themeName) => {
|
||||
</router-view>
|
||||
<GlobalAudio />
|
||||
<FloatBall />
|
||||
<PluginNoticeDialog />
|
||||
<UpdateProgress />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
@font-face {
|
||||
font-family: 'lyricfont';
|
||||
src: url('./lyricfont.ttf');
|
||||
font-weight: 500;
|
||||
}
|
||||
*,
|
||||
*::before,
|
||||
@@ -78,3 +77,6 @@ body {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #cbd5e1 #f1f5f9;
|
||||
}
|
||||
.t-dialog__mask{
|
||||
backdrop-filter: blur(5px);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
||||
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
||||
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
||||
--td-mask-active: rgba(0, 0, 0, 0.6);
|
||||
--td-mask-active: rgba(255, 255, 255, 0.6);
|
||||
--td-mask-disabled: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
--td-bg-color-specialcomponent: transparent;
|
||||
--td-border-level-1-color: var(--td-gray-color-11);
|
||||
--td-border-level-2-color: var(--td-gray-color-9);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.4);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
||||
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
||||
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
||||
--td-mask-active: rgba(0, 0, 0, 0.6);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@
|
||||
--td-bg-color-specialcomponent: transparent;
|
||||
--td-border-level-1-color: var(--td-gray-color-11);
|
||||
--td-border-level-2-color: var(--td-gray-color-9);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.4);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
||||
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
||||
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
||||
--td-mask-active: rgba(0, 0, 0, 0.6);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
||||
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
||||
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
||||
--td-mask-active: rgba(0, 0, 0, 0.6);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
||||
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
||||
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
||||
--td-mask-active: rgba(0, 0, 0, 0.6);
|
||||
--td-mask-active: rgba(0, 0, 0, 0.1);
|
||||
--td-mask-disabled: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { ref, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
|
||||
import { ControlAudioStore } from '@renderer/store/ControlAudio'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import audioManager from '@renderer/utils/audioManager'
|
||||
import audioManager from '@renderer/utils/audio/audioManager'
|
||||
|
||||
interface Props {
|
||||
show?: boolean
|
||||
|
||||
@@ -12,11 +12,16 @@ import {
|
||||
import type { SongList } from '@renderer/types/audio'
|
||||
import type { LyricLine } from '@applemusic-like-lyrics/core'
|
||||
import { ref, computed, onMounted, watch, reactive, onBeforeUnmount, toRaw } from 'vue'
|
||||
import { shouldUseBlackText } from '@renderer/utils/contrastColor'
|
||||
import { shouldUseBlackText } from '@renderer/utils/color/contrastColor'
|
||||
import { ControlAudioStore } from '@renderer/store/ControlAudio'
|
||||
import { Fullscreen1Icon, FullscreenExit1Icon, ChevronDownIcon } from 'tdesign-icons-vue-next'
|
||||
// 直接从包路径导入,避免 WebAssembly 导入问题
|
||||
import { parseYrc, parseLrc, parseTTML } from '@applemusic-like-lyrics/lyric/pkg/amll_lyric.js'
|
||||
import {
|
||||
parseYrc,
|
||||
parseLrc,
|
||||
parseTTML,
|
||||
parseQrc
|
||||
} from '@applemusic-like-lyrics/lyric/pkg/amll_lyric.js'
|
||||
import _ from 'lodash'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
@@ -151,7 +156,11 @@ watch(
|
||||
if (lyricData.crlyric) {
|
||||
// 使用逐字歌词
|
||||
lyricText = lyricData.crlyric
|
||||
parsedLyrics = parseYrc(lyricText)
|
||||
if (source === 'tx') {
|
||||
parsedLyrics = parseQrc(lyricText)
|
||||
} else {
|
||||
parsedLyrics = parseYrc(lyricText)
|
||||
}
|
||||
console.log(`使用${source}逐字歌词`, parsedLyrics)
|
||||
} else if (lyricData.lyric) {
|
||||
lyricText = lyricData.lyric
|
||||
@@ -347,13 +356,14 @@ const lightMainColor = computed(() => {
|
||||
:lyric-lines="props.show ? state.lyricLines : []"
|
||||
:current-time="state.currentTime"
|
||||
class="lyric-player"
|
||||
:enable-spring="true"
|
||||
:enable-scale="true"
|
||||
@line-click="
|
||||
(e) => {
|
||||
if (Audio.audio) Audio.audio.currentTime = e.line.getLine().startTime / 1000
|
||||
}
|
||||
"
|
||||
>
|
||||
<template #bottom-line> Test Bottom Line </template>
|
||||
</LyricPlayer>
|
||||
</div>
|
||||
</div>
|
||||
@@ -493,6 +503,8 @@ const lightMainColor = computed(() => {
|
||||
perspective: 1000px;
|
||||
|
||||
.pointer {
|
||||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
position: absolute;
|
||||
width: calc(var(--cd-width-auto) / 3.5);
|
||||
left: calc(50% - 1.8vh);
|
||||
|
||||
@@ -18,16 +18,16 @@ const { liebiao, shengyin } = icons
|
||||
import { storeToRefs } from 'pinia'
|
||||
import FullPlay from './FullPlay.vue'
|
||||
import PlaylistDrawer from './PlaylistDrawer.vue'
|
||||
import { extractDominantColor } from '@renderer/utils/colorExtractor'
|
||||
import { getBestContrastTextColorWithOpacity } from '@renderer/utils/contrastColor'
|
||||
import { extractDominantColor } from '@renderer/utils/color/colorExtractor'
|
||||
import { getBestContrastTextColorWithOpacity } from '@renderer/utils/color/contrastColor'
|
||||
import { PlayMode, type SongList } from '@renderer/types/audio'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
initPlaylistEventListeners,
|
||||
destroyPlaylistEventListeners,
|
||||
getSongRealUrl
|
||||
} from '@renderer/utils/playlistManager'
|
||||
import mediaSessionController from '@renderer/utils/useAmtc'
|
||||
} from '@renderer/utils/playlist/playlistManager'
|
||||
import mediaSessionController from '@renderer/utils/audio/useSmtc'
|
||||
import defaultCoverImg from '/default-cover.png'
|
||||
|
||||
const controlAudio = ControlAudioStore()
|
||||
@@ -163,9 +163,10 @@ const playSong = async (song: SongList) => {
|
||||
}
|
||||
|
||||
// 更新歌曲信息并触发主题色更新
|
||||
songInfo.value = {
|
||||
...song
|
||||
}
|
||||
songInfo.value.name = song.name
|
||||
songInfo.value.singer = song.singer
|
||||
songInfo.value.albumName = song.albumName
|
||||
songInfo.value.img = song.img
|
||||
|
||||
// 更新媒体会话元数据
|
||||
mediaSessionController.updateMetadata({
|
||||
@@ -176,24 +177,15 @@ const playSong = async (song: SongList) => {
|
||||
})
|
||||
|
||||
// 确保主题色更新
|
||||
await setColor()
|
||||
|
||||
let urlToPlay = ''
|
||||
|
||||
// 如果没有URL,需要获取URL
|
||||
if (!urlToPlay) {
|
||||
// eslint-disable-next-line no-useless-catch
|
||||
try {
|
||||
urlToPlay = await getSongRealUrl(toRaw(song))
|
||||
|
||||
// 同时更新播放列表中对应歌曲的URL
|
||||
const playlistIndex = list.value.findIndex((item) => item.songmid === song.songmid)
|
||||
if (playlistIndex !== -1) {
|
||||
;(list.value[playlistIndex] as any).url = urlToPlay
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
// 获取URL
|
||||
// eslint-disable-next-line no-useless-catch
|
||||
try {
|
||||
urlToPlay = await getSongRealUrl(toRaw(song))
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
// 先停止当前播放
|
||||
@@ -209,16 +201,16 @@ const playSong = async (song: SongList) => {
|
||||
|
||||
// 等待音频准备就绪
|
||||
await waitForAudioReady()
|
||||
|
||||
await setColor()
|
||||
songInfo.value = {
|
||||
...song
|
||||
}
|
||||
// // 短暂延迟确保音频状态稳定
|
||||
// await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
|
||||
// 开始播放
|
||||
try {
|
||||
const startResult = start()
|
||||
if (startResult && typeof startResult.then === 'function') {
|
||||
await startResult
|
||||
}
|
||||
start()
|
||||
} catch (error) {
|
||||
console.error('启动播放失败:', error)
|
||||
// 如果是 AbortError,尝试重新播放
|
||||
@@ -835,13 +827,11 @@ watch(showFullPlay, (val) => {
|
||||
:disabled="isLoadingSong"
|
||||
@click.stop="() => !isLoadingSong && togglePlayPause()"
|
||||
>
|
||||
<Transition name="loadSong" mode="out-in">
|
||||
<transition name="fade" mode="out-in">
|
||||
<div v-if="isLoadingSong" key="loading" class="loading-spinner play-loading"></div>
|
||||
<transition v-else name="fade" mode="out-in">
|
||||
<span v-if="Audio.isPlay" key="play" class="iconfont icon-zanting"></span>
|
||||
<span v-else key="pause" class="iconfont icon-bofang"></span>
|
||||
</transition>
|
||||
</Transition>
|
||||
<span v-else-if="Audio.isPlay" key="play" class="iconfont icon-zanting"></span>
|
||||
<span v-else key="pause" class="iconfont icon-bofang"></span>
|
||||
</transition>
|
||||
</button>
|
||||
<t-button class="control-btn" shape="circle" variant="text" @click.stop="playNext">
|
||||
<span class="iconfont icon-xiayishou"></span>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
importPlaylistFromFile,
|
||||
importPlaylistFromClipboard,
|
||||
validateImportedPlaylist
|
||||
} from '@renderer/utils/playlistExportImport'
|
||||
} from '@renderer/utils/playlist/playlistExportImport'
|
||||
import { CloudDownloadIcon } from 'tdesign-icons-vue-next'
|
||||
import type { SongList } from '@renderer/types/audio'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
@@ -124,10 +124,20 @@ const currentOperatingSong = ref<any>(null)
|
||||
|
||||
// 统一的鼠标/触摸事件处理
|
||||
const handleMouseDown = (event: MouseEvent, index: number, song: any) => {
|
||||
// 检查是否点击了删除按钮或其子元素
|
||||
const target = event.target as HTMLElement
|
||||
if (target.closest('.song-remove')) {
|
||||
return // 如果点击的是删除按钮,直接返回,不处理拖拽逻辑
|
||||
}
|
||||
handlePointerStart(event, index, song, false)
|
||||
}
|
||||
|
||||
const handleTouchStart = (event: TouchEvent, index: number, song: any) => {
|
||||
// 检查是否点击了删除按钮或其子元素
|
||||
const target = event.target as HTMLElement
|
||||
if (target.closest('.song-remove')) {
|
||||
return // 如果点击的是删除按钮,直接返回,不处理拖拽逻辑
|
||||
}
|
||||
handlePointerStart(event, index, song, true)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, onMounted, onBeforeUnmount, watch, computed } from 'vue'
|
||||
import { extractColors, Color } from '@renderer/utils/colorExtractor'
|
||||
import { extractColors, Color } from '@renderer/utils/color/colorExtractor'
|
||||
import DefaultCover from '@renderer/assets/images/Default.jpg'
|
||||
import CoverImage from '@renderer/assets/images/cover.png'
|
||||
|
||||
@@ -40,7 +40,7 @@ const actualCoverImage = computed(() => {
|
||||
const vertexShaderSource = `
|
||||
attribute vec2 a_position;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0.0, 1.0);
|
||||
v_texCoord = a_position * 0.5 + 0.5;
|
||||
@@ -53,81 +53,81 @@ const fragmentShaderSource = `
|
||||
varying vec2 v_texCoord;
|
||||
uniform float u_time;
|
||||
uniform vec3 u_color;
|
||||
|
||||
|
||||
// 改进的随机函数 - 更平滑
|
||||
float random(vec2 st) {
|
||||
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
|
||||
}
|
||||
|
||||
|
||||
// 改进的噪声函数 - 使用三次Hermite插值,更平滑
|
||||
float noise(vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
|
||||
// 四个角的随机值
|
||||
float a = random(i);
|
||||
float b = random(i + vec2(1.0, 0.0));
|
||||
float c = random(i + vec2(0.0, 1.0));
|
||||
float d = random(i + vec2(1.0, 1.0));
|
||||
|
||||
|
||||
// 使用三次Hermite插值,更加平滑
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
|
||||
return mix(a, b, u.x) +
|
||||
(c - a) * u.y * (1.0 - u.x) +
|
||||
(d - b) * u.x * u.y;
|
||||
}
|
||||
|
||||
|
||||
// 改进的分数布朗运动 - 降低频率,减少网格感
|
||||
float fbm(vec2 st) {
|
||||
float value = 0.0;
|
||||
float amplitude = 0.5;
|
||||
float frequency = 0.6; // 降低初始频率
|
||||
|
||||
|
||||
// 减少迭代次数,使用更平滑的混合
|
||||
for (int i = 0; i < 4; i++) { // 减少迭代次数
|
||||
value += amplitude * noise(st * frequency);
|
||||
frequency *= 1.8; // 降低频率增长率
|
||||
amplitude *= 0.6; // 提高振幅衰减率
|
||||
}
|
||||
|
||||
|
||||
// 额外的平滑处理
|
||||
return smoothstep(0.2, 0.8, value);
|
||||
}
|
||||
|
||||
|
||||
// HSV转RGB颜色
|
||||
vec3 hsv2rgb(vec3 c) {
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
// 使用时间和位置创建动态效果
|
||||
vec2 st = v_texCoord;
|
||||
float time = u_time * 0.20; // 降低时间速率,使动画更平滑
|
||||
|
||||
|
||||
// 创建更平滑的移动噪声场
|
||||
vec2 q = vec2(
|
||||
fbm(st + vec2(0.0, time * 0.3)),
|
||||
fbm(st + vec2(time * 0.2, 0.0))
|
||||
);
|
||||
|
||||
|
||||
// 使用q创建第二层噪声,降低强度
|
||||
vec2 r = vec2(
|
||||
fbm(st + 2.0 * q + vec2(1.7, 9.2) + time * 0.1),
|
||||
fbm(st + 2.0 * q + vec2(8.3, 2.8) + time * 0.08)
|
||||
);
|
||||
|
||||
|
||||
// 最终的噪声值 - 额外平滑处理
|
||||
float f = fbm(st + r * 0.7);
|
||||
|
||||
|
||||
// 从主色调提取HSV
|
||||
vec3 baseColor = u_color;
|
||||
float maxComp = max(max(baseColor.r, baseColor.g), baseColor.b);
|
||||
float minComp = min(min(baseColor.r, baseColor.g), baseColor.b);
|
||||
float delta = maxComp - minComp;
|
||||
|
||||
|
||||
// 估算色相
|
||||
float hue = 0.0;
|
||||
if (delta > 0.0) {
|
||||
@@ -140,78 +140,78 @@ const fragmentShaderSource = `
|
||||
}
|
||||
hue /= 6.0;
|
||||
}
|
||||
|
||||
|
||||
// 估算饱和度和明度
|
||||
float saturation = maxComp == 0.0 ? 0.0 : delta / maxComp;
|
||||
float value = maxComp;
|
||||
|
||||
|
||||
// 提高基础亮度和饱和度,使颜色更加明亮清新
|
||||
saturation = min(saturation * 1.0, 1.0); // 增加饱和度
|
||||
value = min(value * 1.3, 1.0); // 增加亮度
|
||||
|
||||
|
||||
// 创建多个颜色变体 - 更明亮的变体
|
||||
vec3 color1 = hsv2rgb(vec3(hue, saturation * 0.9, min(value * 1.1, 1.0)));
|
||||
vec3 color2 = hsv2rgb(vec3(mod(hue + 0.05, 1.0), min(saturation * 1.3, 1.0), min(value * 1.2, 1.0)));
|
||||
vec3 color3 = hsv2rgb(vec3(mod(hue + 0.1, 1.0), min(saturation * 1.1, 1.0), min(value * 1.15, 1.0)));
|
||||
vec3 color4 = hsv2rgb(vec3(mod(hue - 0.05, 1.0), min(saturation * 1.2, 1.0), min(value * 1.25, 1.0)));
|
||||
|
||||
|
||||
// 使用噪声值混合多个颜色 - 更平滑的混合,使用更多主色调
|
||||
float t1 = smoothstep(0.0, 1.0, f);
|
||||
float t2 = sin(f * 3.14) * 0.5 + 0.5;
|
||||
float t3 = cos(f * 2.0 + time * 0.5) * 0.5 + 0.5;
|
||||
float t4 = sin(f * 4.0 + time * 0.3) * 0.5 + 0.5; // 额外的混合因子
|
||||
|
||||
|
||||
// 创建两个额外的颜色变体,增加色彩丰富度
|
||||
vec3 color5 = hsv2rgb(vec3(mod(hue + 0.15, 1.0), min(saturation * 1.4, 1.0), min(value * 1.3, 1.0)));
|
||||
vec3 color6 = hsv2rgb(vec3(mod(hue - 0.15, 1.0), min(saturation * 1.3, 1.0), min(value * 1.2, 1.0)));
|
||||
|
||||
|
||||
// 混合所有颜色
|
||||
vec3 colorMix1 = mix(color1, color2, t1);
|
||||
vec3 colorMix2 = mix(color3, color4, t2);
|
||||
vec3 colorMix3 = mix(color5, color6, t4);
|
||||
|
||||
|
||||
vec3 color = mix(
|
||||
mix(colorMix1, colorMix2, t3),
|
||||
colorMix3,
|
||||
sin(f * 2.5 + time * 0.4) * 0.5 + 0.5
|
||||
);
|
||||
|
||||
|
||||
// 添加更多的动态亮点和波纹
|
||||
color += 0.15 * sin(f * 8.0 + time) * vec3(1.0);
|
||||
|
||||
|
||||
// 增加波纹效果
|
||||
float ripple1 = sin(st.x * 12.0 + time * 0.8) * sin(st.y * 12.0 + time * 0.7) * 0.06;
|
||||
float ripple2 = sin(st.x * 8.0 - time * 0.6) * sin(st.y * 8.0 - time * 0.5) * 0.05;
|
||||
float ripple3 = sin(st.x * 15.0 + time * 0.4) * sin(st.y * 15.0 + time * 0.3) * 0.04;
|
||||
|
||||
|
||||
// 混合多层波纹
|
||||
color += vec3(ripple1 + ripple2 + ripple3);
|
||||
|
||||
|
||||
// 添加更大范围、更柔和的光晕效果
|
||||
float glow = smoothstep(0.3, 0.7, f);
|
||||
color = mix(color, vec3(1.0), glow * 0.12);
|
||||
|
||||
|
||||
// 添加柔和的渐变效果,进一步减少网格感
|
||||
float vignette = smoothstep(0.0, 0.7, 0.5 - length(st - 0.5));
|
||||
color = mix(color, color * 1.2, vignette * 0.3);
|
||||
|
||||
|
||||
// 应用高斯模糊效果,减少锐利的网格边缘
|
||||
vec2 pixel = vec2(1.0) / vec2(800.0, 600.0); // 假设的分辨率
|
||||
float blur = 0.0;
|
||||
|
||||
|
||||
// 简化的高斯模糊 - 只采样几个点以保持性能
|
||||
blur += f * 0.5;
|
||||
blur += fbm(st + pixel * vec2(1.0, 0.0)) * 0.125;
|
||||
blur += fbm(st + pixel * vec2(-1.0, 0.0)) * 0.125;
|
||||
blur += fbm(st + pixel * vec2(0.0, 1.0)) * 0.125;
|
||||
blur += fbm(st + pixel * vec2(0.0, -1.0)) * 0.125;
|
||||
|
||||
|
||||
// 使用模糊值平滑颜色过渡
|
||||
color = mix(color, mix(color1, color4, 0.5), (blur - f) * 0.2);
|
||||
|
||||
|
||||
// 确保颜色在有效范围内
|
||||
color = clamp(color, 0.0, 1.0);
|
||||
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
||||
`
|
||||
|
||||
324
src/renderer/src/components/PluginNoticeDialog.vue
Normal file
@@ -0,0 +1,324 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
v-model:visible="visible"
|
||||
:header="dialogTitle"
|
||||
:width="dialogWidth"
|
||||
:close-btn="true"
|
||||
:close-on-overlay-click="false"
|
||||
:destroy-on-close="true"
|
||||
placement="center"
|
||||
@close="handleClose"
|
||||
>
|
||||
<template #body>
|
||||
<div class="plugin-notice-content">
|
||||
<!-- 通知消息 -->
|
||||
<div class="notice-message">
|
||||
<p class="message-text">{{ notice?.message }}</p>
|
||||
|
||||
<!-- 更新通知的额外信息 -->
|
||||
<div v-if="notice?.dialogType === 'update'" class="update-info">
|
||||
<div class="version-info">
|
||||
<span class="version-label">当前版本:</span>
|
||||
<span class="version-value">{{ notice?.currentVersion || 'Unknown' }}</span>
|
||||
</div>
|
||||
<div class="version-info">
|
||||
<span class="version-label">新版本:</span>
|
||||
<span class="version-value new-version">{{ notice?.newVersion || 'Unknown' }}</span>
|
||||
</div>
|
||||
<div v-if="notice?.pluginType" class="plugin-type">
|
||||
<span class="type-label">插件类型:</span>
|
||||
<t-tag :theme="notice.pluginType === 'cr' ? 'primary' : 'success'" size="small">
|
||||
{{ notice.pluginType === 'cr' ? 'CeruMusic' : 'LX Music' }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-actions">
|
||||
<t-button
|
||||
v-for="action in notice?.actions || []"
|
||||
:key="action.type"
|
||||
:theme="action.primary ? 'primary' : 'default'"
|
||||
:loading="actionLoading === action.type"
|
||||
@click="handleAction(action.type)"
|
||||
>
|
||||
{{ action.text }}
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
|
||||
interface DialogNotice {
|
||||
type: string
|
||||
data: any
|
||||
timestamp: number
|
||||
pluginName: string
|
||||
dialogType: 'update' | 'info' | 'error' | 'warning' | 'success'
|
||||
title: string
|
||||
message: string
|
||||
updateUrl?: string
|
||||
pluginType?: 'lx' | 'cr'
|
||||
currentVersion?: string
|
||||
newVersion?: string
|
||||
actions: Array<{
|
||||
text: string
|
||||
type: 'cancel' | 'update' | 'confirm'
|
||||
primary?: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false)
|
||||
const notice = ref<DialogNotice | null>(null)
|
||||
const actionLoading = ref<string | null>(null)
|
||||
const noticeQueue = ref<DialogNotice[]>([]) // 通知队列
|
||||
|
||||
// 计算属性
|
||||
const dialogWidth = computed(() => {
|
||||
return notice.value?.dialogType === 'update' ? '500px' : '400px'
|
||||
})
|
||||
|
||||
// 对话框标题(包含队列信息)
|
||||
const dialogTitle = computed(() => {
|
||||
const baseTitle = notice.value?.title || '插件通知'
|
||||
const queueLength = noticeQueue.value.length
|
||||
|
||||
if (queueLength > 0) {
|
||||
return `${baseTitle} (还有 ${queueLength} 个通知)`
|
||||
}
|
||||
|
||||
return baseTitle
|
||||
})
|
||||
|
||||
// 显示通知对话框
|
||||
const showNotice = (noticeData: DialogNotice) => {
|
||||
// 添加到队列
|
||||
noticeQueue.value.push(noticeData)
|
||||
console.log('[PluginNotice] 添加通知到队列:', noticeData, '队列长度:', noticeQueue.value.length)
|
||||
|
||||
// 如果当前没有显示对话框,立即显示
|
||||
if (!visible.value) {
|
||||
showNextNotice()
|
||||
}
|
||||
}
|
||||
|
||||
// 显示队列中的下一个通知
|
||||
const showNextNotice = () => {
|
||||
if (noticeQueue.value.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const nextNotice = noticeQueue.value.shift()
|
||||
if (nextNotice) {
|
||||
notice.value = nextNotice
|
||||
visible.value = true
|
||||
console.log(
|
||||
'[PluginNotice] 显示下一个通知:',
|
||||
nextNotice,
|
||||
'剩余队列长度:',
|
||||
noticeQueue.value.length
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理操作按钮点击
|
||||
const handleAction = async (actionType: string) => {
|
||||
if (!notice.value) return
|
||||
|
||||
actionLoading.value = actionType
|
||||
|
||||
try {
|
||||
console.log('[PluginNotice] 处理操作:', actionType, notice.value)
|
||||
|
||||
if (actionType === 'update' && notice.value.updateUrl) {
|
||||
window.open(notice.value.updateUrl)
|
||||
handleClose()
|
||||
} else if (actionType === 'cancel') {
|
||||
// 取消操作直接关闭
|
||||
handleClose()
|
||||
} else {
|
||||
// 其他操作直接关闭对话框
|
||||
handleClose()
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[PluginNotice] 处理操作失败:', error)
|
||||
MessagePlugin.error(`操作失败: ${error.message}`)
|
||||
} finally {
|
||||
actionLoading.value = null
|
||||
}
|
||||
}
|
||||
|
||||
// 处理对话框关闭
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
notice.value = null
|
||||
actionLoading.value = null
|
||||
|
||||
// 延迟一点时间后显示下一个通知,避免对话框切换过快
|
||||
setTimeout(() => {
|
||||
showNextNotice()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
// 监听插件通知事件
|
||||
const handlePluginNotice = (noticeData: DialogNotice) => {
|
||||
showNotice(noticeData)
|
||||
}
|
||||
let event: () => void
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
// 监听来自主进程的插件通知
|
||||
event = window.api.pluginNotice.onPluginNotice(handlePluginNotice)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
event()
|
||||
// 清空队列
|
||||
noticeQueue.value = []
|
||||
})
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
showNotice,
|
||||
getQueueLength: () => noticeQueue.value.length,
|
||||
clearQueue: () => {
|
||||
noticeQueue.value = []
|
||||
console.log('[PluginNotice] 清空通知队列')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.plugin-notice-content {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
padding: 16px 0;
|
||||
|
||||
.notice-icon {
|
||||
flex-shrink: 0;
|
||||
|
||||
.icon-update {
|
||||
color: #0052d9;
|
||||
}
|
||||
|
||||
.icon-error {
|
||||
color: #e34d59;
|
||||
}
|
||||
|
||||
.icon-warning {
|
||||
color: #ed7b2f;
|
||||
}
|
||||
|
||||
.icon-success {
|
||||
color: #00a870;
|
||||
}
|
||||
|
||||
.icon-info {
|
||||
color: #0052d9;
|
||||
}
|
||||
}
|
||||
|
||||
.notice-message {
|
||||
flex: 1;
|
||||
|
||||
.message-text {
|
||||
margin: 0 0 16px 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.update-info {
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 6px;
|
||||
padding: 20px;
|
||||
margin: 0 10px;
|
||||
border: 1px solid var(--td-border-level-1-color);
|
||||
|
||||
.version-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.version-label {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.version-value {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
&.new-version {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.plugin-type {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--td-border-level-2-color);
|
||||
|
||||
.type-label {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
// 响应式设计
|
||||
@media (max-width: 768px) {
|
||||
.plugin-notice-content {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
|
||||
.notice-icon {
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
flex-direction: column-reverse;
|
||||
|
||||
:deep(.t-button) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 深色主题适配
|
||||
:deep(.t-dialog) {
|
||||
.t-dialog__header {
|
||||
border-bottom: 1px solid var(--td-border-level-1-color);
|
||||
}
|
||||
|
||||
.t-dialog__footer {
|
||||
border-top: 1px solid var(--td-border-level-1-color);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,162 +0,0 @@
|
||||
# 主题切换组件使用说明
|
||||
|
||||
## 概述
|
||||
|
||||
ThemeSelector 是一个现代化的主题切换组件,支持在多个预设主题色之间切换。组件与现有的 TDesign 主题系统完全兼容。
|
||||
|
||||
## 功能特性
|
||||
|
||||
- ✅ 支持多种预设主题色(默认、粉色、蓝色、青色、橙色)
|
||||
- ✅ 使用 `theme-mode` 属性实现主题切换
|
||||
- ✅ 自动保存用户选择到本地存储
|
||||
- ✅ 现代化的下拉选择界面
|
||||
- ✅ 平滑的过渡动画效果
|
||||
- ✅ 响应式设计,支持移动端
|
||||
- ✅ 与 TDesign 主题系统完全兼容
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 基本使用
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<div>
|
||||
<!-- 在任何需要的地方使用主题切换器 -->
|
||||
<ThemeSelector />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import ThemeSelector from '@/components/ThemeSelector.vue'
|
||||
</script>
|
||||
```
|
||||
|
||||
### 2. 在导航栏中使用
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<header class="app-header">
|
||||
<h1>应用标题</h1>
|
||||
<div class="header-actions">
|
||||
<ThemeSelector />
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
```
|
||||
|
||||
### 3. 在设置页面中使用
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<div class="settings-page">
|
||||
<div class="setting-item">
|
||||
<label>主题色</label>
|
||||
<ThemeSelector />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 主题切换原理
|
||||
|
||||
组件通过以下方式实现主题切换:
|
||||
|
||||
1. **默认主题**: 移除 `theme-mode` 属性
|
||||
|
||||
```javascript
|
||||
document.documentElement.removeAttribute('theme-mode')
|
||||
```
|
||||
|
||||
2. **其他主题**: 设置对应的 `theme-mode` 属性
|
||||
```javascript
|
||||
document.documentElement.setAttribute('theme-mode', 'pink')
|
||||
```
|
||||
|
||||
## 支持的主题
|
||||
|
||||
| 主题名称 | 属性值 | 主色调 |
|
||||
| -------- | --------- | ------- |
|
||||
| 默认 | `default` | #57b4ff |
|
||||
| 粉色 | `pink` | #fc5e7e |
|
||||
| 蓝色 | `blue` | #57b4ff |
|
||||
| 青色 | `cyan` | #3ac2b8 |
|
||||
| 橙色 | `orange` | #fb9458 |
|
||||
|
||||
## 自定义配置
|
||||
|
||||
如果需要添加新的主题,请按以下步骤操作:
|
||||
|
||||
### 1. 创建主题CSS文件
|
||||
|
||||
在 `src/renderer/src/assets/theme/` 目录下创建新的主题文件,例如 `green.css`:
|
||||
|
||||
```css
|
||||
:root[theme-mode='green'] {
|
||||
--td-brand-color: #10b981;
|
||||
--td-brand-color-hover: #059669;
|
||||
/* 其他主题变量... */
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 更新组件配置
|
||||
|
||||
在 `ThemeSelector.vue` 中添加新主题:
|
||||
|
||||
```javascript
|
||||
const themes = [
|
||||
// 现有主题...
|
||||
{ name: 'green', label: '绿色', color: '#10b981' }
|
||||
]
|
||||
```
|
||||
|
||||
## 样式自定义
|
||||
|
||||
组件使用 TDesign 的 CSS 变量,可以通过覆盖这些变量来自定义样式:
|
||||
|
||||
```css
|
||||
.theme-selector {
|
||||
/* 自定义触发器样式 */
|
||||
--td-radius-medium: 8px;
|
||||
}
|
||||
|
||||
.theme-dropdown {
|
||||
/* 自定义下拉菜单样式 */
|
||||
--td-shadow-2: 0 8px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
```
|
||||
|
||||
## 事件和回调
|
||||
|
||||
组件会自动处理主题切换和本地存储,无需额外配置。如果需要监听主题变化,可以监听 `localStorage` 的变化:
|
||||
|
||||
```javascript
|
||||
// 监听主题变化
|
||||
window.addEventListener('storage', (e) => {
|
||||
if (e.key === 'selected-theme') {
|
||||
console.log('主题已切换到:', e.newValue)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保项目中已引入对应的主题CSS文件
|
||||
2. 组件会自动加载用户上次选择的主题
|
||||
3. 主题切换是全局的,会影响整个应用
|
||||
4. 建议在应用的主入口处使用,避免重复渲染
|
||||
|
||||
## 演示组件
|
||||
|
||||
项目还包含一个 `ThemeDemo.vue` 组件,展示了主题切换的效果:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<ThemeDemo />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import ThemeDemo from '@/components/ThemeDemo.vue'
|
||||
</script>
|
||||
```
|
||||
|
||||
这个演示组件展示了不同UI元素在各种主题下的表现。
|
||||
@@ -1,86 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
const keyword = ref('')
|
||||
const isSearching = ref(false)
|
||||
|
||||
// 搜索类型:1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单
|
||||
|
||||
// 处理搜索事件
|
||||
const handleSearch = async () => {
|
||||
if (!keyword.value.trim()) return
|
||||
|
||||
isSearching.value = true
|
||||
try {
|
||||
// 调用搜索API
|
||||
|
||||
// 跳转到搜索结果页面,并传递搜索结果和关键词
|
||||
router.push({
|
||||
path: '/home/search',
|
||||
query: { keyword: keyword.value }
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('搜索失败:', error)
|
||||
} finally {
|
||||
isSearching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理按键事件,按下回车键时触发搜索
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Enter') {
|
||||
handleSearch()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="search-component">
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
placeholder="搜索音乐、歌手"
|
||||
:loading="isSearching"
|
||||
@keydown="handleKeyDown"
|
||||
>
|
||||
<template #suffix>
|
||||
<t-button
|
||||
theme="primary"
|
||||
variant="text"
|
||||
shape="square"
|
||||
:disabled="isSearching"
|
||||
@click="handleSearch"
|
||||
>
|
||||
<i class="iconfont icon-sousuo"></i>
|
||||
</t-button>
|
||||
</template>
|
||||
</t-input>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.search-component {
|
||||
width: 100%;
|
||||
|
||||
:deep(.t-input) {
|
||||
border-radius: 0rem !important;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:deep(.t-input__suffix) {
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-size: 1rem;
|
||||
color: #6b7280;
|
||||
transition: color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: #f97316;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -25,7 +25,7 @@ const { settings } = storeToRefs(settingsStore)
|
||||
const showFloatBall = ref(settings.value.showFloatBall !== false)
|
||||
|
||||
// 处理悬浮球开关切换
|
||||
const handleFloatBallToggle = (val: boolean) => {
|
||||
const handleFloatBallToggle = (val: any) => {
|
||||
settingsStore.updateSettings({ showFloatBall: val })
|
||||
}
|
||||
|
||||
|
||||
342
src/renderer/src/components/Settings/DirectorySettings.vue
Normal file
@@ -0,0 +1,342 @@
|
||||
<template>
|
||||
<div class="directory-settings">
|
||||
<t-card title="存储目录配置" hover-shadow>
|
||||
<template #actions>
|
||||
<t-button theme="default" size="small" @click="resetDirectories"> 重置为默认 </t-button>
|
||||
</template>
|
||||
|
||||
<div class="directory-section">
|
||||
<h4>缓存目录</h4>
|
||||
<p class="directory-description">用于存储歌曲缓存文件,提高播放速度</p>
|
||||
|
||||
<div class="directory-item">
|
||||
<div class="directory-info">
|
||||
<div class="directory-path">
|
||||
<t-input
|
||||
v-model="directories.cacheDir"
|
||||
readonly
|
||||
placeholder="缓存目录路径"
|
||||
class="path-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="directory-size">
|
||||
<t-tag theme="primary" variant="light">
|
||||
{{ cacheDirSize.formatted }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="directory-actions">
|
||||
<t-button theme="default" @click="selectCacheDir"> 选择目录 </t-button>
|
||||
<t-button theme="default" variant="outline" @click="openCacheDir"> 打开目录 </t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<t-divider />
|
||||
|
||||
<div class="directory-section">
|
||||
<h4>下载目录</h4>
|
||||
<p class="directory-description">用于存储下载的音乐文件</p>
|
||||
|
||||
<div class="directory-item">
|
||||
<div class="directory-info">
|
||||
<div class="directory-path">
|
||||
<t-input
|
||||
v-model="directories.downloadDir"
|
||||
readonly
|
||||
placeholder="下载目录路径"
|
||||
class="path-input"
|
||||
/>
|
||||
</div>
|
||||
<div class="directory-size">
|
||||
<t-tag theme="success" variant="light">
|
||||
{{ downloadDirSize.formatted }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="directory-actions">
|
||||
<t-button theme="default" @click="selectDownloadDir"> 选择目录 </t-button>
|
||||
<t-button theme="default" variant="outline" @click="openDownloadDir">
|
||||
打开目录
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="save-section">
|
||||
<t-button theme="primary" size="large" :loading="isSaving" @click="saveDirectories">
|
||||
保存设置
|
||||
</t-button>
|
||||
</div>
|
||||
</t-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, toRaw } from 'vue'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
|
||||
// 定义事件
|
||||
const emit = defineEmits<{
|
||||
'directory-changed': []
|
||||
'cache-cleared': []
|
||||
}>()
|
||||
|
||||
// 响应式数据
|
||||
const directories = ref({
|
||||
cacheDir: '',
|
||||
downloadDir: ''
|
||||
})
|
||||
|
||||
const cacheDirSize = ref({ size: 0, formatted: '0 B' })
|
||||
const downloadDirSize = ref({ size: 0, formatted: '0 B' })
|
||||
const isSaving = ref(false)
|
||||
|
||||
// 加载目录配置
|
||||
const loadDirectories = async () => {
|
||||
try {
|
||||
const dirs = await window.api.directorySettings.getDirectories()
|
||||
directories.value = dirs
|
||||
|
||||
// 获取目录大小
|
||||
await Promise.all([updateCacheDirSize(), updateDownloadDirSize()])
|
||||
} catch (error) {
|
||||
console.error('加载目录配置失败:', error)
|
||||
MessagePlugin.error('加载目录配置失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 更新缓存目录大小
|
||||
const updateCacheDirSize = async () => {
|
||||
try {
|
||||
const sizeInfo = await window.api.directorySettings.getDirectorySize(directories.value.cacheDir)
|
||||
cacheDirSize.value = sizeInfo
|
||||
} catch (error) {
|
||||
console.error('获取缓存目录大小失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 更新下载目录大小
|
||||
const updateDownloadDirSize = async () => {
|
||||
try {
|
||||
const sizeInfo = await window.api.directorySettings.getDirectorySize(
|
||||
directories.value.downloadDir
|
||||
)
|
||||
downloadDirSize.value = sizeInfo
|
||||
} catch (error) {
|
||||
console.error('获取下载目录大小失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 选择缓存目录
|
||||
const selectCacheDir = async () => {
|
||||
try {
|
||||
const result = await window.api.directorySettings.selectCacheDir()
|
||||
|
||||
if (result.success && result.path) {
|
||||
directories.value.cacheDir = result.path
|
||||
await updateCacheDirSize()
|
||||
MessagePlugin.success('缓存目录已选择,记得保存奥')
|
||||
} else if (result.message !== '用户取消选择') {
|
||||
MessagePlugin.error(result.message || '选择目录失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('选择缓存目录失败:', error)
|
||||
MessagePlugin.error('选择目录失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 选择下载目录
|
||||
const selectDownloadDir = async () => {
|
||||
try {
|
||||
const result = await window.api.directorySettings.selectDownloadDir()
|
||||
|
||||
if (result.success && result.path) {
|
||||
directories.value.downloadDir = result.path
|
||||
await updateDownloadDirSize()
|
||||
MessagePlugin.success('下载目录已选择,记得保存奥')
|
||||
} else if (result.message !== '用户取消选择') {
|
||||
MessagePlugin.error(result.message || '选择目录失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('选择下载目录失败:', error)
|
||||
MessagePlugin.error('选择目录失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 打开缓存目录
|
||||
const openCacheDir = async () => {
|
||||
try {
|
||||
const result = await window.api.directorySettings.openDirectory(directories.value.cacheDir)
|
||||
|
||||
if (!result.success) {
|
||||
MessagePlugin.error(result.message || '打开目录失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('打开缓存目录失败:', error)
|
||||
MessagePlugin.error('打开目录失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 打开下载目录
|
||||
const openDownloadDir = async () => {
|
||||
try {
|
||||
const result = await window.api.directorySettings.openDirectory(directories.value.downloadDir)
|
||||
|
||||
if (!result.success) {
|
||||
MessagePlugin.error(result.message || '打开目录失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('打开下载目录失败:', error)
|
||||
MessagePlugin.error('打开目录失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 保存目录设置
|
||||
const saveDirectories = async () => {
|
||||
isSaving.value = true
|
||||
|
||||
try {
|
||||
const result = await window.api.directorySettings.saveDirectories(toRaw(directories.value))
|
||||
|
||||
if (result.success) {
|
||||
MessagePlugin.success('目录设置已保存')
|
||||
emit('directory-changed')
|
||||
} else {
|
||||
MessagePlugin.error(result.message || '保存设置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存目录设置失败:', error)
|
||||
MessagePlugin.error('保存设置失败')
|
||||
} finally {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置为默认目录
|
||||
const resetDirectories = async () => {
|
||||
const confirm = DialogPlugin.confirm({
|
||||
header: '重置目录设置',
|
||||
body: '确定要重置为默认目录吗?这将清除当前的自定义目录设置。',
|
||||
confirmBtn: '确定重置',
|
||||
cancelBtn: '取消',
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
const result = await window.api.directorySettings.resetDirectories()
|
||||
|
||||
if (result.success && result.directories) {
|
||||
directories.value = result.directories
|
||||
await Promise.all([updateCacheDirSize(), updateDownloadDirSize()])
|
||||
MessagePlugin.success('已重置为默认目录')
|
||||
emit('directory-changed')
|
||||
} else {
|
||||
MessagePlugin.error(result.message || '重置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('重置目录设置失败:', error)
|
||||
MessagePlugin.error('重置失败')
|
||||
}
|
||||
confirm.hide()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 刷新目录大小(供父组件调用)
|
||||
const refreshDirectorySizes = async () => {
|
||||
console.log('刷新目录大小')
|
||||
await Promise.all([updateCacheDirSize(), updateDownloadDirSize()])
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
refreshDirectorySizes
|
||||
})
|
||||
|
||||
// 组件挂载时加载配置
|
||||
onMounted(() => {
|
||||
loadDirectories()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.directory-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.directory-section {
|
||||
margin-bottom: 24px;
|
||||
|
||||
h4 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.directory-description {
|
||||
margin: 0 0 16px 0;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.directory-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.directory-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.directory-path {
|
||||
flex: 1;
|
||||
|
||||
.path-input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.directory-size {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.directory-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.save-section {
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid var(--td-border-level-1-color);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cache-management {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.directory-info {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.directory-actions {
|
||||
justify-content: stretch;
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,22 +1,54 @@
|
||||
<template>
|
||||
<div class="music-cache">
|
||||
<t-card hover-shadow :loading="cacheInfo ? false : true" title="本地歌曲缓存配置">
|
||||
<template #actions> 已有歌曲缓存大小:{{ cacheInfo.sizeFormatted }} </template>
|
||||
<t-card hover-shadow :loading="!cacheInfo || cacheInfo.clearing" title="本地歌曲缓存配置">
|
||||
<template #actions>
|
||||
已有歌曲缓存大小:{{ cacheInfo?.sizeFormatted || '0 B' }}
|
||||
<span v-if="cacheInfo?.count > 0">({{ cacheInfo.count }} 个文件)</span>
|
||||
</template>
|
||||
<div class="card-body">
|
||||
<t-button size="large" @click="clearCache"> 清除本地缓存 </t-button>
|
||||
<t-button
|
||||
size="large"
|
||||
:loading="cacheInfo?.clearing"
|
||||
:disabled="!cacheInfo?.count || cacheInfo?.count === 0"
|
||||
@click="clearCache"
|
||||
>
|
||||
{{ cacheInfo?.clearing ? '正在清除...' : '清除本地缓存' }}
|
||||
</t-button>
|
||||
<div v-if="!cacheInfo?.count || cacheInfo?.count === 0" class="no-cache-tip">
|
||||
暂无缓存文件
|
||||
</div>
|
||||
</div>
|
||||
</t-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { DialogPlugin } from 'tdesign-vue-next'
|
||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
// 定义事件
|
||||
const emit = defineEmits<{
|
||||
'cache-cleared': []
|
||||
}>()
|
||||
|
||||
const cacheInfo: any = ref({})
|
||||
|
||||
const loadCacheInfo = async (forceRefresh = false) => {
|
||||
try {
|
||||
console.log('正在获取缓存信息...', forceRefresh ? '(强制刷新)' : '')
|
||||
const res = await window.api.musicCache.getInfo()
|
||||
console.log('获取到缓存信息:', res)
|
||||
cacheInfo.value = res
|
||||
} catch (error) {
|
||||
console.error('获取缓存信息失败:', error)
|
||||
MessagePlugin.error('获取缓存信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.api.musicCache.getInfo().then((res) => (cacheInfo.value = res))
|
||||
loadCacheInfo()
|
||||
})
|
||||
|
||||
const clearCache = () => {
|
||||
const confirm = DialogPlugin.confirm({
|
||||
header: '确认清除缓存吗',
|
||||
@@ -29,12 +61,79 @@ const clearCache = () => {
|
||||
},
|
||||
onConfirm: async () => {
|
||||
confirm.hide()
|
||||
cacheInfo.value = {}
|
||||
await window.api.musicCache.clear()
|
||||
window.api.musicCache.getInfo().then((res) => (cacheInfo.value = res))
|
||||
|
||||
try {
|
||||
// 显示加载状态
|
||||
cacheInfo.value = { ...cacheInfo.value, clearing: true }
|
||||
|
||||
// 执行清除操作
|
||||
const result = await window.api.musicCache.clear()
|
||||
|
||||
if (result.success) {
|
||||
console.log('缓存清除成功,开始更新界面')
|
||||
MessagePlugin.success(result.message || '缓存清除成功')
|
||||
|
||||
// 发射缓存清除事件
|
||||
emit('cache-cleared')
|
||||
|
||||
// 立即重置缓存信息显示
|
||||
cacheInfo.value = {
|
||||
count: 0,
|
||||
size: 0,
|
||||
sizeFormatted: '0 B',
|
||||
clearing: false
|
||||
}
|
||||
|
||||
// 多次尝试重新加载,确保获取到最新状态
|
||||
let retryCount = 0
|
||||
const maxRetries = 3
|
||||
|
||||
const reloadWithRetry = async () => {
|
||||
retryCount++
|
||||
console.log(`第${retryCount}次尝试重新加载缓存信息`)
|
||||
|
||||
await loadCacheInfo(true)
|
||||
|
||||
// 如果还有缓存文件且重试次数未达上限,继续重试
|
||||
if (cacheInfo.value.count > 0 && retryCount < maxRetries) {
|
||||
console.log(`仍有${cacheInfo.value.count}个缓存文件,1秒后重试`)
|
||||
setTimeout(reloadWithRetry, 1000)
|
||||
} else {
|
||||
console.log('缓存信息更新完成:', cacheInfo.value)
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟一下再开始重新加载
|
||||
setTimeout(reloadWithRetry, 300)
|
||||
} else {
|
||||
MessagePlugin.error(result.message || '缓存清除失败')
|
||||
// 清除加载状态
|
||||
if (cacheInfo.value.clearing) {
|
||||
delete cacheInfo.value.clearing
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('清除缓存失败:', error)
|
||||
MessagePlugin.error('清除缓存失败,请重试')
|
||||
// 清除加载状态
|
||||
if (cacheInfo.value.clearing) {
|
||||
delete cacheInfo.value.clearing
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 刷新缓存信息(供父组件调用)
|
||||
const refreshCacheInfo = async () => {
|
||||
console.log('刷新缓存信息')
|
||||
await loadCacheInfo(true)
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
refreshCacheInfo
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -42,8 +141,14 @@ const clearCache = () => {
|
||||
width: 100%;
|
||||
|
||||
.card-body {
|
||||
padding: 10px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
|
||||
.no-cache-tip {
|
||||
margin-top: 10px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
importPlaylistFromFile,
|
||||
importPlaylistFromClipboard,
|
||||
validateImportedPlaylist
|
||||
} from '@renderer/utils/playlistExportImport'
|
||||
} from '@renderer/utils/playlist/playlistExportImport'
|
||||
import type { SongList } from '@renderer/types/audio'
|
||||
import { CloudDownloadIcon, DeleteIcon, CloudUploadIcon } from 'tdesign-icons-vue-next'
|
||||
|
||||
|
||||
613
src/renderer/src/components/layout/HomeLayout.vue
Normal file
@@ -0,0 +1,613 @@
|
||||
<script setup lang="ts">
|
||||
import TitleBarControls from '@renderer/components/TitleBarControls.vue'
|
||||
import { SearchIcon } from 'tdesign-icons-vue-next'
|
||||
import { onMounted, ref, watchEffect, computed } from 'vue'
|
||||
import { LocalUserDetailStore } from '@renderer/store/LocalUserDetail'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { searchValue } from '@renderer/store/search'
|
||||
|
||||
onMounted(() => {
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
watchEffect(() => {
|
||||
source.value = sourceicon[LocalUserDetail.userSource.source || 'wy']
|
||||
})
|
||||
})
|
||||
|
||||
const sourceicon = {
|
||||
kg: 'kugouyinle',
|
||||
wy: 'wangyiyun',
|
||||
mg: 'mg',
|
||||
tx: 'tx',
|
||||
kw: 'kw'
|
||||
}
|
||||
const source = ref('kugouyinle')
|
||||
interface MenuItem {
|
||||
name: string
|
||||
icon: string
|
||||
path: string
|
||||
}
|
||||
const menuList: MenuItem[] = [
|
||||
{
|
||||
name: '发现',
|
||||
icon: 'icon-faxian',
|
||||
path: '/home/find'
|
||||
},
|
||||
{
|
||||
name: '本地',
|
||||
icon: 'icon-music',
|
||||
path: '/home/local'
|
||||
},
|
||||
{
|
||||
name: '最近',
|
||||
icon: 'icon-shijian',
|
||||
path: '/home/recent'
|
||||
}
|
||||
]
|
||||
const menuActive = ref(0)
|
||||
const router = useRouter()
|
||||
const source_list_show = ref(false)
|
||||
|
||||
// 检查是否有插件数据
|
||||
const hasPluginData = computed(() => {
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
return !!(
|
||||
LocalUserDetail.userInfo.pluginId &&
|
||||
LocalUserDetail.userInfo.supportedSources &&
|
||||
Object.keys(LocalUserDetail.userInfo.supportedSources).length > 0
|
||||
)
|
||||
})
|
||||
|
||||
// 音源名称映射
|
||||
const sourceNames = {
|
||||
wy: '网易云音乐',
|
||||
kg: '酷狗音乐',
|
||||
mg: '咪咕音乐',
|
||||
tx: 'QQ音乐',
|
||||
kw: '酷我音乐'
|
||||
}
|
||||
|
||||
// 动态音源列表数据,基于supportedSources
|
||||
const sourceList = computed(() => {
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
const supportedSources = LocalUserDetail.userInfo.supportedSources
|
||||
|
||||
if (!supportedSources) return []
|
||||
|
||||
return Object.keys(supportedSources).map((key) => ({
|
||||
key,
|
||||
name: sourceNames[key] || key,
|
||||
icon: sourceicon[key] || key
|
||||
}))
|
||||
})
|
||||
|
||||
// 切换音源选择器显示状态
|
||||
const toggleSourceList = () => {
|
||||
source_list_show.value = !source_list_show.value
|
||||
}
|
||||
|
||||
// 选择音源
|
||||
const selectSource = (sourceKey: string) => {
|
||||
if (!hasPluginData.value) return
|
||||
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
LocalUserDetail.userInfo.selectSources = sourceKey
|
||||
|
||||
// 自动选择该音源的最高音质
|
||||
const sourceDetail = LocalUserDetail.userInfo.supportedSources?.[sourceKey]
|
||||
if (sourceDetail && sourceDetail.qualitys && sourceDetail.qualitys.length > 0) {
|
||||
const currentQuality = LocalUserDetail.userInfo.selectQuality
|
||||
if (!currentQuality || !sourceDetail.qualitys.includes(currentQuality)) {
|
||||
LocalUserDetail.userInfo.selectQuality =
|
||||
sourceDetail.qualitys[sourceDetail.qualitys.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
// 更新音源图标
|
||||
source.value = sourceicon[sourceKey]
|
||||
source_list_show.value = false
|
||||
}
|
||||
|
||||
// 点击遮罩关闭音源选择器
|
||||
const handleMaskClick = () => {
|
||||
source_list_show.value = false
|
||||
}
|
||||
|
||||
const handleClick = (index: number): void => {
|
||||
menuActive.value = index
|
||||
router.push(menuList[index].path)
|
||||
}
|
||||
|
||||
// 导航历史前进后退功能
|
||||
const goBack = (): void => {
|
||||
router.go(-1)
|
||||
}
|
||||
|
||||
const goForward = (): void => {
|
||||
router.go(1)
|
||||
}
|
||||
|
||||
// 搜索相关
|
||||
const keyword = ref('')
|
||||
|
||||
// 搜索类型:1: 单曲, 10: 专辑, 100: 歌手, 1000: 歌单
|
||||
// const searchType = ref(1)
|
||||
|
||||
// 处理搜索事件
|
||||
const handleSearch = async () => {
|
||||
if (!keyword.value.trim()) return
|
||||
const useSearch = searchValue()
|
||||
// 重新设置搜索关键字
|
||||
try {
|
||||
// 跳转到搜索结果页面,并传递搜索结果和关键词
|
||||
useSearch.setValue(keyword.value.trim()) // 设置搜索关键字
|
||||
router.push({
|
||||
path: '/home/search'
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('搜索失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理按键事件,按下回车键时触发搜索
|
||||
const handleKeyDown = () => {
|
||||
handleSearch()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<t-layout class="home-container">
|
||||
<!-- sidebar -->
|
||||
<t-aside class="sidebar">
|
||||
<div class="sidebar-content">
|
||||
<div class="logo-section">
|
||||
<div class="logo-icon">
|
||||
<i class="iconfont icon-music"></i>
|
||||
</div>
|
||||
<p class="app-title">
|
||||
<span style="color: #000; font-weight: 800">Ceru Music</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<nav class="nav-section">
|
||||
<t-button
|
||||
v-for="(item, index) in menuList"
|
||||
:key="index"
|
||||
:variant="menuActive == index ? 'base' : 'text'"
|
||||
:class="menuActive == index ? 'nav-button active' : 'nav-button'"
|
||||
block
|
||||
@click="handleClick(index)"
|
||||
>
|
||||
<i :class="`iconfont ${item.icon} nav-icon`"></i>
|
||||
{{ item.name }}
|
||||
</t-button>
|
||||
</nav>
|
||||
</div>
|
||||
</t-aside>
|
||||
|
||||
<t-layout style="flex: 1">
|
||||
<t-content>
|
||||
<div class="content">
|
||||
<!-- Header -->
|
||||
<div class="header">
|
||||
<t-button shape="circle" theme="default" class="nav-btn" @click="goBack">
|
||||
<i class="iconfont icon-xiangzuo"></i>
|
||||
</t-button>
|
||||
<t-button shape="circle" theme="default" class="nav-btn" @click="goForward">
|
||||
<i class="iconfont icon-xiangyou"></i>
|
||||
</t-button>
|
||||
|
||||
<div class="search-container">
|
||||
<div class="search-input">
|
||||
<div class="source-selector" @click="toggleSourceList">
|
||||
<svg class="icon" aria-hidden="true">
|
||||
<use :xlink:href="`#icon-${source}`"></use>
|
||||
</svg>
|
||||
</div>
|
||||
<!-- 透明遮罩 -->
|
||||
<transition name="mask">
|
||||
<div v-if="source_list_show" class="source-mask" @click="handleMaskClick"></div>
|
||||
</transition>
|
||||
<!-- 音源选择列表 -->
|
||||
<transition name="source">
|
||||
<div v-if="source_list_show" class="source-list">
|
||||
<div class="items">
|
||||
<div
|
||||
v-for="item in sourceList"
|
||||
:key="item.key"
|
||||
class="source-item"
|
||||
:class="{ active: source === item.icon }"
|
||||
@click="selectSource(item.key)"
|
||||
>
|
||||
<svg class="source-icon" aria-hidden="true">
|
||||
<use :xlink:href="`#icon-${item.icon}`"></use>
|
||||
</svg>
|
||||
<span class="source-name">{{ item.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
placeholder="搜索音乐、歌手"
|
||||
style="width: 100%"
|
||||
@enter="handleKeyDown"
|
||||
>
|
||||
<template #suffix>
|
||||
<t-button
|
||||
theme="primary"
|
||||
variant="text"
|
||||
shape="circle"
|
||||
style="display: flex; align-items: center; justify-content: center"
|
||||
@click="handleSearch"
|
||||
>
|
||||
<SearchIcon style="font-size: 16px; color: #000" />
|
||||
</t-button>
|
||||
</template>
|
||||
</t-input>
|
||||
</div>
|
||||
|
||||
<TitleBarControls :color="'#000'"></TitleBarControls>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mainContent">
|
||||
<slot name="body"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</t-content>
|
||||
</t-layout>
|
||||
</t-layout>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
:deep(.animate__animated) {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// 音源选择器过渡动画
|
||||
.source-enter-active,
|
||||
.source-leave-active {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.source-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(-0.5rem);
|
||||
}
|
||||
|
||||
.source-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-0.5rem);
|
||||
}
|
||||
|
||||
// 遮罩过渡动画
|
||||
.mask-enter-active,
|
||||
.mask-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.mask-enter-from,
|
||||
.mask-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.home-container {
|
||||
height: calc(100vh - var(--play-bottom-height));
|
||||
overflow-y: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 15rem;
|
||||
background-image: linear-gradient(to bottom, var(--td-brand-color-4) -140vh, #ffffff 30vh);
|
||||
border-right: 0.0625rem solid #e5e7eb;
|
||||
flex-shrink: 0;
|
||||
|
||||
.sidebar-content {
|
||||
padding: 1rem;
|
||||
|
||||
.logo-section {
|
||||
-webkit-app-region: drag;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
.logo-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
background-color: var(--td-brand-color-4);
|
||||
border-radius: 0.625rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
.iconfont {
|
||||
font-size: 1.25rem;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-weight: 500;
|
||||
font-size: 1.125rem;
|
||||
color: #111827;
|
||||
|
||||
span {
|
||||
font-weight: 500;
|
||||
color: #b8f0cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nav-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
.nav-button {
|
||||
justify-content: flex-start;
|
||||
height: 2.4rem;
|
||||
text-align: left;
|
||||
padding: 0.7rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
border: none;
|
||||
|
||||
.nav-icon {
|
||||
margin-right: 0.75rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: var(--td-brand-color-4);
|
||||
color: rgb(255, 255, 255);
|
||||
|
||||
&:hover {
|
||||
background-color: var(--td-brand-color-5);
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.active) {
|
||||
color: #6b7280;
|
||||
|
||||
&:hover {
|
||||
color: #111827;
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-layout__content) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0;
|
||||
background-image: linear-gradient(to bottom, var(--td-brand-color-4) -110vh, #ffffff 15vh);
|
||||
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
|
||||
.header {
|
||||
-webkit-app-region: drag;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 1.5rem;
|
||||
|
||||
.nav-btn {
|
||||
-webkit-app-region: no-drag;
|
||||
margin-right: 0.5rem;
|
||||
|
||||
&:last-of-type {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-size: 1rem;
|
||||
color: #3d4043;
|
||||
}
|
||||
|
||||
&:hover .iconfont {
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
|
||||
.search-container {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
position: relative;
|
||||
justify-content: space-between;
|
||||
|
||||
.search-input {
|
||||
-webkit-app-region: no-drag;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: width 0.3s;
|
||||
padding: 0 0.5rem;
|
||||
width: min(18.75rem, 400px);
|
||||
margin-right: 0.5rem;
|
||||
border-radius: 1.25rem !important;
|
||||
background-color: #fff;
|
||||
overflow: visible;
|
||||
position: relative;
|
||||
|
||||
&:has(input:focus) {
|
||||
width: max(18.75rem, 400px);
|
||||
}
|
||||
|
||||
.source-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
box-sizing: border-box;
|
||||
padding: 0.25rem;
|
||||
aspect-ratio: 1 / 1;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
transition: background-color 0.2s;
|
||||
|
||||
&:hover {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
|
||||
.source-arrow {
|
||||
margin-left: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
color: #6b7280;
|
||||
transition: transform 0.2s;
|
||||
|
||||
&.rotated {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.source-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 9999999;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.source-list {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
z-index: 10000000;
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
min-width: 10rem;
|
||||
overflow-y: hidden;
|
||||
margin-top: 0.25rem;
|
||||
padding: 0.5em;
|
||||
|
||||
.items {
|
||||
max-height: 12rem;
|
||||
overflow-y: auto;
|
||||
|
||||
// 隐藏滚动条
|
||||
&::-webkit-scrollbar {
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
// Firefox 隐藏滚动条
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.source-item {
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 0.75rem;
|
||||
margin-bottom: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
|
||||
&:last-child {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: var(--td-brand-color-1);
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
.source-icon {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.source-name {
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-input) {
|
||||
border-radius: 0rem !important;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
&.t-input--suffix {
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-btn {
|
||||
.iconfont {
|
||||
font-size: 1rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
&:hover .iconfont {
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mainContent {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
position: relative;
|
||||
height: 0;
|
||||
/* 确保flex子元素能够正确计算高度 */
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 0.375rem;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: #f1f5f9;
|
||||
border-radius: 0.1875rem;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: #cbd5e1;
|
||||
border-radius: 0.1875rem;
|
||||
transition: background-color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: #94a3b8;
|
||||
}
|
||||
}
|
||||
|
||||
/* Firefox 滚动条样式 */
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #cbd5e1 #f1f5f9;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
7
src/renderer/src/env.d.ts
vendored
@@ -1 +1,8 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { reactive } from 'vue'
|
||||
import { transitionVolume } from '@renderer/utils/volume'
|
||||
import { transitionVolume } from '@renderer/utils/audio/volume'
|
||||
import { LocalUserDetailStore } from '@renderer/store/LocalUserDetail'
|
||||
|
||||
import type {
|
||||
|
||||
@@ -3,6 +3,10 @@ import { ref } from 'vue'
|
||||
|
||||
export interface SettingsState {
|
||||
showFloatBall: boolean
|
||||
directories?: {
|
||||
cacheDir: string
|
||||
downloadDir: string
|
||||
}
|
||||
}
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// 测试网易云音乐服务的IPC通信
|
||||
export async function testNeteaseService() {
|
||||
try {
|
||||
console.log('开始测试网易云音乐服务...')
|
||||
|
||||
// 测试搜索功能
|
||||
const searchResult = await window.api.music.request('search', {
|
||||
type: 1,
|
||||
keyword: '周杰伦',
|
||||
limit: 10,
|
||||
offset: 0
|
||||
})
|
||||
console.log('搜索结果:', searchResult)
|
||||
|
||||
// 如果搜索成功且有结果,测试获取歌曲详情
|
||||
if (searchResult && searchResult.songs && searchResult.songs.length > 0) {
|
||||
const songId = searchResult.songs[0].id
|
||||
const songDetail = await window.api.music.request('getSongDetail', {
|
||||
ids: [songId.toString()]
|
||||
})
|
||||
console.log('歌曲详情:', songDetail)
|
||||
|
||||
// 测试获取歌词
|
||||
const lyric = await window.api.music.request('getLyric', {
|
||||
id: songId.toString()
|
||||
})
|
||||
console.log('歌词:', lyric)
|
||||
}
|
||||
|
||||
console.log('网易云音乐服务测试完成!')
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('网易云音乐服务测试失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,48 @@ async function downloadSingleSong(songInfo: MusicItem): Promise<void> {
|
||||
try {
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
let quality = LocalUserDetail.userSource.quality as string
|
||||
|
||||
// 检查是否为特殊音质(高清臻音、全景环绕或超清母带)
|
||||
const isSpecialQuality = ['hires', 'atmos', 'master'].includes(quality)
|
||||
|
||||
// 如果是特殊音质,先尝试获取对应链接
|
||||
if (isSpecialQuality) {
|
||||
try {
|
||||
console.log(`尝试下载特殊音质: ${quality} - ${qualityMap[quality]}`)
|
||||
const tip = MessagePlugin.success('开始下载歌曲:' + songInfo.name)
|
||||
|
||||
const specialResult = await window.api.music.requestSdk('downloadSingleSong', {
|
||||
pluginId: LocalUserDetail.userSource.pluginId?.toString() || '',
|
||||
source: songInfo.source,
|
||||
quality,
|
||||
songInfo: toRaw(songInfo)
|
||||
})
|
||||
|
||||
; (await tip).close()
|
||||
|
||||
// 如果成功获取特殊音质链接,处理结果并返回
|
||||
if (specialResult && 'error' in specialResult && !specialResult.error) {
|
||||
if (!Object.hasOwn(specialResult, 'path')) {
|
||||
MessagePlugin.info(specialResult.message)
|
||||
} else {
|
||||
await NotifyPlugin.success({
|
||||
title: '下载成功',
|
||||
content: `${specialResult.message} 保存位置: ${specialResult.path}`
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`下载${qualityMap[quality]}音质失败,回退到标准逻辑`)
|
||||
// 如果获取特殊音质失败,继续执行原有逻辑
|
||||
} catch (specialError) {
|
||||
console.log(`下载${qualityMap[quality]}音质出错,回退到标准逻辑:`, specialError)
|
||||
// 特殊音质获取失败,继续执行原有逻辑
|
||||
}
|
||||
MessagePlugin.error('下载失败了,向下兼容音质')
|
||||
}
|
||||
|
||||
// 原有逻辑:检查歌曲支持的最高音质
|
||||
if (
|
||||
qualityKey.indexOf(quality) >
|
||||
qualityKey.indexOf(
|
||||
@@ -41,6 +83,8 @@ async function downloadSingleSong(songInfo: MusicItem): Promise<void> {
|
||||
) {
|
||||
quality = (songInfo.types[songInfo.types.length - 1] as unknown as { type: any }).type
|
||||
}
|
||||
|
||||
console.log(`使用音质下载: ${quality} - ${qualityMap[quality]}`)
|
||||
const tip = MessagePlugin.success('开始下载歌曲:' + songInfo.name)
|
||||
const result = await window.api.music.requestSdk('downloadSingleSong', {
|
||||
pluginId: LocalUserDetail.userSource.pluginId?.toString() || '',
|
||||
@@ -48,7 +92,7 @@ async function downloadSingleSong(songInfo: MusicItem): Promise<void> {
|
||||
quality,
|
||||
songInfo: toRaw(songInfo)
|
||||
})
|
||||
;(await tip).close()
|
||||
; (await tip).close()
|
||||
if (!Object.hasOwn(result, 'path')) {
|
||||
MessagePlugin.info(result.message)
|
||||
} else {
|
||||
@@ -1,3 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2025. 时迁酱 Inc. All rights reserved.
|
||||
*
|
||||
* This software is the confidential and proprietary information of 时迁酱.
|
||||
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* @author 时迁酱,无聊的霜霜,Star
|
||||
* @since 2025-9-19
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
interface MediaSessionCallbacks {
|
||||
play: () => void
|
||||
pause: () => void
|
||||
@@ -39,12 +50,20 @@ class MediaSessionController {
|
||||
if (!this.isSupported) return
|
||||
|
||||
try {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: metadata.title,
|
||||
artist: metadata.artist,
|
||||
album: metadata.album,
|
||||
artwork: this.generateArtworkSizes(metadata.artworkUrl)
|
||||
})
|
||||
// 确保元数据完整性,避免空值导致SMTC显示异常
|
||||
const safeMetadata = {
|
||||
title: metadata.title || '未知歌曲',
|
||||
artist: metadata.artist || '未知艺术家',
|
||||
album: metadata.album || '未知专辑',
|
||||
artwork: metadata.artworkUrl ? this.generateArtworkSizes(metadata.artworkUrl) : []
|
||||
}
|
||||
|
||||
navigator.mediaSession.metadata = new MediaMetadata(safeMetadata)
|
||||
|
||||
// 强制更新播放状态,确保SMTC正确识别
|
||||
if (this.audioElement) {
|
||||
navigator.mediaSession.playbackState = this.audioElement.paused ? 'paused' : 'playing'
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to update media session metadata:', error)
|
||||
}
|
||||
@@ -13,8 +13,8 @@ type PlaylistEvents = {
|
||||
// 创建全局事件总线
|
||||
const emitter = mitt<PlaylistEvents>()
|
||||
|
||||
// 将事件总线挂载到全局
|
||||
;(window as any).musicEmitter = emitter
|
||||
// 将事件总线挂载到全局
|
||||
; (window as any).musicEmitter = emitter
|
||||
const qualityMap: Record<string, string> = {
|
||||
'128k': '标准音质',
|
||||
'192k': '高品音质',
|
||||
@@ -37,19 +37,51 @@ export async function getSongRealUrl(song: SongList): Promise<string> {
|
||||
const LocalUserDetail = LocalUserDetailStore()
|
||||
// 通过统一的request方法获取真实的播放URL
|
||||
let quality = LocalUserDetail.userSource.quality as string
|
||||
|
||||
// 检查是否为特殊音质(高清臻音、全景环绕或超清母带)
|
||||
const isSpecialQuality = ['hires', 'atmos', 'master'].includes(quality)
|
||||
|
||||
// 如果是特殊音质,先尝试获取对应链接
|
||||
if (isSpecialQuality) {
|
||||
try {
|
||||
console.log(`尝试获取特殊音质: ${quality} - ${qualityMap[quality]}`)
|
||||
const specialUrlData = await window.api.music.requestSdk('getMusicUrl', {
|
||||
pluginId: LocalUserDetail.userSource.pluginId as unknown as string,
|
||||
source: song.source,
|
||||
songInfo: song as any,
|
||||
quality
|
||||
})
|
||||
|
||||
// 如果成功获取特殊音质链接,直接返回
|
||||
if (typeof specialUrlData === 'string' || (typeof specialUrlData === 'object' && !specialUrlData.error)) {
|
||||
console.log(`成功获取${qualityMap[quality]}链接`)
|
||||
return specialUrlData as string
|
||||
}
|
||||
|
||||
console.log(`获取${qualityMap[quality]}链接失败,回退到标准逻辑`)
|
||||
// 如果获取特殊音质失败,继续执行原有逻辑
|
||||
} catch (specialError) {
|
||||
console.log(`获取${qualityMap[quality]}链接出错,回退到标准逻辑:`, specialError)
|
||||
// 特殊音质获取失败,继续执行原有逻辑
|
||||
}
|
||||
}
|
||||
|
||||
// 原有逻辑:检查歌曲支持的最高音质
|
||||
if (
|
||||
qualityKey.indexOf(quality) >
|
||||
qualityKey.indexOf((song.types[song.types.length - 1] as unknown as { type: any }).type)
|
||||
) {
|
||||
quality = (song.types[song.types.length - 1] as unknown as { type: any }).type
|
||||
}
|
||||
console.log(quality)
|
||||
|
||||
console.log(`使用音质: ${quality} - ${qualityMap[quality]}`)
|
||||
const urlData = await window.api.music.requestSdk('getMusicUrl', {
|
||||
pluginId: LocalUserDetail.userSource.pluginId as unknown as string,
|
||||
source: song.source,
|
||||
songInfo: song as any,
|
||||
quality
|
||||
})
|
||||
|
||||
console.log(urlData)
|
||||
if (typeof urlData === 'object' && urlData.error) {
|
||||
throw new Error(urlData.error)
|
||||
@@ -74,15 +106,11 @@ export async function addToPlaylistAndPlay(
|
||||
playSongCallback: (song: SongList) => Promise<void>
|
||||
) {
|
||||
try {
|
||||
// 获取真实播放URL
|
||||
|
||||
await getSongRealUrl(song)
|
||||
const playResult = playSongCallback(song)
|
||||
|
||||
// 使用store的方法添加歌曲到第一位
|
||||
localUserStore.addSongToFirst(song)
|
||||
|
||||
// 播放歌曲 - 确保正确处理Promise
|
||||
const playResult = playSongCallback(song)
|
||||
if (playResult && typeof playResult.then === 'function') {
|
||||
await playResult
|
||||
}
|
||||
@@ -152,9 +180,7 @@ export async function replacePlaylist(
|
||||
|
||||
// 播放第一首歌曲
|
||||
if (songs[0]) {
|
||||
await getSongRealUrl(songs[0])
|
||||
const playResult = playSongCallback(songs[0])
|
||||
|
||||
if (playResult && typeof playResult.then === 'function') {
|
||||
await playResult
|
||||
}
|
||||