mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
Merge branch 'master' into update-custom-electron-titlebar
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { edit } = require("../../config");
|
||||
const prompt = require("custom-electron-prompt");
|
||||
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
const promptOptions = require("../../providers/prompt-options");
|
||||
const { clear, connect, registerRefresh, isConnected } = require("./back");
|
||||
|
||||
let hasRegisterred = false;
|
||||
@ -26,7 +28,7 @@ module.exports = (win, options, refreshMenu) => {
|
||||
checked: options.activityTimoutEnabled,
|
||||
click: (item) => {
|
||||
options.activityTimoutEnabled = item.checked;
|
||||
setOptions('discord', options);
|
||||
setMenuOptions('discord', options);
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -35,13 +37,29 @@ module.exports = (win, options, refreshMenu) => {
|
||||
checked: options.listenAlong,
|
||||
click: (item) => {
|
||||
options.listenAlong = item.checked;
|
||||
setOptions('discord', options);
|
||||
setMenuOptions('discord', options);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Set timeout time in config",
|
||||
// open config.json
|
||||
click: edit,
|
||||
label: "Set inactivity timeout",
|
||||
click: () => setInactivityTimeout(win, options),
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
async function setInactivityTimeout(win, options) {
|
||||
let output = await prompt({
|
||||
title: 'Set Inactivity Timeout',
|
||||
label: 'Enter inactivity timeout in seconds:',
|
||||
value: Math.round((options.activityTimoutTime ?? 0) / 1e3),
|
||||
type: "counter",
|
||||
counterOptions: { minimum: 0, multiFire: true },
|
||||
width: 450,
|
||||
...promptOptions()
|
||||
}, win)
|
||||
|
||||
if (output) {
|
||||
options.activityTimoutTime = Math.round(output * 1e3);
|
||||
setMenuOptions("discord", options);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ const ytpl = require("ytpl");
|
||||
const chokidar = require('chokidar');
|
||||
const filenamify = require('filenamify');
|
||||
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
const { sendError } = require("./back");
|
||||
const { defaultMenuDownloadLabel, getFolder, presets, setBadge } = require("./utils");
|
||||
|
||||
@ -49,7 +49,7 @@ module.exports = (win, options) => {
|
||||
});
|
||||
if (result) {
|
||||
options.downloadFolder = result[0];
|
||||
setOptions("downloader", options);
|
||||
setMenuOptions("downloader", options);
|
||||
} // else = user pressed cancel
|
||||
},
|
||||
},
|
||||
@ -60,7 +60,7 @@ module.exports = (win, options) => {
|
||||
type: "radio",
|
||||
click: () => {
|
||||
options.preset = preset;
|
||||
setOptions("downloader", options);
|
||||
setMenuOptions("downloader", options);
|
||||
},
|
||||
checked: options.preset === preset || presets[preset] === undefined,
|
||||
})),
|
||||
|
||||
@ -3,20 +3,34 @@ const is = require("electron-is");
|
||||
|
||||
module.exports = () => {
|
||||
ipcRenderer.on("update-song-info", (_, extractedSongInfo) => {
|
||||
const lyricsTab = document.querySelector('tp-yt-paper-tab[tabindex="-1"]');
|
||||
const tabList = document.querySelectorAll("tp-yt-paper-tab");
|
||||
const tabs = {
|
||||
upNext: tabList[0],
|
||||
lyrics: tabList[1],
|
||||
discover: tabList[2],
|
||||
}
|
||||
|
||||
// Check if disabled
|
||||
if (!lyricsTab || !lyricsTab.hasAttribute("disabled")) {
|
||||
if (!tabs.lyrics?.hasAttribute("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hasLyrics = true;
|
||||
|
||||
const html = ipcRenderer.sendSync(
|
||||
"search-genius-lyrics",
|
||||
extractedSongInfo
|
||||
);
|
||||
if (!html) {
|
||||
// Delete previous lyrics if tab is open and couldn't get new lyrics
|
||||
checkLyricsContainer(() => {
|
||||
hasLyrics = false;
|
||||
setTabsOnclick(undefined);
|
||||
});
|
||||
return;
|
||||
} else if (is.dev()) {
|
||||
}
|
||||
|
||||
if (is.dev()) {
|
||||
console.log("Fetched lyrics from Genius");
|
||||
}
|
||||
|
||||
@ -35,27 +49,16 @@ module.exports = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
lyricsTab.removeAttribute("disabled");
|
||||
lyricsTab.removeAttribute("aria-disabled");
|
||||
document.querySelector("tp-yt-paper-tab").onclick = () => {
|
||||
lyricsTab.removeAttribute("disabled");
|
||||
lyricsTab.removeAttribute("aria-disabled");
|
||||
};
|
||||
enableLyricsTab();
|
||||
|
||||
lyricsTab.onclick = () => {
|
||||
setTabsOnclick(enableLyricsTab);
|
||||
|
||||
checkLyricsContainer();
|
||||
|
||||
tabs.lyrics.onclick = () => {
|
||||
const tabContainer = document.querySelector("ytmusic-tab-renderer");
|
||||
const observer = new MutationObserver((_, observer) => {
|
||||
const lyricsContainer = document.querySelector(
|
||||
'[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer'
|
||||
);
|
||||
if (lyricsContainer) {
|
||||
lyricsContainer.innerHTML = `<div id="contents" class="style-scope ytmusic-section-list-renderer genius-lyrics">
|
||||
${lyrics}
|
||||
|
||||
<yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer">Source : Genius</yt-formatted-string>
|
||||
</div>`;
|
||||
observer.disconnect();
|
||||
}
|
||||
checkLyricsContainer(() => observer.disconnect());
|
||||
});
|
||||
observer.observe(tabContainer, {
|
||||
attributes: true,
|
||||
@ -63,5 +66,41 @@ module.exports = () => {
|
||||
subtree: true,
|
||||
});
|
||||
};
|
||||
|
||||
function checkLyricsContainer(callback = () => {}) {
|
||||
const lyricsContainer = document.querySelector(
|
||||
'[page-type="MUSIC_PAGE_TYPE_TRACK_LYRICS"] > ytmusic-message-renderer'
|
||||
);
|
||||
if (lyricsContainer) {
|
||||
callback();
|
||||
setLyrics(lyricsContainer)
|
||||
}
|
||||
}
|
||||
|
||||
function setLyrics(lyricsContainer) {
|
||||
lyricsContainer.innerHTML =
|
||||
`<div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics">
|
||||
${hasLyrics ? lyrics : 'Could not retrieve lyrics from genius'}
|
||||
|
||||
</div>
|
||||
<yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="align-self: baseline"></yt-formatted-string>`;
|
||||
if (hasLyrics) {
|
||||
lyricsContainer.querySelector('.footer').textContent = 'Source: Genius';
|
||||
enableLyricsTab();
|
||||
}
|
||||
}
|
||||
|
||||
function setTabsOnclick(callback) {
|
||||
for (const tab of [tabs.upNext, tabs.discover]) {
|
||||
if (tab) {
|
||||
tab.onclick = callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function enableLyricsTab() {
|
||||
tabs.lyrics.removeAttribute("disabled");
|
||||
tabs.lyrics.removeAttribute("aria-disabled");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -6,8 +6,7 @@
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#contents.genius-lyrics {
|
||||
font-size: 1vw;
|
||||
opacity: 0.9;
|
||||
text-align: center;
|
||||
.description {
|
||||
font-size: 1.1vw !important;
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
const path = require("path");
|
||||
const { app } = require("electron");
|
||||
const fs = require("fs");
|
||||
@ -15,7 +15,7 @@ module.exports.icons = {
|
||||
|
||||
module.exports.setOption = (options, option, value) => {
|
||||
options[option] = value;
|
||||
setOptions("notifications", options)
|
||||
setMenuOptions("notifications", options)
|
||||
}
|
||||
|
||||
module.exports.urgencyLevels = [
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const { ipcRenderer } = require("electron");
|
||||
const { globalShortcut } = require('@electron/remote');
|
||||
|
||||
const { setOptions, isEnabled } = require("../../config/plugins");
|
||||
const { setOptions, setMenuOptions, isEnabled } = require("../../config/plugins");
|
||||
|
||||
function $(selector) { return document.querySelector(selector); }
|
||||
let api;
|
||||
@ -48,7 +48,7 @@ function firstRun(options) {
|
||||
for (option in newOptions) {
|
||||
options[option] = newOptions[option];
|
||||
}
|
||||
setOptions("precise-volume", options);
|
||||
setMenuOptions("precise-volume", options);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { enabled } = require("./back");
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
const prompt = require("custom-electron-prompt");
|
||||
const promptOptions = require("../../providers/prompt-options");
|
||||
|
||||
@ -11,7 +11,7 @@ function changeOptions(changedOptions, options, win) {
|
||||
if (enabled()) {
|
||||
win.webContents.send("setOptions", changedOptions);
|
||||
} else { // Fallback to usual method if disabled
|
||||
setOptions("precise-volume", options);
|
||||
setMenuOptions("precise-volume", options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
const prompt = require("custom-electron-prompt");
|
||||
const promptOptions = require("../../providers/prompt-options");
|
||||
|
||||
@ -20,7 +20,7 @@ function setOption(options, key = null, newValue = null) {
|
||||
options[key] = newValue;
|
||||
}
|
||||
|
||||
setOptions("shortcuts", options);
|
||||
setMenuOptions("shortcuts", options);
|
||||
}
|
||||
|
||||
// Helper function for keybind prompt
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { setMenuOptions } = require("../../config/plugins");
|
||||
|
||||
module.exports = (win, options) => [
|
||||
{
|
||||
@ -7,7 +7,7 @@ module.exports = (win, options) => [
|
||||
checked: options.forceHide,
|
||||
click: item => {
|
||||
options.forceHide = item.checked;
|
||||
setOptions("video-toggle", options);
|
||||
setMenuOptions("video-toggle", options);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user