新增 是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Tray, Menu, nativeImage } from 'electron'
|
||||
import { isWin } from '@common/utils'
|
||||
import { isMac, isWin } from '@common/utils'
|
||||
import path from 'node:path'
|
||||
import {
|
||||
hideWindow as hideMainWindow,
|
||||
@@ -13,6 +13,7 @@ import { quitApp } from '@main/app'
|
||||
let tray: Electron.Tray | null
|
||||
let isEnableTray: boolean = false
|
||||
let themeId: number
|
||||
let isShowStatusBarLyric: boolean = false
|
||||
|
||||
const playerState = {
|
||||
empty: false,
|
||||
@@ -28,6 +29,7 @@ const watchConfigKeys = [
|
||||
'desktopLyric.isAlwaysOnTop',
|
||||
'tray.themeId',
|
||||
'tray.enable',
|
||||
'player.isShowStatusBarLyric',
|
||||
'common.langId',
|
||||
] satisfies Array<keyof LX.AppSetting>
|
||||
|
||||
@@ -65,6 +67,8 @@ const messages = {
|
||||
unlock_win_lyric: 'Unlock desktop lyrics',
|
||||
top_win_lyric: 'Set top lyrics',
|
||||
untop_win_lyric: 'Cancel top lyrics',
|
||||
show_statusbar_lyric: 'Show statusbar lyric',
|
||||
hide_statusbar_lyric: 'Hide statusbar lyric',
|
||||
exit: 'Exit',
|
||||
},
|
||||
'zh-cn': {
|
||||
@@ -82,6 +86,8 @@ const messages = {
|
||||
unlock_win_lyric: '解锁桌面歌词',
|
||||
top_win_lyric: '置顶歌词',
|
||||
untop_win_lyric: '取消置顶',
|
||||
show_statusbar_lyric: '显示状态栏歌词',
|
||||
hide_statusbar_lyric: '隐藏状态栏歌词',
|
||||
exit: '退出',
|
||||
},
|
||||
'zh-tw': {
|
||||
@@ -99,6 +105,8 @@ const messages = {
|
||||
unlock_win_lyric: '解鎖桌面歌詞',
|
||||
top_win_lyric: '置頂歌詞',
|
||||
untop_win_lyric: '取消置頂',
|
||||
show_statusbar_lyric: '顯示狀態列歌詞',
|
||||
hide_statusbar_lyric: '隱藏狀態列歌詞',
|
||||
exit: '退出',
|
||||
},
|
||||
} as const
|
||||
@@ -141,11 +149,12 @@ export const destroyTray = () => {
|
||||
if (!tray) return
|
||||
tray.destroy()
|
||||
isEnableTray = false
|
||||
isShowStatusBarLyric = false
|
||||
tray = null
|
||||
}
|
||||
|
||||
const handleUpdateConfig = (config: any) => {
|
||||
global.lx.event_app.update_config(config)
|
||||
const handleUpdateConfig = (setting: Partial<LX.AppSetting>) => {
|
||||
global.lx.event_app.update_config(setting)
|
||||
}
|
||||
|
||||
const createPlayerMenu = () => {
|
||||
@@ -231,6 +240,22 @@ export const createMenu = () => {
|
||||
handleUpdateConfig({ 'desktopLyric.isAlwaysOnTop': true })
|
||||
},
|
||||
})
|
||||
if (isMac) {
|
||||
menu.push({ type: 'separator' })
|
||||
menu.push(isShowStatusBarLyric
|
||||
? {
|
||||
label: i18n.getMessage('hide_statusbar_lyric'),
|
||||
click() {
|
||||
handleUpdateConfig({ 'player.isShowStatusBarLyric': false })
|
||||
},
|
||||
}
|
||||
: {
|
||||
label: i18n.getMessage('show_statusbar_lyric'),
|
||||
click() {
|
||||
handleUpdateConfig({ 'player.isShowStatusBarLyric': true })
|
||||
},
|
||||
})
|
||||
}
|
||||
menu.push({ type: 'separator' })
|
||||
if (isExistMainWindow()) {
|
||||
const isShow = isShowMainWindow()
|
||||
@@ -263,6 +288,12 @@ export const setTrayImage = (themeId: number) => {
|
||||
tray.setImage(nativeImage.createFromPath(getIconPath(themeId)))
|
||||
}
|
||||
|
||||
const setLyric = (lyricLineText?: string) => {
|
||||
if (isShowStatusBarLyric && tray && lyricLineText != null) {
|
||||
tray.setTitle(lyricLineText)
|
||||
}
|
||||
}
|
||||
|
||||
const init = () => {
|
||||
if (themeId != global.lx.appSetting['tray.themeId']) {
|
||||
themeId = global.lx.appSetting['tray.themeId']
|
||||
@@ -272,6 +303,14 @@ const init = () => {
|
||||
isEnableTray = global.lx.appSetting['tray.enable']
|
||||
global.lx.appSetting['tray.enable'] ? createTray() : destroyTray()
|
||||
}
|
||||
if (isShowStatusBarLyric !== global.lx.appSetting['player.isShowStatusBarLyric']) {
|
||||
isShowStatusBarLyric = global.lx.appSetting['player.isShowStatusBarLyric']
|
||||
if (isShowStatusBarLyric) {
|
||||
setLyric(global.lx.player_status.lyricLineText)
|
||||
} else {
|
||||
tray?.setTitle('')
|
||||
}
|
||||
}
|
||||
createMenu()
|
||||
}
|
||||
|
||||
@@ -317,21 +356,27 @@ export default () => {
|
||||
case 'paused':
|
||||
playerState.play = false
|
||||
playerState.empty &&= false
|
||||
setLyric('')
|
||||
break
|
||||
case 'error':
|
||||
playerState.play = false
|
||||
playerState.empty &&= false
|
||||
setLyric('')
|
||||
break
|
||||
case 'playing':
|
||||
playerState.play = true
|
||||
playerState.empty &&= false
|
||||
setLyric(global.lx.player_status.lyricLineText)
|
||||
break
|
||||
case 'stoped':
|
||||
playerState.play &&= false
|
||||
playerState.empty = true
|
||||
setLyric('')
|
||||
break
|
||||
}
|
||||
updated = true
|
||||
} else {
|
||||
setLyric(status.lyricLineText)
|
||||
}
|
||||
if (status.collect != null) {
|
||||
playerState.collect = status.collect
|
||||
|
||||
Reference in New Issue
Block a user