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