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

6
.gitignore vendored
View File

@ -26,3 +26,9 @@ app/git
releasenote.md
app/yarn-error.log
app/js/platform/aiscript.js
app/view/es-ES
app/view/es-FR
app/view/es-NO
app/view/es-CN
app/view/es-RU
app/view/es-TW

View File

@ -155,6 +155,8 @@ function nowplaying(mode) {
}
} else if (mode == 'itunes') {
postMessage(['itunes', ''], '*')
} else if (mode == 'anynp') {
postMessage(['itunes', 'anynp'], '*')
} else if (mode == 'lastFm') {
var user = localStorage.getItem('lastFmUser')
var start = 'https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=' + user + '&limit=1&api_key=8f113803bfea951b6dde9e56d32458b2&format=json'
@ -228,6 +230,16 @@ function nowplaying(mode) {
}
async function npCore(arg) {
console.table(arg)
if(arg.anynp) {
var flag = localStorage.getItem('artwork')
var q = arg.title
if (flag && localStorage.getItem('complete-artwork')) {
aaw = await getUnknownAA(q)
postMessage(['bmpImage', [aaw.aaw, 0]], '*')
}
$('#textarea').val(q)
return false
}
var content = localStorage.getItem('np-temp')
if (!content || content == '' || content == 'null') {
var content = '#NowPlaying {song} / {album} / {artist}\n{url}'

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.

View File

@ -90,7 +90,8 @@
"productName": "TheDesk",
"appId": "top.thedesk",
"asarUnpack": [
"node_modules/itunes-nowplaying-mac"
"node_modules/itunes-nowplaying-mac",
"main/script"
],
"directories": {
"output": "../build"