Fix Spotify auth completion sync
- Make the Spotify auth completion popup notify the opener across callback origins. - Refresh service status in the settings UI after auth completes so the button flips to Disconnect immediately. - Keep the standalone callback instruction page and the main app flow working with the same completion signal.
This commit is contained in:
parent
74e3cc460c
commit
f733744f91
3 changed files with 5 additions and 4 deletions
|
|
@ -5539,7 +5539,6 @@ def auth_spotify():
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.addEventListener('message', function(event) {{
|
window.addEventListener('message', function(event) {{
|
||||||
if (event.origin !== window.location.origin) return;
|
|
||||||
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
||||||
setTimeout(() => window.close(), 300);
|
setTimeout(() => window.close(), 300);
|
||||||
}});
|
}});
|
||||||
|
|
@ -5734,7 +5733,7 @@ def _spotify_auth_success_page(detail_text: str) -> str:
|
||||||
(function() {{
|
(function() {{
|
||||||
try {{
|
try {{
|
||||||
if (window.opener && !window.opener.closed) {{
|
if (window.opener && !window.opener.closed) {{
|
||||||
window.opener.postMessage({{ type: 'spotify-auth-complete' }}, window.location.origin);
|
window.opener.postMessage({{ type: 'spotify-auth-complete' }}, '*');
|
||||||
}}
|
}}
|
||||||
}} catch (error) {{
|
}} catch (error) {{
|
||||||
console.warn('Unable to notify opener about Spotify auth completion', error);
|
console.warn('Unable to notify opener about Spotify auth completion', error);
|
||||||
|
|
|
||||||
|
|
@ -3079,7 +3079,7 @@ async function authenticateSpotify() {
|
||||||
// Save settings first to ensure client_id/client_secret are persisted
|
// Save settings first to ensure client_id/client_secret are persisted
|
||||||
await saveSettings();
|
await saveSettings();
|
||||||
showToast('Spotify authentication started', 'success');
|
showToast('Spotify authentication started', 'success');
|
||||||
window.open('/auth/spotify', '_blank');
|
window._spotifyAuthWindow = window.open('/auth/spotify', '_blank');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error authenticating Spotify:', error);
|
console.error('Error authenticating Spotify:', error);
|
||||||
showToast('Failed to start Spotify authentication', 'error', 'gs-connecting');
|
showToast('Failed to start Spotify authentication', 'error', 'gs-connecting');
|
||||||
|
|
|
||||||
|
|
@ -3108,16 +3108,18 @@ async function _forceServiceStatusRefresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let _spotifyAuthCompletionListenerInstalled = false;
|
let _spotifyAuthCompletionListenerInstalled = false;
|
||||||
|
window._spotifyAuthWindow = window._spotifyAuthWindow || null;
|
||||||
|
|
||||||
function initializeSpotifyAuthCompletionListener() {
|
function initializeSpotifyAuthCompletionListener() {
|
||||||
if (_spotifyAuthCompletionListenerInstalled) return;
|
if (_spotifyAuthCompletionListenerInstalled) return;
|
||||||
_spotifyAuthCompletionListenerInstalled = true;
|
_spotifyAuthCompletionListenerInstalled = true;
|
||||||
|
|
||||||
window.addEventListener('message', async event => {
|
window.addEventListener('message', async event => {
|
||||||
if (event.origin !== window.location.origin) return;
|
|
||||||
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
||||||
|
if (window._spotifyAuthWindow && event.source && event.source !== window._spotifyAuthWindow) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
window._spotifyAuthWindow = null;
|
||||||
await _forceServiceStatusRefresh();
|
await _forceServiceStatusRefresh();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Could not refresh Spotify status after auth completion:', error);
|
console.warn('Could not refresh Spotify status after auth completion:', error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue