From ce778afff6eb56d7ba54b58768053b49b92111a3 Mon Sep 17 00:00:00 2001 From: Revincx Date: Wed, 5 Oct 2022 15:23:11 +0800 Subject: [PATCH 1/7] feat: Tray icon theme now follows system theme --- public/img/icons/menu-dark@88.png | Bin 0 -> 1096 bytes .../img/icons/{menu@88.png => menu-light@88.png} | Bin src/electron/tray.js | 7 +++++-- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 public/img/icons/menu-dark@88.png rename public/img/icons/{menu@88.png => menu-light@88.png} (100%) diff --git a/public/img/icons/menu-dark@88.png b/public/img/icons/menu-dark@88.png new file mode 100644 index 0000000000000000000000000000000000000000..a2feb00833cad8a136aeb2f031a7b4cd48c641ed GIT binary patch literal 1096 zcmV-O1h@N%P)6AOau)AOau)AOau(js!RoU?BqFkr$2xC?eoUfFl8*z8d$g*Jbat zJhsm6swvqTS(ZNkZtJo|+?;?DZ~{)i2{-{K-~^n26L10x6F9MOe*Nsui^!gcXxRVn ztcaZJM?~2EB_e+Y=lS046YBOLNj|&4d?+FxM1;!xEAU6zA9bS0hAawwT_DVD0@%+1 z^sR!`x(zV@b0<>AB!)Y%6tadi)HSNL1Xl$T4f5@Vl&f$xT-{ypK>OA(V0<#IC9|C} zr`#lbCL&h@kEtp784=<4&RVIEj)tn&ns?3V=p_BNRPdxFQJ1D==gZY;{RfzQv=@CpJ#py*YTUojnE4&npaj5L=Dyq5rhGjn zc~}x)g@xO=T#DN$5ip?DZ2&s!1tX;bRyBX=9)j8W=h6WyX#6vsmF!v@wE*tB4Vrb? zxQ&_stD1oe+7LbYl)vLP{22vWq~qce~ejvr+8uN|p#%n_Z|jS?gd3a%#Ucz_^2_u{#S> z@GSAA07kXEX^Bh7)*Xxi&mFM3gCxDMF<_x_sR19i3_p1|J zO-hr60Oo~3w+#V4#J9N7DJb=miTc&3B|=`1G!Hn1D43^a(xsq_OJ-h%tfDuyAm(Jx zm1CxM2_=-62X$ZFE{Vv`1|k2AIYz?zE>2jY3g?uWx<*~o#%;n0TTn7}j1E`*5F=su zrCQZY-EfJ?jVoLWXvBhQS$egznflWKXSpFFSGs|7uDrRu7;ug?k}?cH(~I8fTM=2T zQ?)eUvC8Z01h8`f-XB-#Z;zGV=;&dM0wM)a%z O0000 Date: Wed, 5 Oct 2022 16:20:04 +0800 Subject: [PATCH 2/7] feat: osdlyrics desktop lyrics support --- src/background.js | 15 +++++++++++++++ src/electron/ipcMain.js | 11 +++++++++++ src/electron/mpris.js | 2 ++ src/locale/lang/en.js | 4 ++++ src/locale/lang/zh-CN.js | 4 ++++ src/locale/lang/zh-TW.js | 4 ++++ src/store/initLocalStorage.js | 1 + src/utils/Player.js | 24 +++++++++++++++++++++-- src/views/settings.vue | 36 +++++++++++++++++++++++++++++++++++ 9 files changed, 99 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 1a98c6b..9d0b42a 100644 --- a/src/background.js +++ b/src/background.js @@ -32,6 +32,7 @@ import express from 'express'; import expressProxy from 'express-http-proxy'; import Store from 'electron-store'; import { createMpris } from '@/electron/mpris'; +import { spawn } from 'child_process'; const clc = require('cli-color'); const log = text => { console.log(`${clc.blueBright('[background.js]')} ${text}`); @@ -420,6 +421,20 @@ class Background { registerGlobalShortcut(this.window, this.store); } + // try to start osdlyrics process on start + if (this.store.get('settings.enableOsdlyricsSupport')) { + log('try to start osdlyrics process'); + const osdlyricsProcess = spawn('osdlyrics'); + + osdlyricsProcess.on('error', err => { + log(`failed to start osdlyrics: ${err.message}`); + }); + + osdlyricsProcess.on('exit', (code, signal) => { + log(`osdlyrics process exited with code ${code}, signal ${signal}`); + }); + } + // create mpris if (isCreateMpris) { createMpris(this.window); diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index 4310342..ecac0f3 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -5,6 +5,8 @@ import cloneDeep from 'lodash/cloneDeep'; import shortcuts from '@/utils/shortcuts'; import { createMenu } from './menu'; import { isCreateTray, isMac } from '@/utils/platform'; +import { resolve } from 'path'; +import { existsSync, mkdirSync, writeFileSync } from 'fs'; const clc = require('cli-color'); const log = text => { @@ -309,6 +311,15 @@ export function initIpcMain(win, store, trayEventEmitter) { registerGlobalShortcut(win, store); }); + ipcMain.on('saveLyric', (event, { name, lyric }) => { + let lyricsDirPath = resolve(process.env.HOME, '.lyrics'); + if (!existsSync(lyricsDirPath)) mkdirSync(lyricsDirPath); + if (!existsSync(resolve(lyricsDirPath, name + '.lrc'))) { + writeFileSync(resolve(lyricsDirPath, name + '.lrc'), lyric); + } + win.webContents.send('saveLyricFinished'); + }); + if (isCreateTray) { ipcMain.on('updateTrayTooltip', (_, title) => { trayEventEmitter.emit('updateTooltip', title); diff --git a/src/electron/mpris.js b/src/electron/mpris.js index 2ea5073..d1c400d 100644 --- a/src/electron/mpris.js +++ b/src/electron/mpris.js @@ -28,6 +28,8 @@ export function createMpris(window) { }); ipcMain.on('metadata', (e, metadata) => { + // 更新 Mpris 状态前将位置设为0, 否则 OSDLyrics 获取到的进度是上首音乐切换时的进度 + player.getPosition = () => 0; player.metadata = { 'mpris:trackid': player.objectPath('track/' + metadata.trackId), 'mpris:artUrl': metadata.artwork[0].src, diff --git a/src/locale/lang/en.js b/src/locale/lang/en.js index fb57890..63c006f 100644 --- a/src/locale/lang/en.js +++ b/src/locale/lang/en.js @@ -180,6 +180,10 @@ export default { exit: 'Exit', minimizeToTray: 'Minimize to tray', }, + enableOsdlyricsSupport: { + title: 'desktop lyrics support', + desc: 'Only takes effect under Linux. After enable, I will download the lyrics file to the local, and try to launch OSDLyrics at startup', + }, unm: { enable: 'Enable', audioSource: { diff --git a/src/locale/lang/zh-CN.js b/src/locale/lang/zh-CN.js index 3a01a29..ecb9fb2 100644 --- a/src/locale/lang/zh-CN.js +++ b/src/locale/lang/zh-CN.js @@ -181,6 +181,10 @@ export default { exit: '退出', minimizeToTray: '最小化到托盘', }, + enableOsdlyricsSupport: { + title: '桌面歌词支持', + desc: '仅 Linux 下生效,开启后将会下载歌词文件到本地,并会尝试在启动时拉起 OSDLyrics。', + }, unm: { enable: '启用', audioSource: { diff --git a/src/locale/lang/zh-TW.js b/src/locale/lang/zh-TW.js index 04b74f2..0a2e9ee 100644 --- a/src/locale/lang/zh-TW.js +++ b/src/locale/lang/zh-TW.js @@ -178,6 +178,10 @@ export default { exit: '退出', minimizeToTray: '最小化到工作列角落', }, + enableOsdlyricsSupport: { + title: '桌面歌詞支持', + desc: '僅 Linux 下生效,開啟後將會下載歌詞文件到本地,並會嘗試在啟動時拉起 OSDLyrics', + }, unm: { enable: '啟用', audioSource: { diff --git a/src/store/initLocalStorage.js b/src/store/initLocalStorage.js index d5b3005..ce0e802 100644 --- a/src/store/initLocalStorage.js +++ b/src/store/initLocalStorage.js @@ -23,6 +23,7 @@ let localStorage = { nyancatStyle: false, showLyricsTranslation: true, lyricsBackground: true, + enableOsdlyricsSupport: false, closeAppOption: 'ask', enableDiscordRichPresence: false, enableGlobalShortcut: true, diff --git a/src/utils/Player.js b/src/utils/Player.js index 21c90f6..668176a 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -3,7 +3,7 @@ import { getArtist } from '@/api/artist'; import { trackScrobble, trackUpdateNowPlaying } from '@/api/lastfm'; import { fmTrash, personalFM } from '@/api/others'; import { getPlaylistDetail, intelligencePlaylist } from '@/api/playlist'; -import { getMP3, getTrackDetail, scrobble } from '@/api/track'; +import { getLyric, getMP3, getTrackDetail, scrobble } from '@/api/track'; import store from '@/store'; import { isAccountLoggedIn } from '@/utils/auth'; import { cacheTrackSource, getTrackSource } from '@/utils/db'; @@ -616,9 +616,29 @@ export default class { navigator.mediaSession.metadata = new window.MediaMetadata(metadata); if (isCreateMpris) { - ipcRenderer?.send('metadata', metadata); + this._updateMprisState(track, metadata); } } + // OSDLyrics 会检测 Mpris 状态并寻找对应歌词文件,所以要在更新 Mpris 状态之前保证歌词下载完成 + async _updateMprisState(track, metadata) { + if (!store.state.settings.enableOsdlyricsSupport) { + return ipcRenderer?.send('metadata', metadata); + } + + let lyricName = track.ar.map(ar => ar.name).join(', ') + '-' + track.name; + let lyricContent = await getLyric(track.id); + + if (!lyricContent.lrc.lyric) { + return ipcRenderer?.send('metadata', metadata); + } + ipcRenderer.send('saveLyric', { + name: lyricName, + lyric: lyricContent.lrc.lyric, + }); + ipcRenderer.on('saveLyricFinished', () => { + ipcRenderer?.send('metadata', metadata); + }); + } _updateMediaSessionPositionState() { if ('mediaSession' in navigator === false) { return; diff --git a/src/views/settings.vue b/src/views/settings.vue index c25d441..c40fe54 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -239,6 +239,31 @@ +
+
+
+ {{ $t('settings.unm.enable') }} + OSDLyrics + {{ $t('settings.enableOsdlyricsSupport.title') }} +
+
+ {{ $t('settings.enableOsdlyricsSupport.desc') }} +
+
+
+
+ + +
+
+

UnblockNeteaseMusic

@@ -963,6 +988,17 @@ export default { }); }, }, + enableOsdlyricsSupport: { + get() { + return this.settings.enableOsdlyricsSupport; + }, + set(value) { + this.$store.commit('updateSettings', { + key: 'enableOsdlyricsSupport', + value, + }); + }, + }, closeAppOption: { get() { return this.settings.closeAppOption; From 345f3588bd192b0e0f6e96f630a4481134fe6919 Mon Sep 17 00:00:00 2001 From: Revincx Date: Sat, 22 Oct 2022 12:36:57 +0800 Subject: [PATCH 3/7] chore: improve translations --- src/locale/lang/en.js | 4 ++-- src/locale/lang/zh-CN.js | 4 ++-- src/locale/lang/zh-TW.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/locale/lang/en.js b/src/locale/lang/en.js index 63c006f..55b8871 100644 --- a/src/locale/lang/en.js +++ b/src/locale/lang/en.js @@ -181,8 +181,8 @@ export default { minimizeToTray: 'Minimize to tray', }, enableOsdlyricsSupport: { - title: 'desktop lyrics support', - desc: 'Only takes effect under Linux. After enable, I will download the lyrics file to the local, and try to launch OSDLyrics at startup', + title: '"Desktop Lyrics" support', + desc: 'Only takes effect under Linux. After enabled, it downloads the lyrics file to the local, and tries to launch OSDLyrics at startup.', }, unm: { enable: 'Enable', diff --git a/src/locale/lang/zh-CN.js b/src/locale/lang/zh-CN.js index ecb9fb2..7966a2e 100644 --- a/src/locale/lang/zh-CN.js +++ b/src/locale/lang/zh-CN.js @@ -182,8 +182,8 @@ export default { minimizeToTray: '最小化到托盘', }, enableOsdlyricsSupport: { - title: '桌面歌词支持', - desc: '仅 Linux 下生效,开启后将会下载歌词文件到本地,并会尝试在启动时拉起 OSDLyrics。', + title: '启用「桌面歌词」支持', + desc: '仅 Linux 下生效。启用后会将歌词文件下载到本地,并在开启播放器时尝试拉起 OSDLyrics。', }, unm: { enable: '启用', diff --git a/src/locale/lang/zh-TW.js b/src/locale/lang/zh-TW.js index 0a2e9ee..9ed415b 100644 --- a/src/locale/lang/zh-TW.js +++ b/src/locale/lang/zh-TW.js @@ -179,8 +179,8 @@ export default { minimizeToTray: '最小化到工作列角落', }, enableOsdlyricsSupport: { - title: '桌面歌詞支持', - desc: '僅 Linux 下生效,開啟後將會下載歌詞文件到本地,並會嘗試在啟動時拉起 OSDLyrics', + title: '啟用「桌面歌詞」支援', + desc: '只在 Linux 環境下生效。啟用後會將歌詞檔案下載至本機位置,並在開啟播放器時嘗試連帶啟動 OSDLyrics。', }, unm: { enable: '啟用', From 41b72563ffb70b2814571284255fd8dd41db2a85 Mon Sep 17 00:00:00 2001 From: Revincx Date: Sat, 22 Oct 2022 13:59:49 +0800 Subject: [PATCH 4/7] refactor: improve lyric file download implement --- src/electron/ipcMain.js | 50 +++++++++++++++++++++++++++++++++------- src/locale/lang/en.js | 2 +- src/locale/lang/zh-CN.js | 2 +- src/locale/lang/zh-TW.js | 2 +- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index ecac0f3..d2df371 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -6,7 +6,7 @@ import shortcuts from '@/utils/shortcuts'; import { createMenu } from './menu'; import { isCreateTray, isMac } from '@/utils/platform'; import { resolve } from 'path'; -import { existsSync, mkdirSync, writeFileSync } from 'fs'; +import { mkdir, rm, writeFile } from 'fs/promises'; const clc = require('cli-color'); const log = text => { @@ -135,6 +135,43 @@ function parseSourceStringToList(executor, sourceString) { }); } +/** + * Write lyrics into local file + * + * @param {string} name + * @param {string} content + */ +async function writeLyric(name, content) { + name = name.replaceAll('/', '⁄'); + + const lyricsDir = resolve(process.env.HOME, '.lyrics'); + const destination = resolve(lyricsDir, name + '.lrc'); + + try { + await writeFile(destination, content); + } catch (e) { + switch (e.code) { + // ENOENT (no such file or directory), + case 'ENOENT': + await mkdir(lyricsDir, { recursive: true }); + + // Try again. Should be succeed. + return await writeLyric(name, content); + // ENOTDIR (not a directory), 指 TMPDIR 有問題。 + case 'ENOTDIR': + // 砍掉 TMPDIR「檔案」。 + await rm(lyricsDir); + + // 預期接下來的流程是 ENOENT 建立資料夾的流程。 + return await writeLyric(name, content); + default: + log(e); + break; + } + log(e); + } +} + export function initIpcMain(win, store, trayEventEmitter) { // WIP: Do not enable logging as it has some issues in non-blocking I/O environment. // UNM.enableLogging(UNM.LoggingType.ConsoleEnv); @@ -311,13 +348,10 @@ export function initIpcMain(win, store, trayEventEmitter) { registerGlobalShortcut(win, store); }); - ipcMain.on('saveLyric', (event, { name, lyric }) => { - let lyricsDirPath = resolve(process.env.HOME, '.lyrics'); - if (!existsSync(lyricsDirPath)) mkdirSync(lyricsDirPath); - if (!existsSync(resolve(lyricsDirPath, name + '.lrc'))) { - writeFileSync(resolve(lyricsDirPath, name + '.lrc'), lyric); - } - win.webContents.send('saveLyricFinished'); + ipcMain.on('saveLyric', async (_, { name, lyric }) => { + await writeLyric(name, lyric); + + return win.webContents.send('saveLyricFinished'); }); if (isCreateTray) { diff --git a/src/locale/lang/en.js b/src/locale/lang/en.js index 55b8871..b589836 100644 --- a/src/locale/lang/en.js +++ b/src/locale/lang/en.js @@ -181,7 +181,7 @@ export default { minimizeToTray: 'Minimize to tray', }, enableOsdlyricsSupport: { - title: '"Desktop Lyrics" support', + title: 'desktop lyrics support', desc: 'Only takes effect under Linux. After enabled, it downloads the lyrics file to the local, and tries to launch OSDLyrics at startup.', }, unm: { diff --git a/src/locale/lang/zh-CN.js b/src/locale/lang/zh-CN.js index 7966a2e..bb55070 100644 --- a/src/locale/lang/zh-CN.js +++ b/src/locale/lang/zh-CN.js @@ -182,7 +182,7 @@ export default { minimizeToTray: '最小化到托盘', }, enableOsdlyricsSupport: { - title: '启用「桌面歌词」支持', + title: '桌面歌词支持', desc: '仅 Linux 下生效。启用后会将歌词文件下载到本地,并在开启播放器时尝试拉起 OSDLyrics。', }, unm: { diff --git a/src/locale/lang/zh-TW.js b/src/locale/lang/zh-TW.js index 9ed415b..dcb1c21 100644 --- a/src/locale/lang/zh-TW.js +++ b/src/locale/lang/zh-TW.js @@ -179,7 +179,7 @@ export default { minimizeToTray: '最小化到工作列角落', }, enableOsdlyricsSupport: { - title: '啟用「桌面歌詞」支援', + title: '桌面歌詞支援', desc: '只在 Linux 環境下生效。啟用後會將歌詞檔案下載至本機位置,並在開啟播放器時嘗試連帶啟動 OSDLyrics。', }, unm: { From ed1daab1f624d23ae5fe98ef483c805eecc0f646 Mon Sep 17 00:00:00 2001 From: Revincx Date: Sat, 26 Aug 2023 08:53:32 +0800 Subject: [PATCH 5/7] feat: use osdlyrics dbus interface to send lyric contents --- src/background.js | 3 ++- src/electron/ipcMain.js | 45 ---------------------------------------- src/electron/mpris.js | 24 +++++++++++++++++++++ src/locale/lang/en.js | 5 ++++- src/locale/lang/zh-CN.js | 4 +++- src/locale/lang/zh-TW.js | 4 +++- src/utils/Player.js | 11 +++++----- src/views/settings.vue | 4 +++- 8 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/background.js b/src/background.js index 3404ef8..94dbbc0 100644 --- a/src/background.js +++ b/src/background.js @@ -31,7 +31,7 @@ import { EventEmitter } from 'events'; import express from 'express'; import expressProxy from 'express-http-proxy'; import Store from 'electron-store'; -import { createMpris } from '@/electron/mpris'; +import { createMpris, createDbus } from '@/electron/mpris'; import { spawn } from 'child_process'; const clc = require('cli-color'); const log = text => { @@ -423,6 +423,7 @@ class Background { // try to start osdlyrics process on start if (this.store.get('settings.enableOsdlyricsSupport')) { + await createDbus(this.window); log('try to start osdlyrics process'); const osdlyricsProcess = spawn('osdlyrics'); diff --git a/src/electron/ipcMain.js b/src/electron/ipcMain.js index d2df371..4310342 100644 --- a/src/electron/ipcMain.js +++ b/src/electron/ipcMain.js @@ -5,8 +5,6 @@ import cloneDeep from 'lodash/cloneDeep'; import shortcuts from '@/utils/shortcuts'; import { createMenu } from './menu'; import { isCreateTray, isMac } from '@/utils/platform'; -import { resolve } from 'path'; -import { mkdir, rm, writeFile } from 'fs/promises'; const clc = require('cli-color'); const log = text => { @@ -135,43 +133,6 @@ function parseSourceStringToList(executor, sourceString) { }); } -/** - * Write lyrics into local file - * - * @param {string} name - * @param {string} content - */ -async function writeLyric(name, content) { - name = name.replaceAll('/', '⁄'); - - const lyricsDir = resolve(process.env.HOME, '.lyrics'); - const destination = resolve(lyricsDir, name + '.lrc'); - - try { - await writeFile(destination, content); - } catch (e) { - switch (e.code) { - // ENOENT (no such file or directory), - case 'ENOENT': - await mkdir(lyricsDir, { recursive: true }); - - // Try again. Should be succeed. - return await writeLyric(name, content); - // ENOTDIR (not a directory), 指 TMPDIR 有問題。 - case 'ENOTDIR': - // 砍掉 TMPDIR「檔案」。 - await rm(lyricsDir); - - // 預期接下來的流程是 ENOENT 建立資料夾的流程。 - return await writeLyric(name, content); - default: - log(e); - break; - } - log(e); - } -} - export function initIpcMain(win, store, trayEventEmitter) { // WIP: Do not enable logging as it has some issues in non-blocking I/O environment. // UNM.enableLogging(UNM.LoggingType.ConsoleEnv); @@ -348,12 +309,6 @@ export function initIpcMain(win, store, trayEventEmitter) { registerGlobalShortcut(win, store); }); - ipcMain.on('saveLyric', async (_, { name, lyric }) => { - await writeLyric(name, lyric); - - return win.webContents.send('saveLyricFinished'); - }); - if (isCreateTray) { ipcMain.on('updateTrayTooltip', (_, title) => { trayEventEmitter.emit('updateTooltip', title); diff --git a/src/electron/mpris.js b/src/electron/mpris.js index d0c7a1c..92b74a6 100644 --- a/src/electron/mpris.js +++ b/src/electron/mpris.js @@ -1,3 +1,4 @@ +import dbus from 'dbus-next'; import { ipcMain, app } from 'electron'; export function createMpris(window) { @@ -63,3 +64,26 @@ export function createMpris(window) { player.shuffle = shuffle; }); } + +export async function createDbus(window) { + const bus = dbus.sessionBus(); + const Variant = dbus.Variant; + + const osdService = await bus.getProxyObject( + 'org.osdlyrics.Daemon', + '/org/osdlyrics/Lyrics' + ); + + const osdInterface = osdService.getInterface('org.osdlyrics.Lyrics'); + + ipcMain.on('sendLyrics', async (e, { track, lyrics }) => { + const metadata = { + title: new Variant('s', track.name), + artist: new Variant('s', track.ar.map(ar => ar.name).join(', ')), + }; + + await osdInterface.SetLyricContent(metadata, Buffer.from(lyrics)); + + window.webContents.send('saveLyricFinished'); + }); +} diff --git a/src/locale/lang/en.js b/src/locale/lang/en.js index d5a19c7..6728b8a 100644 --- a/src/locale/lang/en.js +++ b/src/locale/lang/en.js @@ -195,7 +195,10 @@ export default { }, enableOsdlyricsSupport: { title: 'desktop lyrics support', - desc: 'Only takes effect under Linux. After enabled, it downloads the lyrics file to the local, and tries to launch OSDLyrics at startup.', + desc1: + 'Only takes effect under Linux. After enabled, it downloads the lyrics file to the local, and tries to launch OSDLyrics at startup.', + desc2: + 'Please ensure that you have installed OSDLyrics before turning on this.', }, unm: { enable: 'Enable', diff --git a/src/locale/lang/zh-CN.js b/src/locale/lang/zh-CN.js index d34112a..9fbcafc 100644 --- a/src/locale/lang/zh-CN.js +++ b/src/locale/lang/zh-CN.js @@ -196,7 +196,9 @@ export default { }, enableOsdlyricsSupport: { title: '桌面歌词支持', - desc: '仅 Linux 下生效。启用后会将歌词文件下载到本地,并在开启播放器时尝试拉起 OSDLyrics。', + desc1: + '仅 Linux 下生效。启用后会将歌词文件下载到本地,并在开启播放器时尝试拉起 OSDLyrics。', + desc2: '请在开启之前确保您已经正确安装了 OSDLyrics。', }, unm: { enable: '启用', diff --git a/src/locale/lang/zh-TW.js b/src/locale/lang/zh-TW.js index 35a7a6c..0882921 100644 --- a/src/locale/lang/zh-TW.js +++ b/src/locale/lang/zh-TW.js @@ -193,7 +193,9 @@ export default { }, enableOsdlyricsSupport: { title: '桌面歌詞支援', - desc: '只在 Linux 環境下生效。啟用後會將歌詞檔案下載至本機位置,並在開啟播放器時嘗試連帶啟動 OSDLyrics。', + desc1: + '只在 Linux 環境下生效。啟用後會將歌詞檔案下載至本機位置,並在開啟播放器時嘗試連帶啟動 OSDLyrics。', + desc2: '請在開啟之前確保您已經正確安裝了 OSDLyrics。', }, unm: { enable: '啟用', diff --git a/src/utils/Player.js b/src/utils/Player.js index 05df629..38c9aa1 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -629,16 +629,17 @@ export default class { return ipcRenderer?.send('metadata', metadata); } - let lyricName = track.ar.map(ar => ar.name).join(', ') + '-' + track.name; let lyricContent = await getLyric(track.id); - if (!lyricContent.lrc.lyric) { + if (!lyricContent.lrc || !lyricContent.lrc.lyric) { return ipcRenderer?.send('metadata', metadata); } - ipcRenderer.send('saveLyric', { - name: lyricName, - lyric: lyricContent.lrc.lyric, + + ipcRenderer.send('sendLyrics', { + track, + lyrics: lyricContent.lrc.lyric, }); + ipcRenderer.on('saveLyricFinished', () => { ipcRenderer?.send('metadata', metadata); }); diff --git a/src/views/settings.vue b/src/views/settings.vue index 949bed0..a381316 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -261,7 +261,9 @@ {{ $t('settings.enableOsdlyricsSupport.title') }}
- {{ $t('settings.enableOsdlyricsSupport.desc') }} + {{ $t('settings.enableOsdlyricsSupport.desc1') }} +
+ {{ $t('settings.enableOsdlyricsSupport.desc2') }}
From 6ad756b215c331e8c5a992519bc66141ad4f7390 Mon Sep 17 00:00:00 2001 From: Revincx Date: Sat, 26 Aug 2023 08:55:46 +0800 Subject: [PATCH 6/7] fix(ui): add max-width attr for settings selector --- src/views/settings.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/settings.vue b/src/views/settings.vue index a381316..82ad74c 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -1515,6 +1515,7 @@ h3 { select { min-width: 192px; + max-width: 600px; font-weight: 600; border: none; padding: 8px 12px 8px 12px; From 486b04b70b973c9eafb30fcd76be76d11df4d9c0 Mon Sep 17 00:00:00 2001 From: Revincx Date: Sat, 26 Aug 2023 09:03:36 +0800 Subject: [PATCH 7/7] feat(player): sync playing progress to mpris service on linux Co-authored-by: alex3236 <45303195+alex3236@users.noreply.github.com> --- src/electron/mpris.js | 5 +++++ src/utils/Player.js | 10 ++++++++-- src/views/lyrics.vue | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/electron/mpris.js b/src/electron/mpris.js index 92b74a6..c6cfeee 100644 --- a/src/electron/mpris.js +++ b/src/electron/mpris.js @@ -44,6 +44,11 @@ export function createMpris(window) { ipcMain.on('playerCurrentTrackTime', (e, position) => { player.getPosition = () => position * 1000 * 1000; + player.seeked(position * 1000 * 1000); + }); + + ipcMain.on('seeked', (e, position) => { + player.seeked(position * 1000 * 1000); }); ipcMain.on('switchRepeatMode', (e, mode) => { diff --git a/src/utils/Player.js b/src/utils/Player.js index 38c9aa1..db9b8d2 100644 --- a/src/utils/Player.js +++ b/src/utils/Player.js @@ -199,6 +199,9 @@ export default class { set progress(value) { if (this._howler) { this._howler.seek(value); + if (isCreateMpris) { + ipcRenderer?.send('seeked', this._howler.seek()); + } } } get isCurrentTrackLiked() { @@ -836,11 +839,14 @@ export default class { this.play(); } } - seek(time = null) { + seek(time = null, sendMpris = true) { + if (isCreateMpris && sendMpris && time) { + ipcRenderer?.send('seeked', time); + } if (time !== null) { this._howler?.seek(time); if (this._playing) - this._playDiscordPresence(this._currentTrack, this.seek()); + this._playDiscordPresence(this._currentTrack, this.seek(null, false)); } return this._howler === null ? 0 : this._howler.seek(); } diff --git a/src/views/lyrics.vue b/src/views/lyrics.vue index 40acc7f..a46695c 100644 --- a/src/views/lyrics.vue +++ b/src/views/lyrics.vue @@ -566,7 +566,7 @@ export default { }, setLyricsInterval() { this.lyricsInterval = setInterval(() => { - const progress = this.player.seek() ?? 0; + const progress = this.player.seek(null, false) ?? 0; let oldHighlightLyricIndex = this.highlightLyricIndex; this.highlightLyricIndex = this.lyric.findIndex((l, index) => { const nextLyric = this.lyric[index + 1];