export async function uploadFavicon () { let favicon = dialog.showOpenDialog({ title: 'Upload Favicon...', defaultPath: app.getPath('home'), buttonLabel: 'Upload Favicon', filters: [ { name: 'Images', extensions: ['png', 'ico', 'jpg'] } ], properties: ['openFile'] }) if (!favicon) return let faviconBuffer = await jetpack.readAsync(favicon[0], 'buffer') let extension = path.extname(favicon[0]) if (extension === '.png') { return toIco(faviconBuffer, {resize: true}) } if (extension === '.jpg') { let imageToPng = nativeImage.createFromBuffer(faviconBuffer).toPNG() return toIco(imageToPng, {resize: true}) } if (extension === '.ico' && ICO.isICO(faviconBuffer)) { return faviconBuffer } }
.then((result) => { const imageFilepathDownloaded = result.filename const imageBuffer = result.image const imageType = fileType(imageBuffer) const isIco = icojs.isICO(imageBuffer) const isPng = imageType.mime === 'image/png' const isJpeg = imageType.mime === 'image/jpg' || imageType.mime === 'image/jpeg' // From .PNG if (isPng || isJpeg) { resizeWriteImage(imageBuffer, imageFilepathDownloaded, notificationsIconWidth, (error, imageFilepathConverted) => { if (error) { return } notificationOptions.icon = imageFilepathConverted showNotification(notificationOptions, decoratedPush) }) return } // From .ICO if (isIco) { icojs.parse(imageBuffer, 'image/png').then(imageList => { const imageMaximum = imageList[imageList.length - 1] resizeWriteImage(Buffer.from(imageMaximum.buffer), imageFilepathDownloaded, notificationsIconWidth, (error, imageFilepathConverted) => { if (error) { return } notificationOptions.icon = imageFilepathConverted showNotification(notificationOptions, decoratedPush) }) }) } })