fix google oauth

This commit is contained in:
paisley
2026-03-08 11:03:34 +08:00
parent 807df95e92
commit 38e8449ea2
14 changed files with 1125 additions and 89 deletions

View File

@@ -35,6 +35,7 @@ import { updateSkillConfig, getSkillConfig, getAllSkillConfigs } from '../utils/
import { whatsAppLoginManager } from '../utils/whatsapp-login';
import { getProviderConfig } from '../utils/provider-registry';
import { deviceOAuthManager, OAuthProviderType } from '../utils/device-oauth';
import { browserOAuthManager, type BrowserOAuthProviderType } from '../utils/browser-oauth';
import { applyProxySettings } from './proxy';
import { getRecentTokenUsageHistory } from '../utils/token-usage';
import { getProviderService } from '../services/providers/provider-service';
@@ -892,19 +893,24 @@ function registerWhatsAppHandlers(mainWindow: BrowserWindow): void {
*/
function registerDeviceOAuthHandlers(mainWindow: BrowserWindow): void {
deviceOAuthManager.setWindow(mainWindow);
browserOAuthManager.setWindow(mainWindow);
// Request Provider OAuth initialization
ipcMain.handle(
'provider:requestOAuth',
async (
_,
provider: OAuthProviderType,
provider: OAuthProviderType | BrowserOAuthProviderType,
region?: 'global' | 'cn',
options?: { accountId?: string; label?: string },
) => {
try {
logger.info(`provider:requestOAuth for ${provider}`);
await deviceOAuthManager.startFlow(provider, region, options);
if (provider === 'google') {
await browserOAuthManager.startFlow(provider, options);
} else {
await deviceOAuthManager.startFlow(provider, region, options);
}
return { success: true };
} catch (error) {
logger.error('provider:requestOAuth failed', error);
@@ -917,6 +923,7 @@ function registerDeviceOAuthHandlers(mainWindow: BrowserWindow): void {
ipcMain.handle('provider:cancelOAuth', async () => {
try {
await deviceOAuthManager.stopFlow();
await browserOAuthManager.stopFlow();
return { success: true };
} catch (error) {
logger.error('provider:cancelOAuth failed', error);
@@ -940,6 +947,10 @@ function registerProviderHandlers(gatewayManager: GatewayManager): void {
logger.info(`[IPC] Scheduling Gateway restart after ${provider} OAuth success for ${accountId}...`);
gatewayManager.debouncedRestart(8000);
});
browserOAuthManager.on('oauth:success', ({ provider, accountId }) => {
logger.info(`[IPC] Scheduling Gateway restart after ${provider} OAuth success for ${accountId}...`);
gatewayManager.debouncedRestart(8000);
});
// Get all providers with key info
ipcMain.handle('provider:list', async () => {