Skip to content

Commit

Permalink
feat(core): open desktop directly in subscription landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Apr 22, 2024
1 parent f70c827 commit c3d3b2d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { type ReactNode, useCallback } from 'react';
import { useSearchParams } from 'react-router-dom';

import * as styles from './styles.css';

Expand All @@ -15,11 +16,16 @@ const UpgradeSuccessLayout = ({
description?: ReactNode;
}) => {
const t = useAFFiNEI18N();
const [params] = useSearchParams();

const { jumpToIndex } = useNavigateHelper();
const { jumpToIndex, openInApp } = useNavigateHelper();
const openAffine = useCallback(() => {
jumpToIndex();
}, [jumpToIndex]);
if (params.get('schema')) {
openInApp(params.get('schema') ?? 'affine', 'bring-to-front');
} else {
jumpToIndex();
}
}, [jumpToIndex, openInApp, params]);

const subtitle = (
<div className={styles.leftContentText}>
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/core/src/hooks/use-navigate-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ export function useNavigateHelper() {
[navigate]
);

const openInApp = useCallback(
(schema: string, path: string) => {
const encodedUrl = encodeURIComponent(`${schema}://${path}`);
return navigate(`/open-app/url?schema=${schema}&url=${encodedUrl}`);
},
[navigate]
);

return useMemo(
() => ({
jumpToPage,
Expand All @@ -169,6 +177,7 @@ export function useNavigateHelper() {
jumpToCollections,
jumpToTags,
jumpToTag,
openInApp,
}),
[
jumpToPage,
Expand All @@ -183,6 +192,7 @@ export function useNavigateHelper() {
jumpToCollections,
jumpToTags,
jumpToTag,
openInApp,
]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export class SubscriptionStore extends Store {
}

async createCheckoutSession(input: CreateCheckoutSessionInput) {
const { successCallbackLink } = input;
if (successCallbackLink && environment.isDesktop) {
const url = new URL(successCallbackLink);
url.searchParams.set('schema', window.appInfo.schema);
input.successCallbackLink = url.toString();
}
const data = await this.gqlService.gql({
query: createCheckoutSessionMutation,
variables: { input },
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/electron/renderer/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { RouterProvider } from 'react-router-dom';
const desktopWhiteList = [
'/desktop-signin',
'/open-app/signin-redirect',
'/open-app/url',
'/upgrade-success',
'/ai-upgrade-success',
];
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/electron/src/main/deep-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ async function handleAffineUrl(url: string) {
if (urlObj.hostname === 'signin-redirect') {
await handleOauthJwt(url);
}
if (urlObj.hostname === 'bring-to-front') {
const mainWindow = await getMainWindow();
if (mainWindow) {
mainWindow.show();
}
}
}

async function handleOauthJwt(url: string) {
Expand Down

0 comments on commit c3d3b2d

Please sign in to comment.