Merge branch 'local-upstream/master' into in-app-menu-icon

This commit is contained in:
Araxeus
2023-02-17 17:44:48 +02:00
9 changed files with 177 additions and 85 deletions

View File

@ -46,6 +46,7 @@ const defaultConfig = {
},
discord: {
enabled: false,
autoReconnect: true, // if enabled, will try to reconnect to discord every 5 seconds after disconnecting or failing to connect
activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below
activityTimoutTime: 10 * 60 * 1000, // 10 minutes
listenAlong: true, // add a "listen along" button to rich presence

View File

@ -486,13 +486,12 @@ function removeContentSecurityPolicy(
// Custom listener to tweak the content security policy
session.webRequest.onHeadersReceived(function (details, callback) {
if (
!details.responseHeaders["content-security-policy-report-only"] &&
!details.responseHeaders["content-security-policy"]
)
return callback({ cancel: false });
details.responseHeaders ??= {}
// Remove the content security policy
delete details.responseHeaders["content-security-policy-report-only"];
delete details.responseHeaders["content-security-policy"];
callback({ cancel: false, responseHeaders: details.responseHeaders });
});

View File

@ -35,8 +35,20 @@
"!plugins/touchbar${/*}"
],
"target": [
"nsis",
"portable"
{
"target": "nsis",
"arch": [
"x64",
"arm64"
]
},
{
"target": "portable",
"arch": [
"x64",
"arm64"
]
}
]
},
"nsis": {
@ -91,13 +103,14 @@
},
"engines": {
"node": ">=16.0.0",
"npm": "Please use yarn and not npm"
"npm": "Please use yarn instead"
},
"dependencies": {
"@cliqz/adblocker-electron": "^1.25.2",
"@ffmpeg/core": "^0.11.0",
"@ffmpeg/ffmpeg": "^0.11.6",
"@foobar404/wave": "^2.0.4",
"@xhayper/discord-rpc": "^1.0.15",
"async-mutex": "^0.4.0",
"browser-id3-writer": "^4.4.0",
"butterchurn": "^2.6.7",
@ -105,7 +118,6 @@
"chokidar": "^3.5.3",
"custom-electron-prompt": "^1.5.1",
"custom-electron-titlebar": "^4.1.6",
"discord-rpc": "^4.0.1",
"electron-better-web-request": "^1.0.1",
"electron-debug": "^3.2.0",
"electron-is": "^3.0.0",
@ -140,11 +152,6 @@
"playwright": "^1.29.2",
"xo": "^0.53.1"
},
"resolutions": {
"glob-parent": "5.1.2",
"minimist": "1.2.7",
"yargs-parser": "21.1.1"
},
"auto-changelog": {
"hideCredit": true,
"package": true,

View File

@ -1,4 +1,4 @@
module.exports = () => {
// Preload adblocker to inject scripts/styles
require("@cliqz/adblocker-electron-preload/dist/preload.cjs");
require("@cliqz/adblocker-electron-preload");
};

View File

@ -6,7 +6,7 @@ require("./fader");
let transitionAudio; // Howler audio used to fade out the current music
let firstVideo = true;
let transitioning = false;
let waitForTransition;
// Crossfade options that can be overridden in plugin options
let crossfadeOptions = {
@ -109,10 +109,9 @@ const syncVideoWithTransitionAudio = async () => {
const onApiLoaded = () => {
watchVideoIDChanges(async (videoID) => {
if (!transitioning) {
const url = await getStreamURL(videoID);
await createAudioForCrossfade(url);
}
await waitForTransition;
const url = await getStreamURL(videoID);
await createAudioForCrossfade(url);
});
};
@ -121,7 +120,11 @@ const crossfade = (cb) => {
cb();
return;
}
transitioning = true;
let resolveTransition;
waitForTransition = new Promise(function (resolve, reject) {
resolveTransition = resolve;
});
const video = document.querySelector("video");
@ -134,7 +137,7 @@ const crossfade = (cb) => {
// Fade out the music
video.volume = 0;
fader.fadeOut(() => {
transitioning = false;
resolveTransition();
cb();
});
};

View File

@ -1,4 +1,5 @@
const Discord = require("discord-rpc");
"use strict";
const Discord = require("@xhayper/discord-rpc");
const { dev } = require("electron-is");
const { dialog, app } = require("electron");
@ -9,58 +10,81 @@ const clientId = "1043858434585526382";
/**
* @typedef {Object} Info
* @property {import('discord-rpc').Client} rpc
* @property {import('@xhayper/discord-rpc').Client} rpc
* @property {boolean} ready
* @property {boolean} autoReconnect
* @property {import('../../providers/song-info').SongInfo} lastSongInfo
*/
/**
* @type {Info}
*/
const info = {
rpc: null,
rpc: new Discord.Client({
clientId
}),
ready: false,
autoReconnect: true,
lastSongInfo: null,
};
/**
* @type {(() => void)[]}
*/
const refreshCallbacks = [];
const resetInfo = () => {
info.rpc = null;
info.ready = false;
clearTimeout(clearActivity);
if (dev()) console.log("discord disconnected");
refreshCallbacks.forEach(cb => cb());
};
info.rpc.on("connected", () => {
if (dev()) console.log("discord connected");
refreshCallbacks.forEach(cb => cb());
});
info.rpc.on("ready", () => {
info.ready = true;
if (info.lastSongInfo) updateActivity(info.lastSongInfo)
});
info.rpc.on("disconnected", () => {
resetInfo();
if (info.autoReconnect) {
connectTimeout();
}
});
const connectTimeout = () => new Promise((resolve, reject) => setTimeout(() => {
if (!info.autoReconnect || info.rpc.isConnected) return;
info.rpc.login().then(resolve).catch(reject);
}, 5000));
const connectRecursive = () => {
if (!info.autoReconnect || info.rpc.isConnected) return;
connectTimeout().catch(connectRecursive);
}
let window;
const connect = (showErr = false) => {
if (info.rpc) {
if (info.rpc.isConnected) {
if (dev())
console.log('Attempted to connect with active RPC object');
console.log('Attempted to connect with active connection');
return;
}
info.rpc = new Discord.Client({
transport: "ipc",
});
info.ready = false;
info.rpc.once("connected", () => {
if (dev()) console.log("discord connected");
refreshCallbacks.forEach(cb => cb());
});
info.rpc.once("ready", () => {
info.ready = true;
if (info.lastSongInfo) updateActivity(info.lastSongInfo)
});
info.rpc.once("disconnected", resetInfo);
// Startup the rpc client
info.rpc.login({ clientId }).catch(err => {
resetInfo();
if (dev()) console.error(err);
if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' });
if (info.autoReconnect) {
connectRecursive();
}
else if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' });
});
};
@ -70,7 +94,9 @@ let clearActivity;
*/
let updateActivity;
module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong, hideDurationLeft }) => {
module.exports = (win, { autoReconnect, activityTimoutEnabled, activityTimoutTime, listenAlong, hideDurationLeft }) => {
info.autoReconnect = autoReconnect;
window = win;
// We get multiple events
// Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1)
@ -92,7 +118,7 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong,
// clear directly if timeout is 0
if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) {
info.rpc.clearActivity().catch(console.error);
info.rpc.user?.clearActivity().catch(console.error);
return;
}
@ -100,7 +126,6 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong,
// @see https://discord.com/developers/docs/topics/gateway#activity-object
// not all options are transfered through https://github.com/discordjs/RPC/blob/6f83d8d812c87cb7ae22064acd132600407d7d05/src/client.js#L518-530
const activityInfo = {
type: 2, // Listening, addressed in https://github.com/discordjs/RPC/pull/149
details: songInfo.title,
state: songInfo.artist,
largeImageKey: songInfo.imageSrc,
@ -116,7 +141,7 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong,
activityInfo.smallImageText = "Paused";
// Set start the timer so the activity gets cleared after a while if enabled
if (activityTimoutEnabled)
clearActivity = setTimeout(() => info.rpc.clearActivity().catch(console.error), activityTimoutTime ?? 10000);
clearActivity = setTimeout(() => info.rpc.user?.clearActivity().catch(console.error), activityTimoutTime ?? 10000);
} else if (!hideDurationLeft) {
// Add the start and end time of the song
const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000;
@ -125,7 +150,7 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong,
songStartTime + songInfo.songDuration * 1000;
}
info.rpc.setActivity(activityInfo).catch(console.error);
info.rpc.user?.setActivity(activityInfo).catch(console.error);
};
// If the page is ready, register the callback
@ -137,9 +162,10 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong,
};
module.exports.clear = () => {
if (info.rpc) info.rpc.clearActivity();
if (info.rpc) info.rpc.user?.clearActivity();
clearTimeout(clearActivity);
};
module.exports.connect = connect;
module.exports.registerRefresh = (cb) => refreshCallbacks.push(cb);
module.exports.isConnected = () => info.rpc !== null;

View File

@ -18,6 +18,15 @@ module.exports = (win, options, refreshMenu) => {
enabled: !isConnected(),
click: connect,
},
{
label: "Auto reconnect",
type: "checkbox",
checked: options.autoReconnect,
click: (item) => {
options.autoReconnect = item.checked;
setMenuOptions('discord', options);
},
},
{
label: "Clear activity",
click: clear,

View File

@ -82,7 +82,7 @@ const downloadVideoToMP3 = async (
sendFeedback("Download: " + progress + "%", ratio);
})
.on("info", (info, format) => {
videoName = info.videoDetails.title.replace("|", "").toString("ascii");
videoName = info.videoDetails.title.replaceAll("|", "").toString("ascii");
if (is.dev()) {
console.log(
"Downloading video - name:",

117
yarn.lock
View File

@ -1190,6 +1190,17 @@ __metadata:
languageName: node
linkType: hard
"@xhayper/discord-rpc@npm:^1.0.15":
version: 1.0.15
resolution: "@xhayper/discord-rpc@npm:1.0.15"
dependencies:
axios: ^1.2.1
discord-api-types: ^0.37.24
ws: ^8.11.0
checksum: a592f20e524ab6ef9b58f5125cd5b30cfd040e5f74f78f935afd88c3bd251523dcf5f599586f5bb24cf7e157fe370711d6109dbfb47fc312bd8890cef6b6d4ea
languageName: node
linkType: hard
"abbrev@npm:^1.0.0":
version: 1.1.1
resolution: "abbrev@npm:1.1.1"
@ -1634,6 +1645,17 @@ __metadata:
languageName: node
linkType: hard
"axios@npm:^1.2.1":
version: 1.3.2
resolution: "axios@npm:1.3.2"
dependencies:
follow-redirects: ^1.15.0
form-data: ^4.0.0
proxy-from-env: ^1.1.0
checksum: 9791af75a6df137b15ef45d13ad11eb357b3860d2496347ee18778db9d0abc2320362a4452f1e070e3160f1dbcc518fcefdc9e005be097e7db39acb22cf608e5
languageName: node
linkType: hard
"babel-runtime@npm:^6.26.0":
version: 6.26.0
resolution: "babel-runtime@npm:6.26.0"
@ -1674,7 +1696,7 @@ __metadata:
languageName: node
linkType: hard
"bindings@npm:^1.2.1, bindings@npm:^1.3.0":
"bindings@npm:^1.2.1":
version: 1.5.0
resolution: "bindings@npm:1.5.0"
dependencies:
@ -2683,17 +2705,10 @@ __metadata:
languageName: node
linkType: hard
"discord-rpc@npm:^4.0.1":
version: 4.0.1
resolution: "discord-rpc@npm:4.0.1"
dependencies:
node-fetch: ^2.6.1
register-scheme: "github:devsnek/node-register-scheme"
ws: ^7.3.1
dependenciesMeta:
register-scheme:
optional: true
checksum: f96e4e32751402c9a689b24eccfa319315995f8906bb86e167c6a94bc6466f3641b41f8a082ac5b4e92baa7cefdb3456e7c4d86ccd2d9373281c9a93b7335c56
"discord-api-types@npm:^0.37.24":
version: 0.37.33
resolution: "discord-api-types@npm:0.37.33"
checksum: d1e31106081ef79d3ea721b8991c5de155879e6d01c47a025b2c41e0496b551608e72e383caf23680938219099b6c3bd43cbacf48edeb7fc9a3c1730c1811ba8
languageName: node
linkType: hard
@ -3978,6 +3993,16 @@ __metadata:
languageName: node
linkType: hard
"follow-redirects@npm:^1.15.0":
version: 1.15.2
resolution: "follow-redirects@npm:1.15.2"
peerDependenciesMeta:
debug:
optional: true
checksum: faa66059b66358ba65c234c2f2a37fcec029dc22775f35d9ad6abac56003268baf41e55f9ee645957b32c7d9f62baf1f0b906e68267276f54ec4b4c597c2b190
languageName: node
linkType: hard
"for-each@npm:^0.3.3":
version: 0.3.3
resolution: "for-each@npm:0.3.3"
@ -4229,7 +4254,7 @@ __metadata:
languageName: node
linkType: hard
"glob-parent@npm:5.1.2":
"glob-parent@npm:^5.1.2, glob-parent@npm:~5.1.2":
version: 5.1.2
resolution: "glob-parent@npm:5.1.2"
dependencies:
@ -4238,6 +4263,15 @@ __metadata:
languageName: node
linkType: hard
"glob-parent@npm:^6.0.2":
version: 6.0.2
resolution: "glob-parent@npm:6.0.2"
dependencies:
is-glob: ^4.0.3
checksum: c13ee97978bef4f55106b71e66428eb1512e71a7466ba49025fc2aec59a5bfb0954d5abd58fc5ee6c9b076eef4e1f6d3375c2e964b88466ca390da4419a786a8
languageName: node
linkType: hard
"glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6":
version: 7.2.3
resolution: "glob@npm:7.2.3"
@ -6062,10 +6096,10 @@ __metadata:
languageName: node
linkType: hard
"minimist@npm:1.2.7":
version: 1.2.7
resolution: "minimist@npm:1.2.7"
checksum: 7346574a1038ca23c32e02252f603801f09384dd1d78b69a943a4e8c2c28730b80e96193882d3d3b22a063445f460e48316b29b8a25addca2d7e5e8f75478bec
"minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6":
version: 1.2.8
resolution: "minimist@npm:1.2.8"
checksum: 75a6d645fb122dad29c06a7597bddea977258957ed88d7a6df59b5cd3fe4a527e253e9bbf2e783e4b73657f9098b96a5fe96ab8a113655d4109108577ecf85b0
languageName: node
linkType: hard
@ -6242,7 +6276,7 @@ __metadata:
languageName: node
linkType: hard
"node-addon-api@npm:^1.3.0, node-addon-api@npm:^1.6.3":
"node-addon-api@npm:^1.6.3":
version: 1.7.2
resolution: "node-addon-api@npm:1.7.2"
dependencies:
@ -7055,6 +7089,13 @@ __metadata:
languageName: node
linkType: hard
"proxy-from-env@npm:^1.1.0":
version: 1.1.0
resolution: "proxy-from-env@npm:1.1.0"
checksum: ed7fcc2ba0a33404958e34d95d18638249a68c430e30fcb6c478497d72739ba64ce9810a24f53a7d921d0c065e5b78e3822759800698167256b04659366ca4d4
languageName: node
linkType: hard
"psl@npm:^1.1.28":
version: 1.9.0
resolution: "psl@npm:1.9.0"
@ -7305,16 +7346,6 @@ __metadata:
languageName: node
linkType: hard
"register-scheme@github:devsnek/node-register-scheme":
version: 0.0.2
resolution: "register-scheme@https://github.com/devsnek/node-register-scheme.git#commit=e7cc9a63a1f512565da44cb57316d9fb10750e17"
dependencies:
bindings: ^1.3.0
node-addon-api: ^1.3.0
checksum: e3281b9b81f5718ebc05c27988f6ef33bcd452048a414ad5862f29348d14513b988ec117cc73ef46955c40f78185aaec1430361dc1d1fe0a662eec864a2bf058
languageName: node
linkType: hard
"request-progress@npm:^2.0.1":
version: 2.0.1
resolution: "request-progress@npm:2.0.1"
@ -8733,18 +8764,18 @@ __metadata:
languageName: node
linkType: hard
"ws@npm:^7.3.1":
version: 7.5.9
resolution: "ws@npm:7.5.9"
"ws@npm:^8.11.0":
version: 8.12.0
resolution: "ws@npm:8.12.0"
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ^5.0.2
utf-8-validate: ">=5.0.2"
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
checksum: c3c100a181b731f40b7f2fddf004aa023f79d64f489706a28bc23ff88e87f6a64b3c6651fbec3a84a53960b75159574d7a7385709847a62ddb7ad6af76f49138
checksum: 818ff3f8749c172a95a114cceb8b89cedd27e43a82d65c7ad0f7882b1e96a2ee6709e3746a903c3fa88beec0c8bae9a9fcd75f20858b32a166dfb7519316a5d7
languageName: node
linkType: hard
@ -8879,13 +8910,29 @@ __metadata:
languageName: node
linkType: hard
"yargs-parser@npm:21.1.1":
"yargs-parser@npm:^20.2.9":
version: 20.2.9
resolution: "yargs-parser@npm:20.2.9"
checksum: 8bb69015f2b0ff9e17b2c8e6bfe224ab463dd00ca211eece72a4cd8a906224d2703fb8a326d36fdd0e68701e201b2a60ed7cf81ce0fd9b3799f9fe7745977ae3
languageName: node
linkType: hard
"yargs-parser@npm:^21.1.1":
version: 21.1.1
resolution: "yargs-parser@npm:21.1.1"
checksum: ed2d96a616a9e3e1cc7d204c62ecc61f7aaab633dcbfab2c6df50f7f87b393993fe6640d017759fe112d0cb1e0119f2b4150a87305cc873fd90831c6a58ccf1c
languageName: node
linkType: hard
"yargs-parser@npm:^4.2.0":
version: 4.2.1
resolution: "yargs-parser@npm:4.2.1"
dependencies:
camelcase: ^3.0.0
checksum: 955f7cd7fa25ee559ea4f3a4bfc5961ae38b340b32ff58834d043b4145c03f8d6a8891b31d258d55f63fb3c81415943e13f1dd45cef9bba05d2303e25e811030
languageName: node
linkType: hard
"yargs@npm:^17.5.1":
version: 17.6.2
resolution: "yargs@npm:17.6.2"
@ -8955,6 +9002,7 @@ __metadata:
"@ffmpeg/ffmpeg": ^0.11.6
"@foobar404/wave": ^2.0.4
"@playwright/test": ^1.29.2
"@xhayper/discord-rpc": ^1.0.15
async-mutex: ^0.4.0
auto-changelog: ^2.4.0
browser-id3-writer: ^4.4.0
@ -8964,7 +9012,6 @@ __metadata:
custom-electron-prompt: ^1.5.1
custom-electron-titlebar: ^4.1.6
del-cli: ^5.0.0
discord-rpc: ^4.0.1
electron: ^22.0.2
electron-better-web-request: ^1.0.1
electron-builder: ^23.6.0