thedesk/app/main/np.js

46 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2021-01-16 06:28:09 +11:00
const { execSync } = require('child_process')
const { join } = require('path')
2019-05-19 17:39:30 +10:00
function np(mainWindow) {
2021-01-16 06:28:09 +11:00
var platform = process.platform
if (platform !== 'darwin') return false
2020-01-12 03:23:07 +11:00
const electron = require('electron')
const ipc = electron.ipcMain
ipc.on('itunes', async (e, args) => {
console.log('Access')
2021-01-16 06:28:09 +11:00
if (args == 'anynp') {
const dir = join(__dirname, "..", "main", "script", "macOSNP.scpt").replace("app.asar","app.asar.unpacked")
const stdout = execSync(`osascript ${dir}`).toString()
const title = stdout.substring(0, stdout.length - 100).match(/"(.+)?"/)[1].replace('\"','"')
const ret = {
title: title,
anynp: true
}
e.sender.send('itunes-np', ret)
2020-01-12 03:23:07 +11:00
} else {
2021-01-16 06:28:09 +11:00
2020-01-12 03:23:07 +11:00
try {
const nowplaying = require('itunes-nowplaying-mac')
let value = await nowplaying()
2020-01-23 02:51:50 +11:00
try {
const artwork = await nowplaying.getThumbnailBuffer(value.databaseID)
if(artwork) {
const base64 = artwork.toString('base64')
value.artwork = base64
e.sender.send('itunes-np', value)
2020-01-23 02:51:50 +11:00
}
} catch (error) {
2020-01-23 02:53:35 +11:00
console.error(error)
e.sender.send('itunes-np', value)
2020-01-23 02:49:36 +11:00
}
2020-01-23 02:51:50 +11:00
2020-01-12 03:23:07 +11:00
} catch (error) {
2020-01-23 02:53:35 +11:00
console.error(error)
e.sender.send('itunes-np', error)
2020-01-12 03:23:07 +11:00
}
}
2020-01-13 00:49:52 +11:00
})
2019-04-03 14:59:29 +11:00
}
2020-01-12 03:23:07 +11:00
exports.TheDeskNowPlaying = np