Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswaycaster committed Nov 2, 2021
0 parents commit 26d4107
Show file tree
Hide file tree
Showing 14 changed files with 3,945 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
out
Binary file added Icon.icns
Binary file not shown.
Binary file added Icon.ico
Binary file not shown.
Binary file added Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MenuIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MenuIcon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# XM Menu Player
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'"
/>
<title></title>
</head>
<body>
<!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
</body>
</html>
71 changes: 71 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Modules to control application life and create native browser window
const { app } = require("electron");
const path = require("path");
const { menubar } = require("menubar");

const mb = menubar({
browserWindow: { width: 450, height: 660 },
preloadWindow: true,
icon: path.join(__dirname, "/MenuIcon.png"),
webPreferences: {
partition: "persist:xmmenuplayer",
},
});

mb.app.commandLine.appendSwitch(
"disable-backgrounding-occluded-windows",
"true"
);

mb.on("ready", () => {
console.log("app is ready");

win = mb.window;
// win.openDevTools();

// First URL
win.loadURL("https://player.siriusxm.com/now-playing");

// mb.on('after-create-window', () => {

// Once dom-ready
win.webContents.once("dom-ready", () => {
setInterval(() => {
// Artist Name
const artistName = win.webContents
.executeJavaScript(
`document.querySelector('.sxm-player-controls .artist-name').innerText`
)
.then((result) => result.trim());

// Track Name
const trackName = win.webContents
.executeJavaScript(
`document.querySelector('.sxm-player-controls .track-name').innerText`
)
.then((result) => result.trim());

// Player State
const playerState = win.webContents
.executeJavaScript(
`document.querySelector('.sxm-player-controls .play-pause-btn').getAttribute('title')`
)
.then((result) => result.trim())
.then((state) => (state == "Play" ? "⏸︎" : ""));

Promise.all([artistName, trackName, playerState])
.then(([artistName, trackName, playerState]) => {
// Set Menubar Title
mb.tray.setTitle(`${playerState} ${artistName} - ${trackName}`);
})
.catch(() => {});
}, 1000);
});
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
});
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "xmmenuplayer",
"productName": "XM Menu Player",
"description": "Menu bar app for easily accessing the SiriusXM Player",
"keywords": [],
"main": "./main.js",
"version": "1.0.0",
"author": "rosswaycaster",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"dependencies": {
"menubar": "*"
},
"devDependencies": {
"electron": "15.3.0",
"@electron-forge/cli": "^6.0.0-beta.59",
"@electron-forge/maker-deb": "^6.0.0-beta.59",
"@electron-forge/maker-rpm": "^6.0.0-beta.59",
"@electron-forge/maker-squirrel": "^6.0.0-beta.59",
"@electron-forge/maker-zip": "^6.0.0-beta.59"
},
"config": {
"forge": {
"packagerConfig": {
"platform": "all",
"icon": "./Icon"
},
"makers": [
{
"name": "@electron-forge/maker-squirrel"
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
}
}
12 changes: 12 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}

for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})
6 changes: 6 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
Loading

0 comments on commit 26d4107

Please sign in to comment.