新增HTTP开放API服务

This commit is contained in:
lyswhut
2024-03-29 14:43:32 +08:00
parent 1e03791e82
commit 9c0ae12959
35 changed files with 681 additions and 340 deletions
+3
View File
@@ -136,6 +136,9 @@ const defaultSetting: LX.AppSetting = {
'sync.server.maxSsnapshotNum': 5,
'sync.client.host': '',
'openAPI.enable': false,
'openAPI.port': '23330',
// 'theme.id': 'blue_plus',
'theme.id': 'green',
'theme.lightId': 'green',
+2 -1
View File
@@ -59,7 +59,7 @@ const modules = {
open_dev_tools: 'open_dev_tools',
set_power_save_blocker: 'set_power_save_blocker',
progress: 'progress',
player_status: 'player_status',
change_tray: 'change_tray',
quit_update: 'quit_update',
update_check: 'update_check',
@@ -134,6 +134,7 @@ const modules = {
clear_music_url: 'clear_music_url',
get_music_url_count: 'get_music_url_count',
open_api_action: 'open_api_action',
sync_action: 'sync_action',
sync_get_server_devices: 'sync_get_server_devices',
sync_remove_server_device: 'sync_remove_server_device',
+11
View File
@@ -619,6 +619,17 @@ declare global {
*/
'sync.client.host': string
/**
* 是否启用开放API服务
*/
'openAPI.enable': boolean
/**
* 同步服务端口号
*/
'openAPI.port': '23333' | string
/**
* 是否在离开搜索界面时自动清空搜索框
*/
+25
View File
@@ -0,0 +1,25 @@
declare namespace LX {
namespace OpenAPI {
interface Status {
status: boolean
message: string
address: string
}
interface EnableServer {
enable: boolean
port: string
}
interface ActionBase <A> {
action: A
}
interface ActionData<A, D> extends ActionBase<A> {
data: D
}
type Action<A, D = undefined> = D extends undefined ? ActionBase<A> : ActionData<A, D>
type Actions = Action<'status'>
| Action<'enable', EnableServer>
}
}
+13
View File
@@ -15,5 +15,18 @@ declare namespace LX {
interface LyricInfo extends LX.Music.LyricInfo {
rawlrcInfo: LX.Music.LyricInfo
}
interface Status {
status: 'playing' | 'paused' | 'error' | 'stoped'
name: string
singer: string
albumName: string
picUrl: string
progress: number
duration: number
lyricLineText: string
lyric: string
collect: boolean
}
}
}
@@ -227,4 +227,8 @@ export default class Lyric {
this._handleLinePlayerOnPlay(num, '', this.linePlayer._currentTime())
} else this.playingLineNum = 0
}
setAutoPause(autoPause) {
this.linePlayer.setAutoPause(autoPause)
}
}
@@ -224,4 +224,16 @@ export default class LinePlayer {
this.extendedLyrics = extendedLyrics
this._init()
}
setAutoPause(autoPause) {
if (autoPause) {
timeoutTools.nextTick = window.requestAnimationFrame.bind(window)
timeoutTools.cancelNextTick = window.cancelAnimationFrame.bind(window)
} else {
timeoutTools.nextTick = (handler) => {
return setTimeout(handler, 80)
}
timeoutTools.cancelNextTick = clearTimeout.bind(global)
}
}
}
+4 -2
View File
@@ -3,6 +3,8 @@ export const getNow = typeof performance == 'object' && window.performance.now ?
export class TimeoutTools {
constructor(thresholdTime = 80) {
this.nextTick = window.requestAnimationFrame.bind(window)
this.cancelNextTick = window.cancelAnimationFrame.bind(window)
this.invokeTime = 0
this.animationFrameId = null
this.timeoutId = null
@@ -11,7 +13,7 @@ export class TimeoutTools {
}
run() {
this.animationFrameId = window.requestAnimationFrame(() => {
this.animationFrameId = this.nextTick(() => {
this.animationFrameId = null
let diff = this.invokeTime - getNow()
// console.log('diff', diff)
@@ -39,7 +41,7 @@ export class TimeoutTools {
clear() {
if (this.animationFrameId) {
window.cancelAnimationFrame(this.animationFrameId)
this.cancelNextTick(this.animationFrameId)
this.animationFrameId = null
}
if (this.timeoutId) {