linux is cooollll

This commit is contained in:
Core 2022-07-13 15:08:54 +01:00
parent c219758207
commit 2a9a5c68ff
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
3 changed files with 8 additions and 15 deletions

View file

@ -76,10 +76,6 @@ ipcMain.on("nowPlayingItemDidChange", (_event, attributes) => {
CiderPlug.callPlugins("onNowPlayingItemDidChange", attributes); CiderPlug.callPlugins("onNowPlayingItemDidChange", attributes);
}); });
ipcMain.on("updatePlaybackProgress", (_event, attributes) => {
CiderPlug.callPlugins("updatePlaybackProgress", attributes);
})
app.on("before-quit", () => { app.on("before-quit", () => {
CiderPlug.callPlugins("onBeforeQuit"); CiderPlug.callPlugins("onBeforeQuit");
console.warn(`${app.getName()} exited.`); console.warn(`${app.getName()} exited.`);

View file

@ -10,8 +10,6 @@ export default class mpris {
* MPRIS Service * MPRIS Service
*/ */
private static player: Player.Player; private static player: Player.Player;
private static globalAttributes: any = {}
/** /**
* Base Plugin Details (Eventually implemented into a GUI in settings) * Base Plugin Details (Eventually implemented into a GUI in settings)
*/ */
@ -76,6 +74,10 @@ export default class mpris {
player.on('loopStatus', (status: string) => renderer.executeJavaScript(`app.mk.repeatMode = ${loopType[status.toLowerCase()]}`)) player.on('loopStatus', (status: string) => renderer.executeJavaScript(`app.mk.repeatMode = ${loopType[status.toLowerCase()]}`))
player.on('shuffle', () => renderer.executeJavaScript('app.mk.shuffleMode = (app.mk.shuffleMode === 0) ? 1 : 0')) player.on('shuffle', () => renderer.executeJavaScript('app.mk.shuffleMode = (app.mk.shuffleMode === 0) ? 1 : 0'))
mpris.utils.getIPCMain().on('mpris:playbackTimeDidChange', (event: any, time: number) => {
player.getPosition = () => time;
})
mpris.utils.getIPCMain().on('repeatModeDidChange', (_e: any, mode: number) => { mpris.utils.getIPCMain().on('repeatModeDidChange', (_e: any, mode: number) => {
switch (mode) { switch (mode) {
case 0: case 0:
@ -160,7 +162,6 @@ export default class mpris {
*/ */
@mpris.linuxOnly @mpris.linuxOnly
onPlaybackStateDidChange(attributes: any): void { onPlaybackStateDidChange(attributes: any): void {
mpris.globalAttributes = attributes
mpris.player.playbackStatus = attributes?.status ? Player.PLAYBACK_STATUS_PLAYING : Player.PLAYBACK_STATUS_PAUSED mpris.player.playbackStatus = attributes?.status ? Player.PLAYBACK_STATUS_PLAYING : Player.PLAYBACK_STATUS_PAUSED
} }
@ -170,14 +171,7 @@ export default class mpris {
*/ */
@mpris.linuxOnly @mpris.linuxOnly
onNowPlayingItemDidChange(attributes: object): void { onNowPlayingItemDidChange(attributes: object): void {
mpris.globalAttributes = attributes
mpris.updateMetaData(attributes); mpris.updateMetaData(attributes);
} }
@mpris.linuxOnly
updatePlaybackProgress(attributes: any): void {
mpris.globalAttributes = attributes
mpris.player.getPosition = () => attributes.currentPlaybackTime * 1000 * 1000;
}
} }

View file

@ -17,10 +17,13 @@ const MusicKitInterop = {
/** wsapi */ /** wsapi */
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackProgressDidChange, () => { MusicKit.getInstance().addEventListener(MusicKit.Events.playbackProgressDidChange, () => {
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes()); ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes());
ipcRenderer.send('updatePlaybackProgress', MusicKitInterop.getAttributes());
}); });
/** wsapi */ /** wsapi */
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackTimeDidChange, () => {
ipcRenderer.send('mpris:playbackTimeDidChange', (MusicKit.getInstance()?.currentPlaybackTime * 1000 * 1000 ) ?? 0);
})
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => { MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
console.debug('[cider:preload] nowPlayingItemDidChange') console.debug('[cider:preload] nowPlayingItemDidChange')
const attributes = MusicKitInterop.getAttributes() const attributes = MusicKitInterop.getAttributes()