mirror of
https://github.com/lqtmcstudio/QZMusic_PC.git
synced 2026-06-20 23:35:06 +08:00
feat: 迁移架构&实现功能
- 持久化音量设置 - 搜索页支持自定义每页显示数量(持久化) - vite-electron-plugin迁移electron-vite
This commit is contained in:
@@ -2,6 +2,7 @@ import { app } from 'electron'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
@@ -15,7 +16,8 @@ type PluginModule = {
|
||||
getUrl?: (id: string, quality: string) => Promise<string> | string,
|
||||
musicSearch?: {
|
||||
search: (query: string, page: number, limit: number) => Promise<any> | any
|
||||
}
|
||||
},
|
||||
getLyric?: (id: string) => Promise<string> | object
|
||||
}
|
||||
|
||||
export class PluginSystem {
|
||||
@@ -26,27 +28,6 @@ export class PluginSystem {
|
||||
this.loadPlugin()
|
||||
}
|
||||
|
||||
async search(query: string, page: number, limit: number): Promise<any> {
|
||||
if (!this.plugin?.musicSearch?.search) {
|
||||
return {
|
||||
list: [],
|
||||
total: 0,
|
||||
allPage: 0,
|
||||
error: 'Search not implemented'
|
||||
}
|
||||
}
|
||||
try {
|
||||
return await this.plugin.musicSearch.search(query, page, limit)
|
||||
} catch (e: any) {
|
||||
return {
|
||||
list: [],
|
||||
total: 0,
|
||||
allPage: 0,
|
||||
error: e.message || 'Plugin search error'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private loadPlugin() {
|
||||
try {
|
||||
const pluginPath = path.join(
|
||||
@@ -100,4 +81,42 @@ export class PluginSystem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async search(query: string, page: number, limit: number): Promise<any> {
|
||||
if (!this.plugin?.musicSearch?.search) {
|
||||
return {
|
||||
list: [],
|
||||
total: 0,
|
||||
allPage: 0,
|
||||
error: 'Search not implemented'
|
||||
}
|
||||
}
|
||||
try {
|
||||
return await this.plugin.musicSearch.search(query, page, limit)
|
||||
} catch (e: any) {
|
||||
return {
|
||||
list: [],
|
||||
total: 0,
|
||||
allPage: 0,
|
||||
error: e.message || 'Plugin search error'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getLyric(id: string): Promise<any> {
|
||||
console.log("getLyric not implemented");
|
||||
if (!this.plugin?.getLyric) {
|
||||
console.log("getLyric not implemented2");
|
||||
return
|
||||
}
|
||||
try {
|
||||
const result = await this.plugin.getLyric(id)
|
||||
console.log(result)
|
||||
return result
|
||||
} catch (e: any) {
|
||||
console.log(e)
|
||||
MessagePlugin.error(e).then()
|
||||
return {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user