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>
|
||||
window.addEventListener('message', function(event) {{
|
||||
if (event.origin !== window.location.origin) return;
|
||||
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
||||
setTimeout(() => window.close(), 300);
|
||||
}});
|
||||
|
|
@ -5734,7 +5733,7 @@ def _spotify_auth_success_page(detail_text: str) -> str:
|
|||
(function() {{
|
||||
try {{
|
||||
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) {{
|
||||
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
|
||||
await saveSettings();
|
||||
showToast('Spotify authentication started', 'success');
|
||||
window.open('/auth/spotify', '_blank');
|
||||
window._spotifyAuthWindow = window.open('/auth/spotify', '_blank');
|
||||
} catch (error) {
|
||||
console.error('Error authenticating Spotify:', error);
|
||||
showToast('Failed to start Spotify authentication', 'error', 'gs-connecting');
|
||||
|
|
|
|||
|
|
@ -3108,16 +3108,18 @@ async function _forceServiceStatusRefresh() {
|
|||
}
|
||||
|
||||
let _spotifyAuthCompletionListenerInstalled = false;
|
||||
window._spotifyAuthWindow = window._spotifyAuthWindow || null;
|
||||
|
||||
function initializeSpotifyAuthCompletionListener() {
|
||||
if (_spotifyAuthCompletionListenerInstalled) return;
|
||||
_spotifyAuthCompletionListenerInstalled = true;
|
||||
|
||||
window.addEventListener('message', async event => {
|
||||
if (event.origin !== window.location.origin) return;
|
||||
if (!event.data || event.data.type !== 'spotify-auth-complete') return;
|
||||
if (window._spotifyAuthWindow && event.source && event.source !== window._spotifyAuthWindow) return;
|
||||
|
||||
try {
|
||||
window._spotifyAuthWindow = null;
|
||||
await _forceServiceStatusRefresh();
|
||||
} catch (error) {
|
||||
console.warn('Could not refresh Spotify status after auth completion:', error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue