新增播放器声音大小、静音、播放进度控制(#2386)
parent
2ccca633ed
commit
021f89da29
|
@ -1,4 +1,3 @@
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 新增「设置 → 其他设置 → 主窗口使用软件内置的圆角及阴影」设置(#2360)
|
- 开放API新增播放器声音大小、静音、播放进度控制,详情看接入文档(#2386)
|
||||||
*默认启用,关闭后将使用系统原生的窗口样式,该设置重启软件后生效*
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ declare namespace LX {
|
||||||
| 'pause'
|
| 'pause'
|
||||||
| 'play'
|
| 'play'
|
||||||
| 'next'
|
| 'next'
|
||||||
|
| 'seek'
|
||||||
|
| 'volume'
|
||||||
|
| 'mute'
|
||||||
|
|
||||||
interface LyricInfo extends LX.Music.LyricInfo {
|
interface LyricInfo extends LX.Music.LyricInfo {
|
||||||
rawlrcInfo: LX.Music.LyricInfo
|
rawlrcInfo: LX.Music.LyricInfo
|
||||||
|
@ -29,6 +32,8 @@ declare namespace LX {
|
||||||
lyricLineAllText: string
|
lyricLineAllText: string
|
||||||
lyric: string
|
lyric: string
|
||||||
collect: boolean
|
collect: boolean
|
||||||
|
volume: number
|
||||||
|
mute: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,8 @@ export const initGlobalData = () => {
|
||||||
lyricLineAllText: '',
|
lyricLineAllText: '',
|
||||||
lyric: '',
|
lyric: '',
|
||||||
collect: false,
|
collect: false,
|
||||||
|
volume: 0,
|
||||||
|
mute: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +232,15 @@ export const listenerAppEvent = (startApp: () => void) => {
|
||||||
global.lx.theme.shouldUseDarkColors = shouldUseDarkColors
|
global.lx.theme.shouldUseDarkColors = shouldUseDarkColors
|
||||||
global.lx?.event_app.system_theme_change(shouldUseDarkColors)
|
global.lx?.event_app.system_theme_change(shouldUseDarkColors)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
global.lx.event_app.on('updated_config', (config, setting) => {
|
||||||
|
if (config.includes('player.volume')) {
|
||||||
|
global.lx.event_app.player_status({ volume: Math.trunc(setting['player.volume']! * 100) })
|
||||||
|
}
|
||||||
|
if (config.includes('player.isMute')) {
|
||||||
|
global.lx.event_app.player_status({ mute: setting['player.isMute'] })
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const initTheme = () => {
|
const initTheme = () => {
|
||||||
|
|
|
@ -142,12 +142,44 @@ const handleStartServer = async(port: number, ip: string) => new Promise<void>((
|
||||||
case '/skip-prev':
|
case '/skip-prev':
|
||||||
sendTaskbarButtonClick('prev')
|
sendTaskbarButtonClick('prev')
|
||||||
break
|
break
|
||||||
|
case '/seek': {
|
||||||
|
const offset = parseFloat(querystring.parse(query ?? '').offset as string)
|
||||||
|
if (Number.isNaN(offset) || offset < 0 || offset > global.lx.player_status.duration) {
|
||||||
|
code = 400
|
||||||
|
msg = 'Invalid offset'
|
||||||
|
} else {
|
||||||
|
sendTaskbarButtonClick('seek', parseFloat(offset.toFixed(3)))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
case '/collect':
|
case '/collect':
|
||||||
sendTaskbarButtonClick('collect')
|
sendTaskbarButtonClick('collect')
|
||||||
break
|
break
|
||||||
case '/uncollect':
|
case '/uncollect':
|
||||||
sendTaskbarButtonClick('unCollect')
|
sendTaskbarButtonClick('unCollect')
|
||||||
break
|
break
|
||||||
|
case '/volume': {
|
||||||
|
const volume = parseInt(querystring.parse(query ?? '').volume as string)
|
||||||
|
if (Number.isNaN(volume) || volume < 0 || volume > 100) {
|
||||||
|
code = 400
|
||||||
|
msg = 'Invalid volume'
|
||||||
|
} else {
|
||||||
|
sendTaskbarButtonClick('volume', volume / 100)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case '/mute': {
|
||||||
|
const mute = querystring.parse(query ?? '').mute
|
||||||
|
if (mute == 'true') {
|
||||||
|
sendTaskbarButtonClick('mute', true)
|
||||||
|
} else if (mute == 'false') {
|
||||||
|
sendTaskbarButtonClick('mute', false)
|
||||||
|
} else {
|
||||||
|
code = 400
|
||||||
|
msg = 'Invalid mute value'
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
case '/subscribe-player-status':
|
case '/subscribe-player-status':
|
||||||
try {
|
try {
|
||||||
handleSubscribePlayerStatus(req, res, query)
|
handleSubscribePlayerStatus(req, res, query)
|
||||||
|
|
|
@ -137,8 +137,8 @@ export const sendFocus = () => {
|
||||||
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.focus)
|
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.focus)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendTaskbarButtonClick = (action: LX.Player.StatusButtonActions) => {
|
export const sendTaskbarButtonClick = (action: LX.Player.StatusButtonActions, data?: unknown) => {
|
||||||
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, action)
|
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, { action, data })
|
||||||
}
|
}
|
||||||
export const sendConfigChange = (setting: Partial<LX.AppSetting>) => {
|
export const sendConfigChange = (setting: Partial<LX.AppSetting>) => {
|
||||||
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.on_config_change, setting)
|
sendEvent(WIN_MAIN_RENDERER_EVENT_NAME.on_config_change, setting)
|
||||||
|
|
|
@ -81,7 +81,7 @@ export default () => {
|
||||||
// buttons.lockLrc = setting.desktopLyric.isLock
|
// buttons.lockLrc = setting.desktopLyric.isLock
|
||||||
// setButtons()
|
// setButtons()
|
||||||
// }
|
// }
|
||||||
const rTaskbarThumbarClick = onPlayerAction(async({ params: action }) => {
|
const rTaskbarThumbarClick = onPlayerAction(async({ params: { action, data } }) => {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'play':
|
case 'play':
|
||||||
play()
|
play()
|
||||||
|
@ -105,6 +105,19 @@ export default () => {
|
||||||
void removeListMusics({ listId: loveList.id, ids: ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo.id : playMusicInfo.musicInfo.id] })
|
void removeListMusics({ listId: loveList.id, ids: ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo.id : playMusicInfo.musicInfo.id] })
|
||||||
if (await updateCollectStatus()) sendPlayerStatus({ collect })
|
if (await updateCollectStatus()) sendPlayerStatus({ collect })
|
||||||
break
|
break
|
||||||
|
case 'seek': {
|
||||||
|
let progress = data as number
|
||||||
|
if (progress < 0) progress = 0
|
||||||
|
else if (progress > playProgress.maxPlayTime) progress = playProgress.maxPlayTime
|
||||||
|
window.app_event.setProgress(progress)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'mute':
|
||||||
|
window.app_event.setVolumeIsMute(data as boolean)
|
||||||
|
break
|
||||||
|
case 'volume':
|
||||||
|
window.app_event.setVolume(data as number)
|
||||||
|
break
|
||||||
// case 'lrc':
|
// case 'lrc':
|
||||||
// setVisibleDesktopLyric(true)
|
// setVisibleDesktopLyric(true)
|
||||||
// updateSetting()
|
// updateSetting()
|
||||||
|
|
|
@ -476,7 +476,10 @@ export const hotKeyGetStatus = async() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 主进程操作播放器状态
|
// 主进程操作播放器状态
|
||||||
export const onPlayerAction = (listener: LX.IpcRendererEventListenerParams<LX.Player.StatusButtonActions>): RemoveListener => {
|
export const onPlayerAction = (listener: LX.IpcRendererEventListenerParams<{
|
||||||
|
action: LX.Player.StatusButtonActions
|
||||||
|
data?: unknown
|
||||||
|
}>): RemoveListener => {
|
||||||
rendererOn(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, listener)
|
rendererOn(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, listener)
|
||||||
return () => {
|
return () => {
|
||||||
rendererOff(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, listener)
|
rendererOff(WIN_MAIN_RENDERER_EVENT_NAME.player_action_on_button_click, listener)
|
||||||
|
|
Loading…
Reference in New Issue