fix showing old lyrics if new lyrics couldn't be resolved

This commit is contained in:
Araxeus
2022-01-29 17:10:47 +02:00
parent 909036108f
commit eff0995d78

View File

@ -15,13 +15,22 @@ module.exports = () => {
return; return;
} }
let hasLyrics = true;
const html = ipcRenderer.sendSync( const html = ipcRenderer.sendSync(
"search-genius-lyrics", "search-genius-lyrics",
extractedSongInfo extractedSongInfo
); );
if (!html) { if (!html) {
// Delete previous lyrics if tab is open and couldn't get new lyrics
checkLyricsContainer(() => {
hasLyrics = false;
setTabsOnclick(undefined);
});
return; return;
} else if (is.dev()) { }
if (is.dev()) {
console.log("Fetched lyrics from Genius"); console.log("Fetched lyrics from Genius");
} }
@ -42,11 +51,7 @@ module.exports = () => {
enableLyricsTab(); enableLyricsTab();
for (tab of [tabs.upNext, tabs.discover]) { setTabsOnclick(enableLyricsTab);
if (tab) {
tab.onclick = enableLyricsTab;
}
}
checkLyricsContainer(); checkLyricsContainer();
@ -74,12 +79,22 @@ module.exports = () => {
function setLyrics(lyricsContainer) { function setLyrics(lyricsContainer) {
lyricsContainer.innerHTML = `<div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics"> lyricsContainer.innerHTML = `<div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics">
${lyrics} ${hasLyrics ? lyrics : 'Could not retrieve lyrics from genius'}
<yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="text-align: initial"></yt-formatted-string> <yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="text-align: initial"></yt-formatted-string>
</div>`; </div>`;
lyricsContainer.querySelector('.footer').textContent = 'Source: Genius'; if (hasLyrics) {
enableLyricsTab(); lyricsContainer.querySelector('.footer').textContent = 'Source: Genius';
enableLyricsTab();
}
}
function setTabsOnclick(callback) {
for (tab of [tabs.upNext, tabs.discover]) {
if (tab) {
tab.onclick = callback;
}
}
} }
function enableLyricsTab() { function enableLyricsTab() {