mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
refactor: webpack config (#11421)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@affine/core": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/nbstore": "workspace:*",
|
||||
"@blocksuite/affine": "workspace:*",
|
||||
|
||||
@@ -23,6 +23,7 @@ import { ClientSchemeProvider } from '@affine/core/modules/url/providers/client-
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import { WorkspacesService } from '@affine/core/modules/workspace';
|
||||
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
||||
import { getWorkerUrl } from '@affine/env/worker';
|
||||
import { I18n } from '@affine/i18n';
|
||||
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '@blocksuite/affine/adapters';
|
||||
@@ -51,11 +52,7 @@ import { AffineTheme } from './plugins/affine-theme';
|
||||
import { AIButton } from './plugins/ai-button';
|
||||
|
||||
const storeManagerClient = new StoreManagerClient(
|
||||
new OpClient(
|
||||
new Worker(
|
||||
new URL(/* webpackChunkName: "nbstore" */ './nbstore.ts', import.meta.url)
|
||||
)
|
||||
)
|
||||
new OpClient(new Worker(getWorkerUrl('nbstore.worker.js')))
|
||||
);
|
||||
window.addEventListener('beforeunload', () => {
|
||||
storeManagerClient.dispose();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"references": [
|
||||
{ "path": "../../component" },
|
||||
{ "path": "../../core" },
|
||||
{ "path": "../../../common/env" },
|
||||
{ "path": "../../i18n" },
|
||||
{ "path": "../../../common/nbstore" },
|
||||
{ "path": "../../../../blocksuite/affine/all" },
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export const config = {
|
||||
entry: {
|
||||
app: './src/app/index.tsx',
|
||||
shell: './src/shell/index.tsx',
|
||||
backgroundWorker: './src/background-worker/index.ts',
|
||||
popup: './src/popup/index.tsx',
|
||||
},
|
||||
};
|
||||
@@ -2,7 +2,13 @@ import path from 'node:path';
|
||||
|
||||
import type { _AsyncVersionOf } from 'async-call-rpc';
|
||||
import { AsyncCall } from 'async-call-rpc';
|
||||
import type { UtilityProcess, WebContents } from 'electron';
|
||||
import type {
|
||||
BaseWindow,
|
||||
OpenDialogOptions,
|
||||
SaveDialogOptions,
|
||||
UtilityProcess,
|
||||
WebContents,
|
||||
} from 'electron';
|
||||
import {
|
||||
app,
|
||||
dialog,
|
||||
@@ -57,7 +63,6 @@ class HelperProcessManager {
|
||||
this.ready = new Promise((resolve, reject) => {
|
||||
helperProcess.once('spawn', () => {
|
||||
try {
|
||||
this.#connectMain();
|
||||
logger.info('[helper] forked', helperProcess.pid);
|
||||
resolve();
|
||||
} catch (err) {
|
||||
@@ -91,11 +96,15 @@ class HelperProcessManager {
|
||||
|
||||
// bridge main <-> helper process
|
||||
// also set up the RPC to the helper process
|
||||
#connectMain() {
|
||||
const dialogMethods = pickAndBind(dialog, [
|
||||
'showOpenDialog',
|
||||
'showSaveDialog',
|
||||
]);
|
||||
connectMain(window: BaseWindow) {
|
||||
const dialogMethods = {
|
||||
showOpenDialog: async (opts: OpenDialogOptions) => {
|
||||
return dialog.showOpenDialog(window, opts);
|
||||
},
|
||||
showSaveDialog: async (opts: SaveDialogOptions) => {
|
||||
return dialog.showSaveDialog(window, opts);
|
||||
},
|
||||
};
|
||||
const shellMethods = pickAndBind(shell, [
|
||||
'openExternal',
|
||||
'showItemInFolder',
|
||||
|
||||
@@ -63,8 +63,6 @@ export class MainWindowManager {
|
||||
defaultHeight: 800,
|
||||
});
|
||||
|
||||
await ensureHelperProcess();
|
||||
|
||||
const browserWindow = new BrowserWindow({
|
||||
titleBarStyle: isMacOS()
|
||||
? 'hiddenInset'
|
||||
@@ -88,6 +86,8 @@ export class MainWindowManager {
|
||||
sandbox: false,
|
||||
},
|
||||
});
|
||||
const helper = await ensureHelperProcess();
|
||||
helper.connectMain(browserWindow);
|
||||
|
||||
if (isLinux()) {
|
||||
browserWindow.setIcon(
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@affine/core": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/nbstore": "workspace:*",
|
||||
"@blocksuite/affine": "workspace:*",
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
WorkspacesService,
|
||||
} from '@affine/core/modules/workspace';
|
||||
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
||||
import { getWorkerUrl } from '@affine/env/worker';
|
||||
import { I18n } from '@affine/i18n';
|
||||
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '@blocksuite/affine/adapters';
|
||||
@@ -414,12 +415,7 @@ export function App() {
|
||||
}
|
||||
|
||||
function createStoreManagerClient() {
|
||||
const worker = new Worker(
|
||||
new URL(
|
||||
/* webpackChunkName: "nbstore-worker" */ './worker.ts',
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
const worker = new Worker(getWorkerUrl('nbstore.worker.js'));
|
||||
const { port1: nativeDBApiChannelServer, port2: nativeDBApiChannelClient } =
|
||||
new MessageChannel();
|
||||
AsyncCall<typeof NbStoreNativeDBApis>(NbStoreNativeDBApis, {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"references": [
|
||||
{ "path": "../../component" },
|
||||
{ "path": "../../core" },
|
||||
{ "path": "../../../common/env" },
|
||||
{ "path": "../../i18n" },
|
||||
{ "path": "../../../common/nbstore" },
|
||||
{ "path": "../../../../blocksuite/affine/all" },
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@affine/core": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/nbstore": "workspace:*",
|
||||
"@blocksuite/affine": "workspace:*",
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
import { PopupWindowProvider } from '@affine/core/modules/url';
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
||||
import { getWorkerUrl } from '@affine/env/worker';
|
||||
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
||||
import { Framework, FrameworkRoot, getCurrentStore } from '@toeverything/infra';
|
||||
import { OpClient } from '@toeverything/infra/op';
|
||||
@@ -22,16 +23,12 @@ import { RouterProvider } from 'react-router-dom';
|
||||
|
||||
let storeManagerClient: StoreManagerClient;
|
||||
|
||||
const workerUrl = getWorkerUrl('nbstore.worker.js');
|
||||
if (window.SharedWorker) {
|
||||
const worker = new SharedWorker(
|
||||
new URL(/* webpackChunkName: "nbstore" */ './nbstore.ts', import.meta.url),
|
||||
{ name: 'affine-shared-worker' }
|
||||
);
|
||||
const worker = new SharedWorker(workerUrl, { name: 'affine-shared-worker' });
|
||||
storeManagerClient = new StoreManagerClient(new OpClient(worker.port));
|
||||
} else {
|
||||
const worker = new Worker(
|
||||
new URL(/* webpackChunkName: "nbstore" */ './nbstore.ts', import.meta.url)
|
||||
);
|
||||
const worker = new Worker(workerUrl);
|
||||
storeManagerClient = new StoreManagerClient(new OpClient(worker));
|
||||
}
|
||||
window.addEventListener('beforeunload', () => {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"references": [
|
||||
{ "path": "../../component" },
|
||||
{ "path": "../../core" },
|
||||
{ "path": "../../../common/env" },
|
||||
{ "path": "../../i18n" },
|
||||
{ "path": "../../../common/nbstore" },
|
||||
{ "path": "../../../../blocksuite/affine/all" },
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"@affine/component": "workspace:*",
|
||||
"@affine/core": "workspace:*",
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@affine/nbstore": "workspace:*",
|
||||
"@affine/track": "workspace:*",
|
||||
|
||||
@@ -12,6 +12,7 @@ import { PopupWindowProvider } from '@affine/core/modules/url';
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import { configureBrowserWorkspaceFlavours } from '@affine/core/modules/workspace-engine';
|
||||
import createEmotionCache from '@affine/core/utils/create-emotion-cache';
|
||||
import { getWorkerUrl } from '@affine/env/worker';
|
||||
import { StoreManagerClient } from '@affine/nbstore/worker/client';
|
||||
import { CacheProvider } from '@emotion/react';
|
||||
import { Framework, FrameworkRoot, getCurrentStore } from '@toeverything/infra';
|
||||
@@ -23,19 +24,16 @@ const cache = createEmotionCache();
|
||||
|
||||
let storeManagerClient: StoreManagerClient;
|
||||
|
||||
const workerUrl = getWorkerUrl('nbstore.worker.js');
|
||||
|
||||
if (
|
||||
window.SharedWorker &&
|
||||
localStorage.getItem('disableSharedWorker') !== 'true'
|
||||
) {
|
||||
const worker = new SharedWorker(
|
||||
new URL(/* webpackChunkName: "nbstore" */ './nbstore.ts', import.meta.url),
|
||||
{ name: 'affine-shared-worker' }
|
||||
);
|
||||
const worker = new SharedWorker(workerUrl);
|
||||
storeManagerClient = new StoreManagerClient(new OpClient(worker.port));
|
||||
} else {
|
||||
const worker = new Worker(
|
||||
new URL(/* webpackChunkName: "nbstore" */ './nbstore.ts', import.meta.url)
|
||||
);
|
||||
const worker = new Worker(workerUrl);
|
||||
storeManagerClient = new StoreManagerClient(new OpClient(worker));
|
||||
}
|
||||
window.addEventListener('beforeunload', () => {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"references": [
|
||||
{ "path": "../../component" },
|
||||
{ "path": "../../core" },
|
||||
{ "path": "../../../common/env" },
|
||||
{ "path": "../../i18n" },
|
||||
{ "path": "../../../common/nbstore" },
|
||||
{ "path": "../../track" },
|
||||
|
||||
Reference in New Issue
Block a user