apply workaround for login

This commit is contained in:
yazninja 2023-05-12 20:59:16 +03:00
parent ba7999af34
commit 658239ed5f
5 changed files with 170 additions and 14 deletions

View file

@ -110,9 +110,9 @@
}
],
"build": {
"electronVersion": "25.0.0-beta.2",
"electronVersion": "24.3.0",
"electronDownload": {
"version": "25.0.0-beta.2+wvcus",
"version": "24.3.0+wvcus",
"mirror": "https://github.com/castlabs/electron-releases/releases/download/v"
},
"appId": "cider",

View file

@ -1,5 +1,5 @@
import { join } from "path";
import { app, BrowserWindow as bw, ipcMain, ShareMenu, shell, screen, dialog, nativeTheme } from "electron";
import { app, BrowserWindow as bw, ipcMain, ShareMenu, shell, screen, dialog, nativeTheme, ipcRenderer } from "electron";
import * as windowStateKeeper from "electron-window-state";
import * as express from "express";
import * as getPort from "get-port";
@ -1407,6 +1407,144 @@ export class BrowserWindow {
shell.openExternal(String(utils.getStoreValue("cc_authURL")));
});
ipcMain.on("auth-window", (_event) => {
AuthWindow(BrowserWindow.win);
});
function AuthWindow(win: bw) {
// create a BrowserWindow
const authWindow = new bw({
width: 500,
height: 600,
show: false,
titleBarOverlay: {
color: "#1d1d1f",
symbolColor: "#ffffff",
},
titleBarStyle: "hidden",
darkTheme: true,
resizable: false,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
sandbox: true,
allowRunningInsecureContent: true,
webSecurity: false,
preload: join(utils.getPath("srcPath"), "./preload/cider-preload.js"),
nodeIntegrationInWorker: false,
experimentalFeatures: true,
},
});
// authWindow.webContents.openDevTools();
// remove all local storage data
authWindow.webContents.session.clearStorageData();
// set user agent
authWindow.webContents.setUserAgent(`Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15`);
// show the window
authWindow.loadURL("https://beta.music.apple.com/");
const cookieKeys = ["itspod", "pltvcid", "pldfltcid", "itua", "media-user-token", "acn1", "dslang"];
ipcMain.on("auth-window-ready", async (_event) => {
authWindow.show();
});
ipcMain.on("auth-completed", async (_event) => {
const cookies = await getCookies();
console.log("cookies", cookies);
win.webContents.send("recv-cookies", cookies);
authWindow.close();
});
const overlayStyling = `
.hehehe {
position: fixed;
top:0;
left:0;
width: 100px;
height: 100px;
background: #1d1d1f;
z-index: 99999;
}
.titlebar {
height: 30px;
position: fixed;
top:0;
left:0;
right:0;
-webkit-app-region: drag;
z-index: 99999;
}`;
// on content loaded
authWindow.webContents.on("did-finish-load", () => {
authWindow.webContents.executeJavaScript(`
let tOut = setInterval(async ()=>{
try {
if(typeof MusicKit === 'undefined') return;
MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, ()=>{
if(MusicKit.getInstance().isAuthorized) {
ipcRenderer.send('auth-completed')
}
})
clearInterval(tOut)
}catch(e) {}
}, 500)
let tOut2 = setInterval(()=>{
try {
const el = document.querySelector('.signin')
if(el) {
el.click()
ipcRenderer.send('auth-window-ready')
clearInterval(tOut2)
}
}catch(e) {}
}, 500)
let styling = \`${overlayStyling}\`;
(()=>{
const titleBarEl = document.createElement('div')
const overlayEl = document.createElement('div')
titleBarEl.classList.add('titlebar')
overlayEl.classList.add('hehehe')
const styleTag = document.createElement('style')
styleTag.innerHTML = styling
document.head.appendChild(styleTag)
document.body.appendChild(overlayEl)
document.body.appendChild(titleBarEl)
})()
`);
});
async function getCookies(): Promise<{ [key: string]: string }> {
return new Promise((res, rej) => {
authWindow.webContents.session.cookies
.get({})
.then((cookies) => {
// for each cookie
const toRenderer: {
[key: string]: string;
} = {};
for (let i = 0; i < cookieKeys.length; i++) {
const key = cookieKeys[i];
// find the cookie
const cookie = cookies.find((cookie) => cookie.name === key);
// if cookie exists
if (cookie) {
toRenderer[`music.ampwebplay.${cookie.name}`] = cookie.value;
}
}
res(toRenderer);
})
.catch((error) => {
console.log(error);
rej();
});
});
}
}
ipcMain.on("cc-logout", (_event) => {
//Make sure to update the default store
utils.setStoreValue("connectUser", {

View file

@ -352,6 +352,16 @@ const app = new Vue({
document.body.removeAttribute("loading");
ipcRenderer.invoke("renderer-ready", true);
document.querySelector("#LOADER").remove();
ipcRenderer.on("recv-cookies", function (_event, cookies) {
console.log('[appIPC] recv-cookies');
Object.keys(cookies).forEach((key) => {
localStorage.setItem(key, cookies[key]);
});
localStorage.setItem("seenOOBE", 1);
window.location.reload();
});
},
getAppStyle() {
let finalStyle = {};
@ -400,7 +410,7 @@ const app = new Vue({
if (val) {
this.mk.isAuthorized ? (this.chrome.menuOpened = !this.chrome.menuOpened) : false;
if (!this.mk.isAuthorized) {
this.mk.authorize();
ipcRenderer.send("auth-window")
}
} else {
setTimeout(() => {
@ -830,17 +840,23 @@ const app = new Vue({
this.chrome.nativeControls = true;
}
this.setLz(this.cfg.general.language);
this.setLzManual();
clearTimeout(this.hangtimer);
this.mk = MusicKit.getInstance();
let needsReload = typeof localStorage["music.ampwebplay.media-user-token"] == "undefined";
this.mk.authorize().then(() => {
self.mkIsReady = true;
if (needsReload) {
document.location.reload();
}
});
if(needsReload) {
ipcRenderer.send("auth-window");
this.mkIsReady = true;
}
// this.mk.authorize().then(() => {
// self.mkIsReady = true;
// if (needsReload) {
// document.location.reload();
// }
// });
this.$forceUpdate();
if (this.isDev) {
this.mk.privateEnabled = true;
@ -1075,6 +1091,7 @@ const app = new Vue({
}
});
this.mk.addEventListener(MusicKit.Events.playbackStateDidChange, (event) => {
ipcRenderer.send("wsapi-updatePlaybackState", wsapi.getAttributes());
document.body.setAttribute("playback-state", event.state == 2 ? "playing" : "paused");

View file

@ -183,8 +183,9 @@
localStorage.setItem("seenOOBE", 1)
window.location.reload()
}
this.screen = "signin"
capiInit()
this.screen = "signin";
capiInit();
},
getLz() {
return this.$root.getLz.apply(this.$root, arguments);

View file

@ -1,7 +1,7 @@
{
"electronVersion": "21.3.3",
"electronVersion": "24.3.0",
"electronDownload": {
"version": "21.3.3+wvcus",
"version": "24.3.0+wvcus",
"mirror": "https://github.com/castlabs/electron-releases/releases/download/v"
},
"appId": "cider",