Skip to content

Commit

Permalink
新增 是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Jun 18, 2024
1 parent de5ea4f commit 308248d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
4 changes: 4 additions & 0 deletions publish/changeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 新增

- 新增 是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940

### 修复

- 修复 MacOS 下点击 dock 右键菜单的退出按钮时,程序没有退出的问题(#1923
Expand Down
1 change: 1 addition & 0 deletions src/common/defaultSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const defaultSetting: LX.AppSetting = {
'player.togglePlayMethod': 'listLoop',
'player.playQuality': '128k',
'player.isShowTaskProgess': true,
'player.isShowStatusBarLyric': false,
'player.volume': 1,
'player.powerSaveBlocker': true,
'player.isMute': false,
Expand Down
6 changes: 6 additions & 0 deletions src/common/types/app_setting.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ declare global {
*/
'player.isShowTaskProgess': boolean


/**
* 是否将歌词显示在状态栏
*/
'player.isShowStatusBarLyric': boolean

/**
* 音量大小
*/
Expand Down
1 change: 1 addition & 0 deletions src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
"setting__play_power_save_blocker": "Prevent computer from sleeping while playing songs",
"setting__play_save_play_time": "Remember playback progress",
"setting__play_startup_auto_play": "Play music automatically after launching the software",
"setting__play_statusbar_lyric": "Show lyrics in status bar (needs tray enabled)",
"setting__play_task_bar": "Show playing progress on the taskbar",
"setting__play_timeout": "Timed pause",
"setting__player_audio_visualization_tip": "The custom audio output device will conflict with the audio visualization function. After the audio visualization is enabled, the audio output device will be reset to the default output device. At present, this problem cannot be solved. Do you still want to enable it?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
"setting__play_power_save_blocker": "播放歌曲时阻止电脑休眠",
"setting__play_save_play_time": "记住播放进度",
"setting__play_startup_auto_play": "启动软件后自动播放音乐",
"setting__play_statusbar_lyric": "在状态栏显示歌词(需要启用托盘)",
"setting__play_task_bar": "在任务栏上显示当前歌曲播放进度",
"setting__play_timeout": "定时暂停",
"setting__player_audio_visualization_tip": "自定义音频输出设备与音频可视化功能会冲突,启用了音频可视化后音频输出设备将会被重置为默认的输出设备,目前此问题暂无法解决,是否仍要开启?",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
"setting__play_power_save_blocker": "播放歌曲時阻止電腦休眠",
"setting__play_save_play_time": "記住播放進度",
"setting__play_startup_auto_play": "啟動軟體後自動播放音樂",
"setting__play_statusbar_lyric": "在狀態列顯示歌詞(需要啟用托盤)",
"setting__play_task_bar": "在工作列上顯示目前歌曲播放進度",
"setting__play_timeout": "定時暫停",
"setting__player_audio_visualization_tip": "自訂音訊輸出設備與音訊視覺化功能會衝突,啟用了音訊視覺化後音訊輸出設備將會被重設為預設的輸出設備,目前此問題暫無法解決,是否仍要開啟?",
Expand Down
51 changes: 48 additions & 3 deletions src/main/modules/tray.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -28,6 +29,7 @@ const watchConfigKeys = [
'desktopLyric.isAlwaysOnTop',
'tray.themeId',
'tray.enable',
'player.isShowStatusBarLyric',
'common.langId',
] satisfies Array<keyof LX.AppSetting>

Expand Down Expand Up @@ -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': {
Expand All @@ -82,6 +86,8 @@ const messages = {
unlock_win_lyric: '解锁桌面歌词',
top_win_lyric: '置顶歌词',
untop_win_lyric: '取消置顶',
show_statusbar_lyric: '显示状态栏歌词',
hide_statusbar_lyric: '隐藏状态栏歌词',
exit: '退出',
},
'zh-tw': {
Expand All @@ -99,6 +105,8 @@ const messages = {
unlock_win_lyric: '解鎖桌面歌詞',
top_win_lyric: '置頂歌詞',
untop_win_lyric: '取消置頂',
show_statusbar_lyric: '顯示狀態列歌詞',
hide_statusbar_lyric: '隱藏狀態列歌詞',
exit: '退出',
},
} as const
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand All @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/views/Setting/components/SettingPlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dd
base-checkbox(id="setting_player_lyric_play_lxlrc" :model-value="appSetting['player.isPlayLxlrc']" :label="$t('setting__play_lyric_lxlrc')" @update:model-value="updateSetting({'player.isPlayLxlrc': $event})")
.gap-top
base-checkbox(id="setting_player_showTaskProgess" :model-value="appSetting['player.isShowTaskProgess']" :label="$t('setting__play_task_bar')" @update:model-value="updateSetting({'player.isShowTaskProgess': $event})")
.gap-top(v-if="isMac")
base-checkbox(id="setting_player_showStatusBarLyric" :model-value="appSetting['player.isShowStatusBarLyric']" :label="$t('setting__play_statusbar_lyric')" @update:model-value="updateSetting({'player.isShowStatusBarLyric': $event})")
.gap-top
base-checkbox(id="setting_player_isMaxOutputChannelCount" :model-value="isMaxOutputChannelCount" :label="$t('setting__play_max_output_channel_count')" @update:model-value="handleUpdateMaxOutputChannelCount")
.gap-top
Expand Down Expand Up @@ -49,6 +51,7 @@ import { appSetting, saveMediaDeviceId, updateSetting } from '@renderer/store/se
import { setPowerSaveBlocker } from '@renderer/core/player/utils'
import { isPlay } from '@renderer/store/player/state'
import { TRY_QUALITYS_LIST } from '@renderer/core/music/utils'
import { isMac } from '@common/utils'
export default {
Expand Down Expand Up @@ -140,6 +143,7 @@ export default {
isMaxOutputChannelCount,
handleUpdateMaxOutputChannelCount,
playQualityList,
isMac,
}
},
}
Expand Down

0 comments on commit 308248d

Please sign in to comment.