feat: use osdlyrics dbus interface to send lyric contents

This commit is contained in:
Revincx 2023-08-26 08:53:32 +08:00
parent 845bc8a921
commit ed1daab1f6
No known key found for this signature in database
GPG key ID: 6E79B88F79CA3126
8 changed files with 45 additions and 55 deletions

View file

@ -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');
});
}