mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
1d36e2e4b2
#### PR Dependency Tree * **PR #15317** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Virtualized mobile navigation with shell navigation and interactive swipe menus; coordinated mobile back handling with interactive phases/state restoration. * Added shared auth request proxy and message-port based token handling across mobile and worker flows. * **Bug Fixes** * Hydrated remote worker error stacks for calls and observable errors. * Improved SQLite FTS/indexer and nbstore optional text handling; refined docs-search ref parsing and notification loading/retry. * **Refactor / UX** * Modal focus-preservation and pointer behavior updates; improved mobile menu controls and back gesture plugins. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import './setup-worker';
|
|
|
|
import { MessagePortAuthProvider } from '@affine/mobile-shared/auth/channel';
|
|
import { installAuthRequestProxy } from '@affine/mobile-shared/auth/request';
|
|
import { broadcastChannelStorages } from '@affine/nbstore/broadcast-channel';
|
|
import {
|
|
cloudStorages,
|
|
configureSocketAuthMethod,
|
|
} from '@affine/nbstore/cloud';
|
|
import { idbStoragesIndexerOnly } from '@affine/nbstore/idb';
|
|
import {
|
|
bindNativeDBApis,
|
|
type NativeDBApis,
|
|
sqliteStorages,
|
|
} from '@affine/nbstore/sqlite';
|
|
import {
|
|
StoreManagerConsumer,
|
|
type WorkerManagerOps,
|
|
} from '@affine/nbstore/worker/consumer';
|
|
import { type MessageCommunicapable, OpConsumer } from '@toeverything/infra/op';
|
|
import { AsyncCall } from 'async-call-rpc';
|
|
|
|
const authProvider = new MessagePortAuthProvider();
|
|
installAuthRequestProxy(authProvider);
|
|
|
|
configureSocketAuthMethod((endpoint, cb) => {
|
|
authProvider
|
|
.getValidAccessToken(endpoint)
|
|
.then(token => cb(token ? { token, tokenType: 'jwt' } : {}))
|
|
.catch(() => cb({ error: 'AUTH_SESSION_TEMPORARILY_UNAVAILABLE' }));
|
|
});
|
|
|
|
globalThis.addEventListener('message', e => {
|
|
if (e.data.type === 'auth-access-token-channel') {
|
|
authProvider.setPort(e.ports[0] as MessagePort);
|
|
return;
|
|
}
|
|
|
|
if (e.data.type === 'native-db-api-channel') {
|
|
const port = e.ports[0] as MessagePort;
|
|
const rpc = AsyncCall<NativeDBApis>(
|
|
{},
|
|
{
|
|
channel: {
|
|
on(listener) {
|
|
const f = (e: MessageEvent<any>) => {
|
|
listener(e.data);
|
|
};
|
|
port.addEventListener('message', f);
|
|
return () => {
|
|
port.removeEventListener('message', f);
|
|
};
|
|
},
|
|
send(data) {
|
|
port.postMessage(data);
|
|
},
|
|
},
|
|
}
|
|
);
|
|
bindNativeDBApis(rpc);
|
|
port.start();
|
|
}
|
|
});
|
|
|
|
const consumer = new OpConsumer<WorkerManagerOps>(
|
|
globalThis as MessageCommunicapable
|
|
);
|
|
|
|
const storeManager = new StoreManagerConsumer([
|
|
...idbStoragesIndexerOnly,
|
|
...sqliteStorages,
|
|
...broadcastChannelStorages,
|
|
...cloudStorages,
|
|
]);
|
|
|
|
storeManager.bindConsumer(consumer);
|