mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 12:45:55 +08:00
feat(core): open app in electron app entry (#8637)
fix PD-208 fix PD-210 fix PD-209 fix AF-1495
This commit is contained in:
@@ -6,10 +6,10 @@ import { buildType, isDev } from './config';
|
||||
import { logger } from './logger';
|
||||
import { uiSubjects } from './ui';
|
||||
import {
|
||||
addTab,
|
||||
addTabWithUrl,
|
||||
getMainWindow,
|
||||
loadUrlInActiveTab,
|
||||
openUrlInHiddenWindow,
|
||||
openUrlInMainWindow,
|
||||
showMainWindow,
|
||||
} from './windows-manager';
|
||||
|
||||
@@ -88,22 +88,11 @@ async function handleAffineUrl(url: string) {
|
||||
) {
|
||||
// @todo(@forehalo): refactor router utilities
|
||||
// basename of /workspace/xxx/yyy is /workspace/xxx
|
||||
const basename = urlObj.pathname.split('/').slice(0, 3).join('/');
|
||||
const pathname = '/' + urlObj.pathname.split('/').slice(3).join('/');
|
||||
|
||||
await addTab({
|
||||
basename,
|
||||
show: true,
|
||||
view: {
|
||||
path: {
|
||||
pathname: pathname,
|
||||
},
|
||||
},
|
||||
});
|
||||
await addTabWithUrl(url);
|
||||
} else {
|
||||
const hiddenWindow = urlObj.searchParams.get('hidden')
|
||||
? await openUrlInHiddenWindow(urlObj)
|
||||
: await openUrlInMainWindow(urlObj);
|
||||
: await loadUrlInActiveTab(url);
|
||||
|
||||
const main = await getMainWindow();
|
||||
if (main && hiddenWindow) {
|
||||
|
||||
@@ -273,15 +273,3 @@ export async function openUrlInHiddenWindow(urlObj: URL) {
|
||||
});
|
||||
return win;
|
||||
}
|
||||
|
||||
// TODO(@pengx17): somehow the page won't load the url passed, help needed
|
||||
export async function openUrlInMainWindow(urlObj: URL) {
|
||||
const url = transformToAppUrl(urlObj);
|
||||
logger.info('loading page at', url);
|
||||
const mainWindow = await getMainWindow();
|
||||
if (mainWindow) {
|
||||
await mainWindow.loadURL(url);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -932,7 +932,35 @@ export const isActiveTab = (wc: WebContents) => {
|
||||
WebContentViewsManager.instance.activeWorkbenchView?.webContents.id
|
||||
);
|
||||
};
|
||||
|
||||
// parse the full pathname to basename and pathname
|
||||
// eg: /workspace/xxx/yyy => { basename: '/workspace/xxx', pathname: '/yyy' }
|
||||
export const parseFullPathname = (url: string) => {
|
||||
const urlObj = new URL(url);
|
||||
const basename = urlObj.pathname.match(/\/workspace\/[^/]+/g)?.[0] ?? '/';
|
||||
return {
|
||||
basename,
|
||||
pathname: urlObj.pathname.slice(basename.length),
|
||||
search: urlObj.search,
|
||||
hash: urlObj.hash,
|
||||
};
|
||||
};
|
||||
|
||||
export const addTab = WebContentViewsManager.instance.addTab;
|
||||
export const addTabWithUrl = (url: string) => {
|
||||
const { basename, pathname, search, hash } = parseFullPathname(url);
|
||||
return addTab({
|
||||
basename,
|
||||
view: {
|
||||
path: { pathname, search, hash },
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const loadUrlInActiveTab = async (_url: string) => {
|
||||
// todo: implement
|
||||
throw new Error('loadUrlInActiveTab not implemented');
|
||||
};
|
||||
export const showTab = WebContentViewsManager.instance.showTab;
|
||||
export const closeTab = WebContentViewsManager.instance.closeTab;
|
||||
export const undoCloseTab = WebContentViewsManager.instance.undoCloseTab;
|
||||
|
||||
@@ -5,6 +5,8 @@ import { Telemetry } from '@affine/core/components/telemetry';
|
||||
import { router } from '@affine/core/desktop/router';
|
||||
import { configureCommonModules } from '@affine/core/modules';
|
||||
import { I18nProvider } from '@affine/core/modules/i18n';
|
||||
import { configureOpenInApp } from '@affine/core/modules/open-in-app';
|
||||
import { WebOpenInAppGuard } from '@affine/core/modules/open-in-app/views/open-in-app-guard';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { CustomThemeModifier } from '@affine/core/modules/theme-editor';
|
||||
import { PopupWindowProvider } from '@affine/core/modules/url';
|
||||
@@ -38,6 +40,7 @@ configureLocalStorageStateStorageImpls(framework);
|
||||
configureBrowserWorkspaceFlavours(framework);
|
||||
configureIndexedDBWorkspaceEngineStorageProvider(framework);
|
||||
configureIndexedDBUserspaceStorageProvider(framework);
|
||||
configureOpenInApp(framework);
|
||||
framework.impl(PopupWindowProvider, {
|
||||
open: (target: string) => {
|
||||
const targetUrl = new URL(target);
|
||||
@@ -75,11 +78,13 @@ export function App() {
|
||||
<Telemetry />
|
||||
<CustomThemeModifier />
|
||||
<GlobalLoading />
|
||||
<RouterProvider
|
||||
fallbackElement={<AppFallback key="RouterFallback" />}
|
||||
router={router}
|
||||
future={future}
|
||||
/>
|
||||
<WebOpenInAppGuard>
|
||||
<RouterProvider
|
||||
fallbackElement={<AppFallback key="RouterFallback" />}
|
||||
router={router}
|
||||
future={future}
|
||||
/>
|
||||
</WebOpenInAppGuard>
|
||||
</AffineContext>
|
||||
</I18nProvider>
|
||||
</CacheProvider>
|
||||
|
||||
Reference in New Issue
Block a user