diff --git a/index.js b/index.js index 2a3db7cd..5722fcf2 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,6 @@ function CreateWindow() { app.on('ready', () => { if (app.isQuiting) { app.quit(); return; } - require('vue-devtools').install() // Apple Header tomfoolery. session.defaultSession.webRequest.onHeadersReceived((details, callback) => { if(details.url.match(/^https:\/\/store-\d{3}\.blobstore\.apple\.com/) || details.url.startsWith("https://store-037.blobstore.apple.com")){ diff --git a/resources/cider-ui-tests/index.html b/resources/cider-ui-tests/index.html index 8b32d746..3fb8a3cc 100644 --- a/resources/cider-ui-tests/index.html +++ b/resources/cider-ui-tests/index.html @@ -180,7 +180,7 @@
- + diff --git a/resources/functions/cider-win.js b/resources/functions/cider-win.js index 932681e4..3d0281be 100644 --- a/resources/functions/cider-win.js +++ b/resources/functions/cider-win.js @@ -1,4 +1,4 @@ -const {app, BrowserWindow} = require("electron") +const {app, BrowserWindow, ipcMain} = require("electron") const {join, resolve} = require("path") const CiderWin = { @@ -34,6 +34,8 @@ const CiderWin = { win.on("closed", () => { win = null }) + }, + SetupHandlers() { } } diff --git a/resources/functions/wsapi.js b/resources/functions/wsapi.js index 7788e83a..f07bc528 100644 --- a/resources/functions/wsapi.js +++ b/resources/functions/wsapi.js @@ -8,6 +8,7 @@ const path = require('path'); const port = process.argv[2] || 9000; const express = require('express'); const router = express.Router(); +const getPort = require('get-port'); const { ipcMain, app, @@ -32,7 +33,7 @@ const wsapi = { return v.toString(16); }); }, - InitWebSockets() { + async InitWebSockets () { ipcMain.on('wsapi-updatePlaybackState', (event, arg) => { wsapi.updatePlaybackState(arg); }) @@ -49,12 +50,20 @@ const wsapi = { wsapi.returnSearchLibrary(JSON.parse(arg)); }); + ipcMain.on('wsapi-returnDynamic', (event, arg, type) => { + wsapi.returnDynamic(JSON.parse(arg), type); + }); + + ipcMain.on('wsapi-returnMusicKitApi', (event, arg, method) => { + wsapi.returnMusicKitApi(JSON.parse(arg), method); + }); + ipcMain.on('wsapi-returnLyrics', (event, arg) => { wsapi.returnLyrics(JSON.parse(arg)); }); - + var safeport = await getPort({port : 26369}); wss = new WebSocketServer({ - port: 26369, + port: safeport, perMessageDeflate: { zlibDeflateOptions: { // See zlib defaults. @@ -75,10 +84,11 @@ const wsapi = { // should not be compressed if context takeover is disabled. } }) - + console.log(`WebSocketServer started on port: ${safeport}`); + const defaultResponse = new wsapi.standardResponse(0, {}, "OK"); - console.log(`WebSocketServer started on port: ${this.port}`); + wss.on('connection', function connection(ws) { ws.id = wsapi.createId(); console.log(`Client ${ws.id} connected`) @@ -127,6 +137,13 @@ const wsapi = { case "shuffle": app.win.webContents.executeJavaScript(`wsapi.toggleShuffle()`); break; + case "set-shuffle": + if(data.shuffle == true) { + app.win.webContents.executeJavaScript(`MusicKit.getInstance().shuffleMode = 1`); + }else{ + app.win.webContents.executeJavaScript(`MusicKit.getInstance().shuffleMode = 0`); + } + break; case "repeat": app.win.webContents.executeJavaScript(`wsapi.toggleRepeat()`); break; @@ -167,10 +184,9 @@ const wsapi = { response.message = "Previous"; break; case "musickit-api": - + app.win.webContents.executeJavaScript(`wsapi.musickitApi(\`${data.method}\`, \`${data.id}\`, ${JSON.stringify(data.params)})`); break; case "musickit-library-api": - break; case "set-autoplay": app.win.webContents.executeJavaScript(`wsapi.setAutoplay(${data.autoplay})`); @@ -200,7 +216,7 @@ const wsapi = { app.win.hide() break; case "play-mediaitem": - app.win.webContents.executeJavaScript(`wsapi.playTrackById(${data.id})`); + app.win.webContents.executeJavaScript(`wsapi.playTrackById(${data.id}, \`${data.kind}\`)`); response.message = "Playing track"; break; case "get-status": @@ -249,6 +265,18 @@ const wsapi = { client.send(JSON.stringify(response)); }); }, + returnMusicKitApi(results, method) { + const response = new wsapi.standardResponse(0, results, "OK", `musickitapi.${method}`); + wsapi.clients.forEach(function each(client) { + client.send(JSON.stringify(response)); + }); + }, + returnDynamic(results, type) { + const response = new wsapi.standardResponse(0, results, "OK", type); + wsapi.clients.forEach(function each(client) { + client.send(JSON.stringify(response)); + }); + }, returnLyrics(results) { const response = new wsapi.standardResponse(0, results, "OK", "lyrics"); wsapi.clients.forEach(function each(client) { @@ -272,9 +300,10 @@ const wsapi = { wsapi.clients.forEach(function each(client) { client.send(JSON.stringify(response)); }); - }, + }, webRemotePort: 8090, - InitWebServer() { + async InitWebServer() { + const webRemotePort = await getPort({port : wsapi.webRemotePort}); // Web Remote // express server that will serve static files in the "../web-remote" folder const webapp = express(); @@ -283,8 +312,8 @@ const wsapi = { webapp.get('/', function (req, res) { res.sendFile(path.join(webRemotePath, 'index.html')); }); - webapp.listen(wsapi.webRemotePort, function () { - console.log(`Web Remote listening on port ${wsapi.webRemotePort}`); + webapp.listen(webRemotePort, function () { + console.log(`Web Remote listening on port ${webRemotePort}`); }); } } diff --git a/resources/js/WSAPI_Interop.js b/resources/js/WSAPI_Interop.js index bb61cfcd..53c9d4f9 100644 --- a/resources/js/WSAPI_Interop.js +++ b/resources/js/WSAPI_Interop.js @@ -16,6 +16,14 @@ const wsapi = { setAutoplay(value) { MusicKit.getInstance().autoplayEnabled = value }, + returnDynamic(data, type) { + ipcRenderer.send('wsapi-returnDynamic', JSON.stringify(data), type) + }, + musickitApi(method, id, params) { + MusicKit.getInstance().api[method](id, params).then((results)=>{ + ipcRenderer.send('wsapi-returnMusicKitApi', JSON.stringify(results), method) + }) + }, getPlaybackState () { ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes()); }, @@ -38,8 +46,8 @@ const wsapi = { love() { }, - playTrackById(id) { - MusicKit.getInstance().setQueue({ song: id }).then(function (queue) { + playTrackById(id, kind = "song") { + MusicKit.getInstance().setQueue({ [kind]: id }).then(function (queue) { MusicKit.getInstance().play() }) }, diff --git a/resources/web-remote/assets/Grabber.svg b/resources/web-remote/assets/Grabber.svg new file mode 100644 index 00000000..287eb001 --- /dev/null +++ b/resources/web-remote/assets/Grabber.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/web-remote/assets/infinity.svg b/resources/web-remote/assets/infinity.svg new file mode 100644 index 00000000..4d06c7b8 --- /dev/null +++ b/resources/web-remote/assets/infinity.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/web-remote/index.html b/resources/web-remote/index.html index 17922e21..18695a58 100644 --- a/resources/web-remote/index.html +++ b/resources/web-remote/index.html @@ -14,528 +14,53 @@ -
-