url param migrate, s1 do the cider.sh (rpc ln67)
This commit is contained in:
parent
4bb64e24c0
commit
19e9555096
3 changed files with 75 additions and 63 deletions
|
@ -101,8 +101,9 @@ const CiderBase = {
|
|||
})
|
||||
|
||||
win.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||
if(details.url.match(/^https:\/\/store-\d{3}\.blobstore\.apple\.com/) || details.url.startsWith("https://store-037.blobstore.apple.com")){
|
||||
details.responseHeaders['Access-Control-Allow-Origin'] = '*';}
|
||||
if (details.url.match(/^https:\/\/store-\d{3}\.blobstore\.apple\.com/) || details.url.startsWith("https://store-037.blobstore.apple.com")) {
|
||||
details.responseHeaders['Access-Control-Allow-Origin'] = '*';
|
||||
}
|
||||
callback({ responseHeaders: details.responseHeaders })
|
||||
})
|
||||
|
||||
|
@ -338,10 +339,11 @@ const CiderBase = {
|
|||
},
|
||||
LinkHandler: (startArgs) => {
|
||||
if (!startArgs) return;
|
||||
console.log("lfmtoken", String(startArgs))
|
||||
|
||||
if (String(startArgs).includes('auth')) {
|
||||
let authURI = String(startArgs).split('/auth/')[1]
|
||||
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
|
||||
console.log("lfmtoken", String(startArgs))
|
||||
const authKey = authURI.split('lastfm?token=')[1];
|
||||
app.cfg.set('lastfm.enabled', true);
|
||||
app.cfg.set('lastfm.auth_token', authKey);
|
||||
|
@ -349,15 +351,26 @@ const CiderBase = {
|
|||
lastfm.authenticate()
|
||||
}
|
||||
} else {
|
||||
const formattedSongID = startArgs.replace('ame://', '').replace('/', '');
|
||||
console.warn(`[LinkHandler] Attempting to load song id: ${formattedSongID}`);
|
||||
if (String(startArgs).includes('/play/')) { //Steer away from protocal:// specific conditionals
|
||||
const playParam = String(startArgs).split('/play/')[1]
|
||||
if (playParam.includes('s/')) { // setQueue can be done with album, song, url, playlist id
|
||||
console.log(playParam)
|
||||
let song = playParam.split('s/')[1]
|
||||
console.warn(`[LinkHandler] Attempting to load song by id: ${song}`);
|
||||
this.win.webContents.executeJavaScript(`
|
||||
MusicKit.getInstance().setQueue({ song: '${song}'}).then(function(queue) {
|
||||
MusicKit.getInstance().play();
|
||||
});
|
||||
`).catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// setQueue can be done with album, song, url, playlist id
|
||||
this.win.webContents.executeJavaScript(`
|
||||
MusicKit.getInstance().setQueue({ song: '${formattedSongID}'}).then(function(queue) {
|
||||
MusicKit.getInstance().play();
|
||||
});
|
||||
`).catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -427,4 +440,4 @@ const CiderBase = {
|
|||
|
||||
}
|
||||
|
||||
module.exports = CiderBase;
|
||||
module.exports = CiderBase;
|
|
@ -1,4 +1,4 @@
|
|||
const {app} = require('electron'),
|
||||
const { app } = require('electron'),
|
||||
DiscordRPC = require('discord-rpc')
|
||||
|
||||
module.exports = {
|
||||
|
@ -7,16 +7,16 @@ module.exports = {
|
|||
* Connects to Discord RPC
|
||||
* @param {string} clientId
|
||||
*/
|
||||
connect: function (clientId) {
|
||||
app.discord = {isConnected: false};
|
||||
connect: function(clientId) {
|
||||
app.discord = { isConnected: false };
|
||||
if (app.cfg.get('general.discord_rpc') == 0 || app.discord.isConnected) return;
|
||||
|
||||
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
|
||||
const client = new DiscordRPC.Client({transport: "ipc"});
|
||||
app.discord = Object.assign(client, {error: false, activityCache: null, isConnected: false});
|
||||
const client = new DiscordRPC.Client({ transport: "ipc" });
|
||||
app.discord = Object.assign(client, { error: false, activityCache: null, isConnected: false });
|
||||
|
||||
// Login to Discord
|
||||
app.discord.login({clientId})
|
||||
app.discord.login({ clientId })
|
||||
.then(() => {
|
||||
app.discord.isConnected = true;
|
||||
})
|
||||
|
@ -37,7 +37,7 @@ module.exports = {
|
|||
/**
|
||||
* Disconnects from Discord RPC
|
||||
*/
|
||||
disconnect: function () {
|
||||
disconnect: function() {
|
||||
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
|
||||
|
||||
try {
|
||||
|
@ -54,7 +54,7 @@ module.exports = {
|
|||
* Sets the activity of the client
|
||||
* @param {object} attributes
|
||||
*/
|
||||
updateActivity: function (attributes) {
|
||||
updateActivity: function(attributes) {
|
||||
if (app.cfg.get('general.discord_rpc') == 0) return;
|
||||
|
||||
if (!app.discord.isConnected) {
|
||||
|
@ -64,20 +64,20 @@ module.exports = {
|
|||
|
||||
// console.log('[DiscordRPC][updateActivity] Updating Discord Activity.')
|
||||
|
||||
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`
|
||||
//console.log(attributes)
|
||||
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}` // cider://play/s/[id] (for song)
|
||||
//console.log(attributes)
|
||||
let ActivityObject = {
|
||||
details: attributes.name,
|
||||
state: `by ${attributes.artistName}`,
|
||||
startTimestamp: attributes.startTime,
|
||||
endTimestamp: attributes.endTime,
|
||||
largeImageKey: (attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024')) ?? 'cider',
|
||||
largeImageKey: (attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024')) ? ? 'cider',
|
||||
largeImageText: attributes.albumName,
|
||||
smallImageKey: (attributes.status ? 'play' : 'pause'),
|
||||
smallImageText: (attributes.status ? 'Playing' : 'Paused'),
|
||||
instance: true,
|
||||
buttons: [
|
||||
{label: "Listen on Cider", url: listenURL},
|
||||
{ label: "Listen on Cider", url: listenURL },
|
||||
]
|
||||
};
|
||||
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue