From 79a62b5e2f0cee2e503ac7eb60a31e4e2e12f360 Mon Sep 17 00:00:00 2001 From: Brandon Plank <52553007+BrandonPlank@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:03:41 -0500 Subject: [PATCH] Use API --- .gitignore | 1 + index.js | 3 ++- resources/cider-ui-tests/index.js | 32 +++++++++++++------------------ resources/functions/cider-base.js | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 0c735597..1850e4a1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ package-lock.json .DS_Store yarn-error.log .yarnclean +auth.json diff --git a/index.js b/index.js index 4c821223..07e3bf6d 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ require('v8-compile-cache'); const {app} = require('electron'); +const {BrowserWindow} = require("electron-acrylic-window"); // Creating the Application Window and Calling all the Functions function CreateWindow() { @@ -19,7 +20,7 @@ function CreateWindow() { app.on('ready', () => { if (app.isQuiting) { app.quit(); return; } - + console.log('[Cider] Application is Ready. Creating Window.') CreateWindow() }); diff --git a/resources/cider-ui-tests/index.js b/resources/cider-ui-tests/index.js index 4332fdc4..f4ee74ea 100644 --- a/resources/cider-ui-tests/index.js +++ b/resources/cider-ui-tests/index.js @@ -779,26 +779,20 @@ const app = new Vue({ document.addEventListener('musickitloaded', function () { // MusicKit global is now defined - fetch("https://beta.music.apple.com/", {mode: "no-cors"}) - .then(response => response.text()) - .then(data => { - var el = document.createElement("html"); - el.innerHTML = data; - var u = el.querySelector(`[name="desktop-music-app/config/environment"]`) - var amwebCFG = JSON.parse(decodeURIComponent(u.getAttribute("content"))); - console.log(amwebCFG.MEDIA_API.token) - MusicKit.configure({ - developerToken: amwebCFG.MEDIA_API.token, - app: { - name: 'My Cool Web App', - build: '1978.4.1' - } - }); - setTimeout(() => { - app.init() - }, 1000) + console.log("Loading musickit") + ipcRenderer.on('devkey', (event, key) => { + console.log(key); + MusicKit.configure({ + developerToken: key, + app: { + name: 'My Cool Web App', + build: '1978.4.1' + } }); - + setTimeout(() => { + app.init() + }, 1000) + }) }); function xmlToJson(xml) { diff --git a/resources/functions/cider-base.js b/resources/functions/cider-base.js index 0bfd2573..1b59a6de 100644 --- a/resources/functions/cider-base.js +++ b/resources/functions/cider-base.js @@ -4,6 +4,8 @@ const getPort = require("get-port"); const express = require("express"); const path = require("path"); const windowStateKeeper = require("electron-window-state"); +const request = require('request'); +const authFile = require("../auth.json"); const CiderBase = { @@ -106,6 +108,18 @@ const CiderBase = { }) } + win.webContents.on('did-finish-load', () => { + let authFile = require("../auth.json") + request({url: "https://devkey.cider.sh/", + headers: { + "Authorization": "Bearer "+authFile.authHeader + } + }, function (error, response, body) { + if (error) return console.log(error); + let parsedJson = JSON.parse(body) + win.webContents.send("devkey", parsedJson.Key) + }) + }) return win }, async InitWebServer() {