From d939914ea7c1851be7948ea10cf68200c60ed22f Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 4 Aug 2022 00:39:23 +0100 Subject: [PATCH] windows can have their artwork --- src/main/plugins/playbackNotifications.ts | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/plugins/playbackNotifications.ts b/src/main/plugins/playbackNotifications.ts index 5dbf750d..9f849f02 100644 --- a/src/main/plugins/playbackNotifications.ts +++ b/src/main/plugins/playbackNotifications.ts @@ -1,6 +1,8 @@ import fetch from "electron-fetch"; -import {nativeImage, Notification} from "electron"; +import {app, nativeImage, Notification} from "electron"; import NativeImage = Electron.NativeImage; +import {createWriteStream} from "fs"; +import {join} from "path"; export default class playbackNotifications { @@ -44,7 +46,8 @@ export default class playbackNotifications { ` }); - // image implementation in windows toasts - //img - this._notification.on('click', (_: any) => { this._utils.getWindow().show() this._utils.getWindow().focus() @@ -99,11 +99,20 @@ export default class playbackNotifications { if (this._artworkImage[a.artwork.url]) { this.createNotification(a); } else { - fetch(a.artwork.url).then(async blob => { - this._artworkImage[a.artwork.url] = nativeImage.createFromBuffer(Buffer.from(await blob.arrayBuffer())); - this._artworkNums[this._artworkNums.length] = a.artwork.url; - this.createNotification(a); - }); + if (process.platform === "win32") { + fetch(a.artwork.url) + .then(res => { + const dest = createWriteStream(join(app.getPath("temp"), `${a.songId}-${a.artwork.url.split('/').pop()}`)); + // @ts-ignore + res.body.pipe(dest) + }) + } else { + fetch(a.artwork.url).then(async blob => { + this._artworkImage[a.artwork.url] = nativeImage.createFromBuffer(Buffer.from(await blob.arrayBuffer())); + this._artworkNums[this._artworkNums.length] = a.artwork.url; + this.createNotification(a); + }); + } } }) }