托盘菜单新增播放、切歌、收藏控制
parent
9c0ae12959
commit
7a08cb5ddd
|
@ -3,6 +3,7 @@
|
||||||
- 主题编辑器添加“深色字体”选项,启用后将减少字体颜色梯度,各类字体(正文、标签字体等)颜色将更接近,这有助于解决创建全透明主题时可能出现的字体配色问题(#1799)
|
- 主题编辑器添加“深色字体”选项,启用后将减少字体颜色梯度,各类字体(正文、标签字体等)颜色将更接近,这有助于解决创建全透明主题时可能出现的字体配色问题(#1799)
|
||||||
- 新增在线自定义源导入功能,允许通过http/https链接导入自定义源
|
- 新增在线自定义源导入功能,允许通过http/https链接导入自定义源
|
||||||
- 新增HTTP开放API服务,默认关闭,该服务可以为第三方软件提供调用LX的能力,可用API看说明文档(#1824)
|
- 新增HTTP开放API服务,默认关闭,该服务可以为第三方软件提供调用LX的能力,可用API看说明文档(#1824)
|
||||||
|
- 托盘菜单新增播放、切歌、收藏控制
|
||||||
|
|
||||||
### 优化
|
### 优化
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
hideWindow as hideMainWindow,
|
hideWindow as hideMainWindow,
|
||||||
isExistWindow as isExistMainWindow,
|
isExistWindow as isExistMainWindow,
|
||||||
isShowWindow as isShowMainWindow,
|
isShowWindow as isShowMainWindow,
|
||||||
|
sendTaskbarButtonClick,
|
||||||
showWindow as showMainWindow,
|
showWindow as showMainWindow,
|
||||||
} from './winMain'
|
} from './winMain'
|
||||||
import { quitApp } from '@main/app'
|
import { quitApp } from '@main/app'
|
||||||
|
@ -13,6 +14,14 @@ let tray: Electron.Tray | null
|
||||||
let isEnableTray: boolean = false
|
let isEnableTray: boolean = false
|
||||||
let themeId: number
|
let themeId: number
|
||||||
|
|
||||||
|
const playerState = {
|
||||||
|
empty: false,
|
||||||
|
collect: false,
|
||||||
|
play: false,
|
||||||
|
next: true,
|
||||||
|
prev: true,
|
||||||
|
}
|
||||||
|
|
||||||
const watchConfigKeys = [
|
const watchConfigKeys = [
|
||||||
'desktopLyric.enable',
|
'desktopLyric.enable',
|
||||||
'desktopLyric.isLock',
|
'desktopLyric.isLock',
|
||||||
|
@ -42,6 +51,12 @@ const themeList = [
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
'en-us': {
|
'en-us': {
|
||||||
|
collect: 'Collection',
|
||||||
|
uncollect: 'Cancel collection',
|
||||||
|
play: 'Play',
|
||||||
|
pause: 'Pause',
|
||||||
|
next: 'Next song',
|
||||||
|
prev: 'Previous song',
|
||||||
hide_win_main: 'Hide Main Window',
|
hide_win_main: 'Hide Main Window',
|
||||||
show_win_main: 'Show Main Window',
|
show_win_main: 'Show Main Window',
|
||||||
hide_win_lyric: 'Close desktop lyrics',
|
hide_win_lyric: 'Close desktop lyrics',
|
||||||
|
@ -53,6 +68,12 @@ const messages = {
|
||||||
exit: 'Exit',
|
exit: 'Exit',
|
||||||
},
|
},
|
||||||
'zh-cn': {
|
'zh-cn': {
|
||||||
|
collect: '收藏',
|
||||||
|
uncollect: '取消收藏',
|
||||||
|
play: '播放',
|
||||||
|
pause: '暂停',
|
||||||
|
next: '下一曲',
|
||||||
|
prev: '上一曲',
|
||||||
hide_win_main: '隐藏主界面',
|
hide_win_main: '隐藏主界面',
|
||||||
show_win_main: '显示主界面',
|
show_win_main: '显示主界面',
|
||||||
hide_win_lyric: '关闭桌面歌词',
|
hide_win_lyric: '关闭桌面歌词',
|
||||||
|
@ -64,6 +85,12 @@ const messages = {
|
||||||
exit: '退出',
|
exit: '退出',
|
||||||
},
|
},
|
||||||
'zh-tw': {
|
'zh-tw': {
|
||||||
|
collect: '收藏',
|
||||||
|
uncollect: '取消收藏',
|
||||||
|
play: '播放',
|
||||||
|
pause: '暫停',
|
||||||
|
next: '下一曲',
|
||||||
|
prev: '上一曲',
|
||||||
hide_win_main: '隱藏主界面',
|
hide_win_main: '隱藏主界面',
|
||||||
show_win_main: '顯示主界面',
|
show_win_main: '顯示主界面',
|
||||||
hide_win_lyric: '關閉桌面歌詞',
|
hide_win_lyric: '關閉桌面歌詞',
|
||||||
|
@ -120,25 +147,50 @@ const handleUpdateConfig = (config: any) => {
|
||||||
global.lx.event_app.update_config(config)
|
global.lx.event_app.update_config(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createPlayerMenu = () => {
|
||||||
|
let menu: Electron.MenuItemConstructorOptions[] = []
|
||||||
|
menu.push(playerState.play ? {
|
||||||
|
label: i18n.getMessage('pause'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('pause')
|
||||||
|
},
|
||||||
|
} : {
|
||||||
|
label: i18n.getMessage('play'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('play')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
menu.push({
|
||||||
|
label: i18n.getMessage('prev'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('prev')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
menu.push({
|
||||||
|
label: i18n.getMessage('next'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('next')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
menu.push(playerState.collect ? {
|
||||||
|
label: i18n.getMessage('uncollect'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('unCollect')
|
||||||
|
},
|
||||||
|
} : {
|
||||||
|
label: i18n.getMessage('collect'),
|
||||||
|
click() {
|
||||||
|
sendTaskbarButtonClick('collect')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return menu
|
||||||
|
}
|
||||||
|
|
||||||
export const createMenu = () => {
|
export const createMenu = () => {
|
||||||
if (!tray) return
|
if (!tray) return
|
||||||
let menu = []
|
let menu: Electron.MenuItemConstructorOptions[] = createPlayerMenu()
|
||||||
if (isExistMainWindow()) {
|
if (playerState.empty) for (const m of menu) m.enabled = false
|
||||||
const isShow = isShowMainWindow()
|
menu.push({ type: 'separator' })
|
||||||
menu.push(isShow
|
|
||||||
? {
|
|
||||||
label: i18n.getMessage('hide_win_main'),
|
|
||||||
click() {
|
|
||||||
hideMainWindow()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
label: i18n.getMessage('show_win_main'),
|
|
||||||
click() {
|
|
||||||
showMainWindow()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
menu.push(global.lx.appSetting['desktopLyric.enable']
|
menu.push(global.lx.appSetting['desktopLyric.enable']
|
||||||
? {
|
? {
|
||||||
label: i18n.getMessage('hide_win_lyric'),
|
label: i18n.getMessage('hide_win_lyric'),
|
||||||
|
@ -178,6 +230,23 @@ export const createMenu = () => {
|
||||||
handleUpdateConfig({ 'desktopLyric.isAlwaysOnTop': true })
|
handleUpdateConfig({ 'desktopLyric.isAlwaysOnTop': true })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
menu.push({ type: 'separator' })
|
||||||
|
if (isExistMainWindow()) {
|
||||||
|
const isShow = isShowMainWindow()
|
||||||
|
menu.push(isShow
|
||||||
|
? {
|
||||||
|
label: i18n.getMessage('hide_win_main'),
|
||||||
|
click() {
|
||||||
|
hideMainWindow()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
label: i18n.getMessage('show_win_main'),
|
||||||
|
click() {
|
||||||
|
showMainWindow()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
menu.push({
|
menu.push({
|
||||||
label: i18n.getMessage('exit'),
|
label: i18n.getMessage('exit'),
|
||||||
click() {
|
click() {
|
||||||
|
@ -241,4 +310,34 @@ export default () => {
|
||||||
i18n.setLang(global.lx.appSetting['common.langId'])
|
i18n.setLang(global.lx.appSetting['common.langId'])
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
global.lx.event_app.on('player_status', (status) => {
|
||||||
|
let updated = false
|
||||||
|
if (status.status) {
|
||||||
|
switch (status.status) {
|
||||||
|
case 'paused':
|
||||||
|
playerState.play = false
|
||||||
|
playerState.empty &&= false
|
||||||
|
break
|
||||||
|
case 'error':
|
||||||
|
playerState.play = false
|
||||||
|
playerState.empty &&= false
|
||||||
|
break
|
||||||
|
case 'playing':
|
||||||
|
playerState.play = true
|
||||||
|
playerState.empty &&= false
|
||||||
|
break
|
||||||
|
case 'stoped':
|
||||||
|
playerState.play &&= false
|
||||||
|
playerState.empty = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
if (status.collect != null) {
|
||||||
|
playerState.collect = status.collect
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
if (updated) init()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ export default () => {
|
||||||
prev: true,
|
prev: true,
|
||||||
}
|
}
|
||||||
const progressStatus = {
|
const progressStatus = {
|
||||||
progress: 0,
|
progress: -1,
|
||||||
status: 'none' as Electron.ProgressBarOptions['mode'],
|
status: 'none' as Electron.ProgressBarOptions['mode'],
|
||||||
}
|
}
|
||||||
let showProgress = global.lx.appSetting['player.isShowTaskProgess']
|
let showProgress = global.lx.appSetting['player.isShowTaskProgess']
|
||||||
|
@ -87,12 +87,11 @@ export default () => {
|
||||||
if (status.collect != null) taskBarButtonFlags.collect = status.collect
|
if (status.collect != null) taskBarButtonFlags.collect = status.collect
|
||||||
setThumbarButtons(taskBarButtonFlags)
|
setThumbarButtons(taskBarButtonFlags)
|
||||||
}
|
}
|
||||||
if (status.progress) {
|
if (status.progress != null && global.lx.player_status.duration) {
|
||||||
const progress = status.progress / global.lx.player_status.duration
|
const progress = status.progress / global.lx.player_status.duration
|
||||||
if (progress.toFixed(2) == progressStatus.progress.toFixed(2)) return
|
if (progress.toFixed(2) != progressStatus.progress.toFixed(2) && showProgress) {
|
||||||
progressStatus.progress = progress
|
progressStatus.progress = progress < 0.01 ? 0.01 : progress
|
||||||
if (showProgress) {
|
setProgressBar(progressStatus.progress, {
|
||||||
setProgressBar(progress, {
|
|
||||||
mode: progressStatus.status,
|
mode: progressStatus.status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ export const setWindowBounds = (options: Partial<Electron.Rectangle>) => {
|
||||||
}
|
}
|
||||||
export const setProgressBar = (progress: number, options?: Electron.ProgressBarOptions) => {
|
export const setProgressBar = (progress: number, options?: Electron.ProgressBarOptions) => {
|
||||||
if (!browserWindow) return
|
if (!browserWindow) return
|
||||||
|
console.log(progress, options)
|
||||||
browserWindow.setProgressBar(progress, options)
|
browserWindow.setProgressBar(progress, options)
|
||||||
}
|
}
|
||||||
export const setIgnoreMouseEvents = (ignore: boolean, options?: Electron.IgnoreMouseEventsOptions) => {
|
export const setIgnoreMouseEvents = (ignore: boolean, options?: Electron.IgnoreMouseEventsOptions) => {
|
||||||
|
|
|
@ -143,6 +143,7 @@ const handleRestorePlay = async(restorePlayInfo: LX.Player.SavedPlayInfo) => {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
if (musicInfo.id != playMusicInfo.musicInfo?.id) return
|
if (musicInfo.id != playMusicInfo.musicInfo?.id) return
|
||||||
window.app_event.setProgress(appSetting['player.isSavePlayTime'] ? restorePlayInfo.time : 0, restorePlayInfo.maxTime)
|
window.app_event.setProgress(appSetting['player.isSavePlayTime'] ? restorePlayInfo.time : 0, restorePlayInfo.maxTime)
|
||||||
|
window.app_event.pause()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ export default () => {
|
||||||
|
|
||||||
const setProgress = (time: number, maxTime?: number) => {
|
const setProgress = (time: number, maxTime?: number) => {
|
||||||
if (!musicInfo.id) return
|
if (!musicInfo.id) return
|
||||||
|
if (maxTime != null) setMaxplayTime(maxTime)
|
||||||
console.log('setProgress', time, maxTime)
|
console.log('setProgress', time, maxTime)
|
||||||
if (time > 0) restorePlayTime = time
|
if (time > 0) restorePlayTime = time
|
||||||
if (mediaBuffer.playTime) {
|
if (mediaBuffer.playTime) {
|
||||||
|
@ -69,8 +70,6 @@ export default () => {
|
||||||
setNowPlayTime(time)
|
setNowPlayTime(time)
|
||||||
setCurrentTime(time)
|
setCurrentTime(time)
|
||||||
|
|
||||||
if (maxTime != null) setMaxplayTime(maxTime)
|
|
||||||
|
|
||||||
// if (!isPlay) audio.play()
|
// if (!isPlay) audio.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue