diff --git a/.gitignore b/.gitignore index ccb2c800..42dd4aa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -package-lock.json \ No newline at end of file +package-lock.json +release-builds/ \ No newline at end of file diff --git a/README.md b/README.md index 9414b3cd..765b7183 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,15 @@ ## Installation * Download the [latest release](https://github.com/N0chteil/Apple-Music-RPC/releases/latest) * Extract the zip file -* Open the **setup.bat** file -* Open the **AMRPC.bat** file +* Open the **AMRPC.exe** file ## Requirements -* Windows 10 -* [iTunes](https://www.microsoft.com/p/itunes/9pb2mz1zmb1s?rtc=1&activetab=pivot:overviewtab) +* Windows 10/macOS (Not tested with macOS) +* [iTunes for Windows 10](https://www.microsoft.com/p/itunes/9pb2mz1zmb1s?rtc=1&activetab=pivot:overviewtab), [iTunes for macOS](https://www.apple.com/itunes/download/macos) * [NodeJS](https://nodejs.org/en/) (Tested with 14.17) ## Information This RPC is only for the Windows program. If you use Apple Music in your browser (macOS, Windows, Linux), check out [Apple Music RPC for PreMiD](https://premid.app/store/presences/Apple%20Music)! ## Coming soon -* Autostart * EXE installer diff --git a/assets/SFPro.ttf b/assets/SFPro.ttf new file mode 100644 index 00000000..5ae2fafb Binary files /dev/null and b/assets/SFPro.ttf differ diff --git a/assets/icons/mac/icon.icns b/assets/icons/mac/icon.icns new file mode 100644 index 00000000..447f91f7 Binary files /dev/null and b/assets/icons/mac/icon.icns differ diff --git a/assets/icons/win/icon.ico b/assets/icons/win/icon.ico new file mode 100644 index 00000000..7fd9c3d9 Binary files /dev/null and b/assets/icons/win/icon.ico differ diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 00000000..3929004c Binary files /dev/null and b/assets/logo.png differ diff --git a/assets/tray/logo@18.png b/assets/tray/logo@18.png new file mode 100644 index 00000000..88f53837 Binary files /dev/null and b/assets/tray/logo@18.png differ diff --git a/config.json b/config.json new file mode 100644 index 00000000..d78a6b98 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "autolaunch": "false", + "debugging": "false", + "version": "2.0.0" +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..50106d41 --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + + AMRPC + + +

Apple Music RPC

+ + + + + \ No newline at end of file diff --git a/index.js b/index.js index 0b9832f0..09bb20f1 100644 --- a/index.js +++ b/index.js @@ -3,23 +3,24 @@ const clientId = '842112189618978897', iTunes = require("itunes-bridge"), getAppleMusicLink = require("get-apple-music-link"), AutoLaunch = require("auto-launch"), - request = require("request"); + request = require("request"), + electron = require("electron"), + url = require("url"), + path = require("path"), + fs = require('fs'); const rpc = new DiscordRPC.Client({ transport: 'ipc' }), currentTrack = iTunes.getCurrentTrack(), - iTunesEmitter = iTunes.emitter; + iTunesEmitter = iTunes.emitter, + {app, Menu, Notification, Tray} = electron, + config = JSON.parse(fs.readFileSync('config.json', 'utf8')); let presenceData = { largeImageKey: 'applemusic-logo', - largeImageText: `AMRPC - V.${process.env.npm_package_version}` + largeImageText: `AMRPC - V.${config.version}` }, debugging = false; -let autoLaunch = new AutoLaunch({ - name: "", - path: __dirname+"AMRPC.bat" -}); - iTunesEmitter.on('playing', async function(type, currentTrack) { presenceData.details = (currentTrack) ? `${currentTrack.name} - ${currentTrack.album}` : "Unknown track"; presenceData.state = (currentTrack) ? currentTrack.artist : "Unknown artist"; @@ -31,7 +32,7 @@ iTunesEmitter.on('playing', async function(type, currentTrack) { if(debugging) console.log(res); presenceData.buttons = [ { - label: "Play on Apple Musicᴮᴱᵀᴬ", + label: "Play on Apple Music", url: res } ] @@ -61,9 +62,7 @@ iTunesEmitter.on('paused', async function(type, currentTrack) { }); iTunesEmitter.on('stopped', async function() { - if(debugging) { - console.log("\naction", "stopped"); - } + if(debugging) console.log("\naction", "stopped"); }); if(process.argv.find(element => element === "supporting")) { @@ -99,6 +98,31 @@ rpc.on('ready', () => { }, 5); }); +app.on("ready", function() { + let tray = new Tray(`${__dirname}\\assets\\logo.png`), + isQuiting; + + let autoLaunch = new AutoLaunch({ + name: "AMRPC", + path: app.getPath('exe') + }); + + app.on("quit", () => tray.destroy()); + app.on('before-quit', function () { + isQuiting = true; + }); + + tray.setToolTip("AMRPC"); + tray.setContextMenu(Menu.buildFromTemplate([ + { label: `AMRPC V${config.version}`, icon: `${__dirname}\\assets\\tray\\logo@18.png`, enabled: false }, + { type: "separator" }, + { label: "Show Presence", type: "checkbox", checked: (config.show) ? true : false, click() { updateShowRPC(this.checked) } }, + { label: "Quit", click() { isQuiting = true, app.quit() } } + ])); + tray.on("right-click", () => tray.update()); + autoLaunch.enable(); +}); + function updateChecker() { const fetchUrl = require("fetch").fetchUrl; @@ -106,44 +130,23 @@ function updateChecker() { body = JSON.parse(body.toString()); let version = { git: body[0].name.replace(".", "").replace("v", ""), - package: process.env.npm_package_version.replace(".", "") + package: config.version.replace(".", "") } if(version.git > version.package) { console.log("\x1b[31m%s\x1b[0m", `VersionCheck: Your version is outdated. Newest release is ${body[0].name}`); - console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Downloading newest release..."); - setTimeout(() => { - updateVersion(body[0].name); - }, 2000); + console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Please download the newest release from GitHub (Updater is currently in work)"); + showNotification("VersionCheck", `Your version is outdated. Newest release is ${body[0].name}`); + showNotification("VersionCheck", "Please download the newest release from GitHub (Updater is currently in work)"); } else { console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Up to date"); + showNotification("VersionCheck", "Up to date"); } }); } -function updateVersion(version) { - const download = require("download-git-repo"), - fs = require('fs'); - - download(`direct:https://github.com/N0chteil/Apple-Music-RPC/releases/download/${version}/amrpc-win.zip`, 'github_newest', function (err) { - err = (err === undefined || err === false) ? false : true; - if(!err) { - console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Successfully downloaded!"); - fs.writeFile("updater.bat", 'del "index.js"\ndel "package.json"\nmove /y github_newest\\*.* .\n@RD /S /Q "github_newest"\nnpm install\ndel "updater.bat"', function(err) { - if(err) return console.log(err); - else { - console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Created updater file. Exiting process in 10 seconds."); - console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Please open the updater file after the process is finished."); - } - }); - setTimeout(() => { - require('child_process').exec('updater.bat'); - process.exit(); - }, 10000); - } else { - console.log("\x1b[36m%s\x1b[0m", "VersionCheck: Error downloading the latest version from GitHub"); - } - }) +function showNotification (title, body) { + new Notification({title: title,body: body}).show() } rpc.login({ clientId }).catch(console.error); \ No newline at end of file diff --git a/package.json b/package.json index 591a5220..a2898e93 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,11 @@ "description": "Discord RPC for iTunes", "main": "index.js", "scripts": { - "start": "node index.js" + "start": "node index.js", + "test": "electron .", + "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds", + "package-win": "electron-packager . AMRPC --overwrite --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=N0chteil --version-string.FileDescription=Discord RPC for Apple Music --version-string.ProductName=\"AMRPC\"", + "package-linux": "electron-packager . AMRPC --overwrite --platform=linux --arch=x64 --icon=assets/logo.png --prune=true --out=release-builds" }, "repository": { "type": "git", @@ -29,5 +33,9 @@ "fetch": "^1.1.0", "get-apple-music-link": "^1.0.0", "itunes-bridge": "^0.6.6" + }, + "devDependencies": { + "electron": "^13.0.1", + "electron-packager": "^15.2.0" } }