This commit is contained in:
booploops 2021-12-27 04:01:57 -08:00
commit c8954e4265
5 changed files with 69 additions and 41 deletions

View file

@ -1,5 +1,5 @@
require('v8-compile-cache');
const { app, screen } = require('electron');
const { app } = require('electron');
// Analytics for debugging.
const ElectronSentry = require("@sentry/electron");
@ -72,6 +72,10 @@ function CreateWindow() {
/** CIDER **/
}
if (process.platform === "linux") {
app.commandLine.appendSwitch('disable-features', 'MediaSessionService');
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* App Event Handlers

View file

@ -5,10 +5,9 @@ const express = require("express");
const path = require("path");
const windowStateKeeper = require("electron-window-state");
const os = require('os');
const Store = require("electron-store");
const store = new Store();
const yt = require('youtube-search-without-api-key');
const discord = require('./discordrpc');
const mpris = require('./mpris');
// Analytics for debugging.
const ElectronSentry = require("@sentry/electron");
@ -85,7 +84,7 @@ const CiderBase = {
)
win.webContents.session.webRequest.onBeforeSendHeaders(async (details, callback) => {
if(details.url == "https://buy.itunes.apple.com/account/web/info"){
if (details.url === "https://buy.itunes.apple.com/account/web/info") {
details.requestHeaders['sec-fetch-site'] = 'same-site';
details.requestHeaders['DNT'] = '1';
let itspod = await win.webContents.executeJavaScript(`window.localStorage.getItem("music.ampwebplay.itspod")`)
@ -189,7 +188,8 @@ const CiderBase = {
if (url.includes("apple") || url.includes("localhost")) {
return {action: "allow"}
}
shell.openExternal(url).catch(() => {})
shell.openExternal(url).catch(() => {
})
return {
action: 'deny'
}
@ -202,13 +202,17 @@ const CiderBase = {
win.webContents.setZoomFactor(screen.getPrimaryDisplay().scaleFactor)
mpris.connect(win)
// Discord
discord.connect('911790844204437504');
ipcMain.on('playbackStateDidChange', (_event, a) => {
discord.updateActivity(a)
mpris.updateState(a)
});
ipcMain.on('nowPlayingItemDidChange', (_event, a) => {
discord.updateActivity(a)
mpris.updateAttributes(a)
});
return win

View file

@ -2,6 +2,11 @@ const {app} = require('electron'),
DiscordRPC = require('discord-rpc')
module.exports = {
/**
* Connects to Discord RPC
* @param {string} clientId
*/
connect: function (clientId) {
app.discord = {isConnected: false};
if (!app.cfg.get('general.discord_rpc')) return;
@ -34,6 +39,9 @@ module.exports = {
});
},
/**
* Disconnects from Discord RPC
*/
disconnect: function () {
if (!app.cfg.get('general.discord_rpc') || !app.discord.isConnected) return;
@ -47,6 +55,10 @@ module.exports = {
}
},
/**
* Sets the activity of the client
* @param {object} attributes
*/
updateActivity: function (attributes) {
if (!app.cfg.get('general.discord_rpc')) return;
@ -74,7 +86,9 @@ module.exports = {
{label: "Listen on Cider", url: listenURL},
]
};
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {ActivityObject.largeImageKey = "cider"}
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
ActivityObject.largeImageKey = "cider"
}
//console.log(`[LinkHandler] Listening URL has been set to: ${listenURL}`);
// if (app.cfg.get('general.discordClearActivityOnPause')) {

View file

@ -1,5 +0,0 @@
const {app} = require('electron');
module.export = () => {
if (process.platform === "linux") app.commandLine.appendSwitch('disable-features', 'MediaSessionService');
}

View file

@ -1,16 +1,16 @@
const {app} = require('electron'),
Player = require('mpris-service');
// Remember to use playerctl when debugging this.
// I'm just putting this here as I keep forgetting the command.
// Copied from AME
let mediaPlayer;
let mediaPlayer = null;
module.exports = {
/**
* Connects to the MPRIS interface.
* @param {Object} win - The BrowserWindow.
*/
connect: (win) => {
if (process.platform !== "linux") return;
const Player = require('mpris-service');
mediaPlayer = Player({
name: 'Cider',
identity: 'Cider',
@ -24,7 +24,7 @@ module.exports = {
let pos_atr = {durationInMillis: 0};
mediaPlayer.getPosition = function () {
const durationInMicro = pos_atr.durationInMillis * 1000;
const percentage = parseFloat(0) || 0;
const percentage = parseFloat("0") || 0;
return durationInMicro * percentage;
}
@ -51,6 +51,10 @@ module.exports = {
});
},
/**
* Updates the MPRIS interface.
* @param {Object} attributes - The attributes of the track.
*/
updateAttributes: (attributes) => {
if (process.platform !== "linux") return;
@ -71,6 +75,10 @@ module.exports = {
mediaPlayer.metadata = MetaData
},
/**
* Updates the playback state of the MPRIS interface.
* @param {Object} attributes - The attributes of the track.
*/
updateState: (attributes) => {
if (process.platform !== "linux") return;
@ -94,6 +102,9 @@ module.exports = {
}
},
/**
* Closes the MPRIS interface.
*/
clearActivity: () => {
if (process.platform !== "linux") return;
mediaPlayer.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}