This commit is contained in:
2025-06-19 15:02:54 +09:00
parent ca31760728
commit 01c4c543fc
6 changed files with 267 additions and 105 deletions

View File

@@ -253,6 +253,24 @@ function setupAskAIEventListeners() {
handleAIResponse(event.detail);
});
// Listen for OAuth callback completion from iframe
window.addEventListener('message', function(event) {
if (event.data.type === 'oauth_success') {
console.log('Received OAuth success message:', event.data);
// Close any OAuth popups/iframes
const oauthFrame = document.getElementById('oauth-frame');
if (oauthFrame) {
oauthFrame.remove();
}
// Reload the page to refresh OAuth app state
setTimeout(() => {
window.location.reload();
}, 500);
}
});
// Track IME composition state
let isComposing = false;
const aiQuestionInput = document.getElementById('aiQuestion');
@@ -284,52 +302,8 @@ function setupAskAIEventListeners() {
});
}
// OAuth Callback handling
function handleOAuthCallback() {
// Check if we're on the callback page
if (window.location.pathname === '/oauth/callback') {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const error = urlParams.get('error');
if (error) {
console.error('OAuth error:', error);
// Redirect to home page with error
setTimeout(() => {
window.location.href = '/?oauth_error=' + encodeURIComponent(error);
}, 1000);
return;
}
if (code) {
console.log('OAuth callback successful, code received');
// Get the original page from localStorage or use home page
const originalPage = localStorage.getItem('oauth_original_page') || '/';
localStorage.removeItem('oauth_original_page');
// Wait a bit for OAuth app to process the callback
setTimeout(() => {
console.log('Redirecting back to:', originalPage);
window.location.href = originalPage;
}, 2000);
return;
}
}
// Store current page before OAuth if we're not on callback page
if (window.location.pathname !== '/oauth/callback') {
localStorage.setItem('oauth_original_page', window.location.href);
}
}
// Initialize Ask AI when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Handle OAuth callback first
handleOAuthCallback();
// Then initialize Ask AI
setupAskAIEventListeners();
console.log('Ask AI initialized successfully');
});