thedesk/app/main/np.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-05-19 17:39:30 +10:00
function np(mainWindow) {
2020-01-12 03:23:07 +11:00
const electron = require('electron')
const join = require('path').join
const app = electron.app
2020-01-12 13:38:28 +11:00
const fs = require('fs')
const fpath = join(app.getPath('userData'), 'npexec')
2020-01-12 03:23:07 +11:00
const ipc = electron.ipcMain
const { exec } = require('child_process')
ipc.on('itunes', async (e, args) => {
console.log('Access')
if (args[0] == 'set') {
} else {
var platform = process.platform
var bit = process.arch
if (platform == 'darwin') {
try {
const nowplaying = require('itunes-nowplaying-mac')
let value = await nowplaying()
2020-01-12 13:38:28 +11:00
if (!value && npExec) {
const artwork = await nowplaying.getThumbnailBuffer(value.databaseID)
const base64 = artwork.toString('base64')
value.artwork = base64
e.sender.webContents.send('itunes-np', value)
}
2020-01-12 03:23:07 +11:00
} catch (error) {
// エラーを返す
console.error(error)
2020-01-12 13:38:28 +11:00
try {
const npExec = fs.readFileSync(fpath, 'utf8')
exec(npExec, (error, stdout, stderr) => {
e.sender.webContents.send('itunes-np', { raw: true, data: stdout })
})
} catch (e) {}
2020-01-12 03:23:07 +11:00
}
} else {
}
}
2020-01-12 13:38:28 +11:00
})
2019-04-03 14:59:29 +11:00
}
2020-01-12 03:23:07 +11:00
exports.TheDeskNowPlaying = np