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
75
index.js
75
index.js
|
@ -1,14 +1,14 @@
|
||||||
require('v8-compile-cache');
|
require('v8-compile-cache');
|
||||||
const {app, components} = require('electron'),
|
const { app, components } = require('electron'), { resolve, join } = require("path"),
|
||||||
{resolve, join} = require("path"),
|
|
||||||
CiderBase = require('./src/main/cider-base');
|
CiderBase = require('./src/main/cider-base');
|
||||||
|
const customProtocols = require('./package.json').fileAssociations[0].protocols
|
||||||
|
console.log(customProtocols)
|
||||||
const comps = components;
|
const comps = components;
|
||||||
|
|
||||||
|
|
||||||
// Analytics for debugging.
|
// Analytics for debugging.
|
||||||
const ElectronSentry = require("@sentry/electron");
|
const ElectronSentry = require("@sentry/electron");
|
||||||
ElectronSentry.init({dsn: "https://68c422bfaaf44dea880b86aad5a820d2@o954055.ingest.sentry.io/6112214"});
|
ElectronSentry.init({ dsn: "https://68c422bfaaf44dea880b86aad5a820d2@o954055.ingest.sentry.io/6112214" });
|
||||||
|
|
||||||
const configDefaults = {
|
const configDefaults = {
|
||||||
"general": {
|
"general": {
|
||||||
|
@ -109,23 +109,23 @@ app.paths = {
|
||||||
|
|
||||||
switch (app.cfg.get("visual.hw_acceleration")) {
|
switch (app.cfg.get("visual.hw_acceleration")) {
|
||||||
default:
|
default:
|
||||||
case "default":
|
case "default":
|
||||||
app.commandLine.appendSwitch('enable-accelerated-mjpeg-decode')
|
app.commandLine.appendSwitch('enable-accelerated-mjpeg-decode')
|
||||||
app.commandLine.appendSwitch('enable-accelerated-video')
|
app.commandLine.appendSwitch('enable-accelerated-video')
|
||||||
app.commandLine.appendSwitch('disable-gpu-driver-bug-workarounds')
|
app.commandLine.appendSwitch('disable-gpu-driver-bug-workarounds')
|
||||||
app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
||||||
app.commandLine.appendSwitch('enable-native-gpu-memory-buffers')
|
app.commandLine.appendSwitch('enable-native-gpu-memory-buffers')
|
||||||
app.commandLine.appendSwitch('enable-accelerated-video-decode');
|
app.commandLine.appendSwitch('enable-accelerated-video-decode');
|
||||||
app.commandLine.appendSwitch('enable-gpu-rasterization');
|
app.commandLine.appendSwitch('enable-gpu-rasterization');
|
||||||
app.commandLine.appendSwitch('enable-native-gpu-memory-buffers');
|
app.commandLine.appendSwitch('enable-native-gpu-memory-buffers');
|
||||||
app.commandLine.appendSwitch('enable-oop-rasterization');
|
app.commandLine.appendSwitch('enable-oop-rasterization');
|
||||||
break;
|
break;
|
||||||
case "webgpu":
|
case "webgpu":
|
||||||
console.info("WebGPU is enabled.");
|
console.info("WebGPU is enabled.");
|
||||||
app.commandLine.appendSwitch('enable-unsafe-webgpu')
|
app.commandLine.appendSwitch('enable-unsafe-webgpu')
|
||||||
break;
|
break;
|
||||||
case "disabled":
|
case "disabled":
|
||||||
console.info("Hardware acceleration is disabled.");
|
console.info("Hardware acceleration is disabled.");
|
||||||
app.commandLine.appendSwitch('disable-gpu')
|
app.commandLine.appendSwitch('disable-gpu')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ function CreateWindow() {
|
||||||
const ciderwin = require("./src/main/cider-base")
|
const ciderwin = require("./src/main/cider-base")
|
||||||
app.win = ciderwin
|
app.win = ciderwin
|
||||||
app.win.Start()
|
app.win.Start()
|
||||||
/** CIDER **/
|
/** CIDER **/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
|
@ -152,10 +152,10 @@ app.commandLine.appendSwitch('no-sandbox');
|
||||||
// app.commandLine.appendSwitch('js-flags', '--max-old-space-size=1024')
|
// app.commandLine.appendSwitch('js-flags', '--max-old-space-size=1024')
|
||||||
|
|
||||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
* App Event Handlers
|
* App Event Handlers
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||||
|
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async() => {
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
app.commandLine.appendSwitch('high-dpi-support', 'true')
|
app.commandLine.appendSwitch('high-dpi-support', 'true')
|
||||||
app.commandLine.appendSwitch('force-device-scale-factor', '1')
|
app.commandLine.appendSwitch('force-device-scale-factor', '1')
|
||||||
|
@ -208,25 +208,28 @@ app.on('widevine-error', (error) => {
|
||||||
|
|
||||||
if (process.defaultApp) {
|
if (process.defaultApp) {
|
||||||
if (process.argv.length >= 2) {
|
if (process.argv.length >= 2) {
|
||||||
app.setAsDefaultProtocolClient('cider', process.execPath, [resolve(process.argv[1])])
|
customProtocols.forEach((customProtocol) => {
|
||||||
app.setAsDefaultProtocolClient('ame', process.execPath, [resolve(process.argv[1])])
|
app.setAsDefaultProtocolClient(customProtocol, process.execPath, [resolve(process.argv[1])])
|
||||||
app.setAsDefaultProtocolClient('itms', process.execPath, [resolve(process.argv[1])])
|
})
|
||||||
app.setAsDefaultProtocolClient('itmss', process.execPath, [resolve(process.argv[1])])
|
|
||||||
app.setAsDefaultProtocolClient('musics', process.execPath, [resolve(process.argv[1])])
|
|
||||||
app.setAsDefaultProtocolClient('music', process.execPath, [resolve(process.argv[1])])
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.setAsDefaultProtocolClient('cider') // Custom AME Protocol
|
/*
|
||||||
app.setAsDefaultProtocolClient('ame') // Custom AME Protocol
|
* cider - Custom Cider Protocol
|
||||||
app.setAsDefaultProtocolClient('itms') // iTunes HTTP Protocol
|
* ame - Custom AME Protocol (Backwards Compat.)
|
||||||
app.setAsDefaultProtocolClient('itmss') // iTunes HTTPS Protocol
|
* itms - iTunes HTTP Protocol
|
||||||
app.setAsDefaultProtocolClient('musics') // macOS Client Protocol
|
* itmss - iTunes HTTPS Protocol
|
||||||
app.setAsDefaultProtocolClient('music') // macOS Client Protocol
|
* musics - macOS Client Protocol
|
||||||
|
* music - macOS Client Protocol
|
||||||
|
*/
|
||||||
|
customProtocols.forEach((customProtocol) => {
|
||||||
|
app.setAsDefaultProtocolClient(customProtocol)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on('open-url', (event, url) => {
|
app.on('open-url', (event, url) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (url.includes('ame://') || url.includes('itms://') || url.includes('itmss://') || url.includes('musics://') || url.includes('music://')) {
|
if (customProtocols.some(protocol => url.includes(protocol))) {
|
||||||
CiderBase.LinkHandler(url)
|
CiderBase.LinkHandler(url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -236,8 +239,7 @@ app.on('second-instance', (_e, argv) => {
|
||||||
|
|
||||||
// Checks if first instance is authorized and if second instance has protocol args
|
// Checks if first instance is authorized and if second instance has protocol args
|
||||||
argv.forEach((value) => {
|
argv.forEach((value) => {
|
||||||
if (value.includes('ame://') || value.includes('itms://') || value.includes('itmss://') || value.includes('musics://') || value.includes('music://')) {
|
if (customProtocols.some(protocol => value.includes(protocol))) {
|
||||||
console.warn(`[InstanceHandler][SecondInstanceHandler] Found Protocol!`)
|
|
||||||
CiderBase.LinkHandler(value);
|
CiderBase.LinkHandler(value);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -258,6 +260,3 @@ if (!app.requestSingleInstanceLock() && true) {
|
||||||
app.quit();
|
app.quit();
|
||||||
// app.isQuiting = true
|
// app.isQuiting = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,8 +101,9 @@ const CiderBase = {
|
||||||
})
|
})
|
||||||
|
|
||||||
win.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
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")){
|
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'] = '*';}
|
details.responseHeaders['Access-Control-Allow-Origin'] = '*';
|
||||||
|
}
|
||||||
callback({ responseHeaders: details.responseHeaders })
|
callback({ responseHeaders: details.responseHeaders })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -338,10 +339,11 @@ const CiderBase = {
|
||||||
},
|
},
|
||||||
LinkHandler: (startArgs) => {
|
LinkHandler: (startArgs) => {
|
||||||
if (!startArgs) return;
|
if (!startArgs) return;
|
||||||
console.log("lfmtoken", String(startArgs))
|
|
||||||
if (String(startArgs).includes('auth')) {
|
if (String(startArgs).includes('auth')) {
|
||||||
let authURI = String(startArgs).split('/auth/')[1]
|
let authURI = String(startArgs).split('/auth/')[1]
|
||||||
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
|
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
|
||||||
|
console.log("lfmtoken", String(startArgs))
|
||||||
const authKey = authURI.split('lastfm?token=')[1];
|
const authKey = authURI.split('lastfm?token=')[1];
|
||||||
app.cfg.set('lastfm.enabled', true);
|
app.cfg.set('lastfm.enabled', true);
|
||||||
app.cfg.set('lastfm.auth_token', authKey);
|
app.cfg.set('lastfm.auth_token', authKey);
|
||||||
|
@ -349,15 +351,26 @@ const CiderBase = {
|
||||||
lastfm.authenticate()
|
lastfm.authenticate()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const formattedSongID = startArgs.replace('ame://', '').replace('/', '');
|
if (String(startArgs).includes('/play/')) { //Steer away from protocal:// specific conditionals
|
||||||
console.warn(`[LinkHandler] Attempting to load song id: ${formattedSongID}`);
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const {app} = require('electron'),
|
const { app } = require('electron'),
|
||||||
DiscordRPC = require('discord-rpc')
|
DiscordRPC = require('discord-rpc')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -7,16 +7,16 @@ module.exports = {
|
||||||
* Connects to Discord RPC
|
* Connects to Discord RPC
|
||||||
* @param {string} clientId
|
* @param {string} clientId
|
||||||
*/
|
*/
|
||||||
connect: function (clientId) {
|
connect: function(clientId) {
|
||||||
app.discord = {isConnected: false};
|
app.discord = { isConnected: false };
|
||||||
if (app.cfg.get('general.discord_rpc') == 0 || app.discord.isConnected) return;
|
if (app.cfg.get('general.discord_rpc') == 0 || app.discord.isConnected) return;
|
||||||
|
|
||||||
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
|
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
|
||||||
const client = new DiscordRPC.Client({transport: "ipc"});
|
const client = new DiscordRPC.Client({ transport: "ipc" });
|
||||||
app.discord = Object.assign(client, {error: false, activityCache: null, isConnected: false});
|
app.discord = Object.assign(client, { error: false, activityCache: null, isConnected: false });
|
||||||
|
|
||||||
// Login to Discord
|
// Login to Discord
|
||||||
app.discord.login({clientId})
|
app.discord.login({ clientId })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
app.discord.isConnected = true;
|
app.discord.isConnected = true;
|
||||||
})
|
})
|
||||||
|
@ -37,7 +37,7 @@ module.exports = {
|
||||||
/**
|
/**
|
||||||
* Disconnects from Discord RPC
|
* Disconnects from Discord RPC
|
||||||
*/
|
*/
|
||||||
disconnect: function () {
|
disconnect: function() {
|
||||||
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
|
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -54,7 +54,7 @@ module.exports = {
|
||||||
* Sets the activity of the client
|
* Sets the activity of the client
|
||||||
* @param {object} attributes
|
* @param {object} attributes
|
||||||
*/
|
*/
|
||||||
updateActivity: function (attributes) {
|
updateActivity: function(attributes) {
|
||||||
if (app.cfg.get('general.discord_rpc') == 0) return;
|
if (app.cfg.get('general.discord_rpc') == 0) return;
|
||||||
|
|
||||||
if (!app.discord.isConnected) {
|
if (!app.discord.isConnected) {
|
||||||
|
@ -64,20 +64,20 @@ module.exports = {
|
||||||
|
|
||||||
// console.log('[DiscordRPC][updateActivity] Updating Discord Activity.')
|
// console.log('[DiscordRPC][updateActivity] Updating Discord Activity.')
|
||||||
|
|
||||||
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`
|
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}` // cider://play/s/[id] (for song)
|
||||||
//console.log(attributes)
|
//console.log(attributes)
|
||||||
let ActivityObject = {
|
let ActivityObject = {
|
||||||
details: attributes.name,
|
details: attributes.name,
|
||||||
state: `by ${attributes.artistName}`,
|
state: `by ${attributes.artistName}`,
|
||||||
startTimestamp: attributes.startTime,
|
startTimestamp: attributes.startTime,
|
||||||
endTimestamp: attributes.endTime,
|
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,
|
largeImageText: attributes.albumName,
|
||||||
smallImageKey: (attributes.status ? 'play' : 'pause'),
|
smallImageKey: (attributes.status ? 'play' : 'pause'),
|
||||||
smallImageText: (attributes.status ? 'Playing' : 'Paused'),
|
smallImageText: (attributes.status ? 'Playing' : 'Paused'),
|
||||||
instance: true,
|
instance: true,
|
||||||
buttons: [
|
buttons: [
|
||||||
{label: "Listen on Cider", url: listenURL},
|
{ label: "Listen on Cider", url: listenURL },
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue