Add macOS control center nowplaying

This commit is contained in:
cutls
2021-01-16 04:28:09 +09:00
parent 8c2d17d096
commit 57ca23e4e5
6 changed files with 35 additions and 7 deletions

View File

@@ -1,13 +1,24 @@
const { execSync } = require('child_process')
const { join } = require('path')
function np(mainWindow) {
var platform = process.platform
if (platform !== 'darwin') return false
const electron = require('electron')
const ipc = electron.ipcMain
ipc.on('itunes', async (e, args) => {
console.log('Access')
if (args[0] == 'set') {
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.webContents.send('itunes-np', ret)
} else {
var platform = process.platform
var bit = process.arch
if (platform == 'darwin') {
try {
const nowplaying = require('itunes-nowplaying-mac')
let value = await nowplaying()
@@ -27,8 +38,6 @@ function np(mainWindow) {
console.error(error)
e.sender.webContents.send('itunes-np', error)
}
} else {
}
}
})

Binary file not shown.

Binary file not shown.