Compare commits
1 Commits
9dcf3c237a
...
macos
| Author | SHA1 | Date | |
|---|---|---|---|
| 0961746560 |
17
MediaControl.scpt
Normal file
17
MediaControl.scpt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
on run argv
|
||||||
|
set var to item 1 of argv
|
||||||
|
|
||||||
|
if var is "playpause" then
|
||||||
|
using terms from application "Spotify"
|
||||||
|
tell application "Spotify" to playpause
|
||||||
|
end using terms from
|
||||||
|
else if var is "next" then
|
||||||
|
using terms from application "Spotify"
|
||||||
|
tell application "Spotify" to next track
|
||||||
|
end using terms from
|
||||||
|
else if var is "previous" then
|
||||||
|
using terms from application "Spotify"
|
||||||
|
tell application "Spotify" to previous track
|
||||||
|
end using terms from
|
||||||
|
end if
|
||||||
|
end run
|
||||||
22
get-media.sh
Executable file
22
get-media.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Get the currently playing Spotify track title
|
||||||
|
process_info=$(osascript -e 'tell application "Spotify" to if player state is playing then name of current track & " - " & artist of current track')
|
||||||
|
|
||||||
|
if [[ -n "$process_info" ]]; then
|
||||||
|
if [[ "$process_info" =~ ^(.*)\ -\ (.*)$ ]]; then
|
||||||
|
artist="${BASH_REMATCH[2]}"
|
||||||
|
songTitle="${BASH_REMATCH[1]}"
|
||||||
|
else
|
||||||
|
artist="Unknown"
|
||||||
|
songTitle="$process_info"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
artist=""
|
||||||
|
songTitle=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create JSON output
|
||||||
|
json_output=$(jq -n --arg title "$songTitle" --arg artist "$artist" --arg amUri "" '{title: $title, artist: $artist, amUri: $amUri}')
|
||||||
|
|
||||||
|
echo "$json_output"
|
||||||
20
main.js
20
main.js
@@ -7,6 +7,18 @@ let win;
|
|||||||
let lastSong = "";
|
let lastSong = "";
|
||||||
let lastPaused = true;
|
let lastPaused = true;
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
getMediaCommand = 'powershell -ExecutionPolicy Bypass -File get-media.ps1';
|
||||||
|
mediaControlCommand = 'MediaControl.exe';
|
||||||
|
} else if (process.platform === 'darwin') {
|
||||||
|
getMediaCommand = './get-media.sh'; // Adjust this path/command to your macOS script
|
||||||
|
mediaControlCommand = 'osascript MediaControl.scpt';
|
||||||
|
} else {
|
||||||
|
console.error("Unsupported OS");
|
||||||
|
resolve({ updated: false });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
createWindow();
|
createWindow();
|
||||||
checkNowPlaying();
|
checkNowPlaying();
|
||||||
@@ -52,7 +64,7 @@ async function checkNowPlaying() {
|
|||||||
|
|
||||||
function checkOwnSong() {
|
function checkOwnSong() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
exec(`powershell -ExecutionPolicy Bypass -File get-media.ps1`, async (error, stdout) => {
|
exec(getMediaCommand, async (error, stdout) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("PowerShell error:", error);
|
console.error("PowerShell error:", error);
|
||||||
resolve({ updated: false });
|
resolve({ updated: false });
|
||||||
@@ -139,7 +151,7 @@ function fetchAlbumArt(title, artist) {
|
|||||||
|
|
||||||
ipcMain.on('media-control', (event, command) => {
|
ipcMain.on('media-control', (event, command) => {
|
||||||
if (command) {
|
if (command) {
|
||||||
exec(`MediaControl.exe ${command}`, (error, stdout, stderr) => {
|
exec(`${mediaControlCommand} ${command}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Error running MediaControl.exe:`, error);
|
console.error(`Error running MediaControl.exe:`, error);
|
||||||
} else {
|
} else {
|
||||||
@@ -398,10 +410,10 @@ function getMainPageHTML() {
|
|||||||
|
|
||||||
if (data.paused) {
|
if (data.paused) {
|
||||||
// Player is paused => show "Play" button
|
// Player is paused => show "Play" button
|
||||||
playPauseButton.textContent = "▶️";
|
playPauseButton.textContent = "⏵︎";
|
||||||
} else {
|
} else {
|
||||||
// Player is playing => show "Pause" button and update track info
|
// Player is playing => show "Pause" button and update track info
|
||||||
playPauseButton.textContent = "⏸️";
|
playPauseButton.textContent = "⏸︎";
|
||||||
|
|
||||||
songTitleElem.innerText = data.title ?? "Unknown Title";
|
songTitleElem.innerText = data.title ?? "Unknown Title";
|
||||||
songArtistElem.innerText = data.artist ?? "Unknown Artist";
|
songArtistElem.innerText = data.artist ?? "Unknown Artist";
|
||||||
|
|||||||
Reference in New Issue
Block a user