Add macOS control center nowplaying
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
BIN
app/main/script/macOSNP.applescript
Normal file
BIN
app/main/script/macOSNP.applescript
Normal file
Binary file not shown.
BIN
app/main/script/macOSNP.scpt
Normal file
BIN
app/main/script/macOSNP.scpt
Normal file
Binary file not shown.
Reference in New Issue
Block a user