feat(core): desktop multiple server support (#8979)

This commit is contained in:
EYHN
2024-12-03 05:51:09 +00:00
parent af81c95b85
commit 8963826463
137 changed files with 2052 additions and 1694 deletions

View File

@@ -15,7 +15,7 @@ import {
useNavigationType,
} from 'react-router-dom';
import { AuthService, ServersService } from '../../cloud';
import { AuthService, DefaultServerService, ServersService } from '../../cloud';
import type { DesktopApi } from '../entities/electron-api';
@OnEvent(ApplicationStarted, e => e.setupStartListener)
@@ -138,20 +138,26 @@ export class DesktopApiService extends Service {
}
private setupAuthRequestEvent() {
this.events.ui.onAuthenticationRequest(({ method, payload }) => {
this.events.ui.onAuthenticationRequest(({ method, payload, server }) => {
(async () => {
if (!(await this.api.handler.ui.isActiveTab())) {
return;
}
// TODO: support multiple servers
const affineCloudServer = this.framework
.get(ServersService)
.server$('affine-cloud').value;
if (!affineCloudServer) {
// Dynamically get these services to avoid circular dependencies
const serversService = this.framework.get(ServersService);
const defaultServerService = this.framework.get(DefaultServerService);
let targetServer;
if (server) {
targetServer = await serversService.addOrGetServerByBaseUrl(server);
} else {
targetServer = defaultServerService.server;
}
if (!targetServer) {
throw new Error('Affine Cloud server not found');
}
const authService = affineCloudServer.scope.get(AuthService);
const authService = targetServer.scope.get(AuthService);
switch (method) {
case 'magic-link': {