Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(electron): add dedicated api for opening external links in the default browser (#6166)

Peng Xiao386bd033afb4
diff --git a/packages/frontend/core/src/utils/cloud-utils.tsx b/packages/frontend/core/src/utils/cloud-utils.tsx
index b70951a8d1..32ffdbc081 100644
--- a/packages/frontend/core/src/utils/cloud-utils.tsx
+++ b/packages/frontend/core/src/utils/cloud-utils.tsx
@@ -1,3 +1,4 @@
+import { apis } from '@affine/electron-api';
import {
generateRandUTF16Chars,
getBaseUrl,
@@ -62,13 +63,12 @@ export const signInCloud = async (
.catch(err => onRejectHandleTrace(err, traceParams));
} else if (OAuthProviderType[provider]) {
if (environment.isDesktop) {
- open(
+ await apis?.ui.openExternal(
`${
runtimeConfig.serverUrlPrefix
}/desktop-signin?provider=${provider}&redirect_uri=${buildRedirectUri(
'/open-app/signin-redirect'
- )}`,
- '_target'
+ )}`
);
} else {
location.href = `${
diff --git a/packages/frontend/electron/src/main/ui/handlers.ts b/packages/frontend/electron/src/main/ui/handlers.ts
index 6cfcdcc7f5..b43e40b29a 100644
--- a/packages/frontend/electron/src/main/ui/handlers.ts
+++ b/packages/frontend/electron/src/main/ui/handlers.ts
@@ -1,4 +1,4 @@
-import { app, nativeTheme } from 'electron';
+import { app, nativeTheme, shell } from 'electron';
import { getLinkPreview } from 'link-preview-js';
import { isMacOS } from '../../shared/utils';
@@ -122,4 +122,7 @@ export const uiHandlers = {
};
}
},
+ openExternal(_, url: string) {
+ return shell.openExternal(url);
+ },
} satisfies NamespaceHandlers;