Skip to content

Commit

Permalink
fix: toggle ext. on/off causing weird ui overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed Oct 28, 2023
1 parent dba39ec commit 2ef7752
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/actions/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ async function load() {
document.addEventListener('app.enabled', async e => {
const { enabled } = e.detail

const enabledFromSession = JSON.parse(sessionStorage.getItem('enabled'))
sessionStorage.setItem('enabled', enabled)
video.active = enabled

if (enabledFromSession === enabled) return
enabled ? await app.connect() : app.disconnect()
})

Expand Down
5 changes: 2 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ chrome.storage.onChanged.addListener(async changes => {

if (!changedKey) return

if (['now-playing', 'enabled'].includes(changedKey)) {
popupPort?.postMessage({ type: changedKey, data: changes[changedKey].newValue })
if (changedKey == 'now-playing') return
if (changedKey == 'now-playing' && ENABLED) {
return popupPort?.postMessage({ type: changedKey, data: changes[changedKey].newValue })
}

if (changedKey == 'enabled') {
Expand Down
26 changes: 11 additions & 15 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ function sortByContrast(background, colors) {
return sortedColors
}

async function updatePopupUIState(popupState) {
await setState({ key: 'popup-ui', value: popupState })
}

async function updateBackgroundAndTextColours({ imageElement, title, artists }) {
const { cover, chorusPopup } = getElements()

Expand All @@ -208,22 +212,14 @@ async function updateBackgroundAndTextColours({ imageElement, title, artists })
const nextPrimary = sortByContrast(background, sortedPalette.slice(1).filter(x => x.percentage > 0)).at(0)

const textColor = getContrastColor(background.base, nextPrimary.base)
chorusPopup.style.backgroundColor = background.color

cover.src = imageElement.src
setTrackInfo({ title, artists, textColor })
const backgroundColor = background.color
chorusPopup.style.backgroundColor = backgroundColor

await setState({
key: 'popup-ui',
value: {
title,
artists,
textColor,
src: imageElement.src,
backgroundColor: background.color,
}
})
const src = imageElement.src
cover.src = src

setTrackInfo({ title, artists, textColor })
await updatePopupUIState({ title, artists, textColor, src, backgroundColor })
return { textColor }
}

Expand Down Expand Up @@ -373,7 +369,7 @@ function loadDefaultUI(enabled) {

setTrackInfo({ title, artists: 'Chorus - Spotify Enhancer' })

chorusPopup.style.backgroundColor = '#1DD760'
chorusPopup.style.backgroundColor = '#1ED760'
extToggle.setFill('#000')
}

Expand Down

0 comments on commit 2ef7752

Please sign in to comment.