feat: integrate platform provider with enhanced crypto handling and new AppLayout component

- Added a new `AppLayout` component to manage navigation and routing within the application.
- Refactored `AppRoot` to utilize `PlatformLoadGuard` for ensuring platform readiness before rendering.
- Introduced `useAppStore` hook for accessing the Redux store directly.
- Updated `SDKVersion` and `PanelQingTing` components to leverage the new platform provider for crypto operations.
- Enhanced error handling with `PlatformNotInitializedError` for better user feedback on uninitialized platform states.
- Added tests for new functionalities and ensured compatibility with the updated platform architecture.
This commit is contained in:
鲁树人 committed 2026-11-01 11:18:24 +09:00
1 parent cb5531e9e4
commit b5fdc8ebbe
18 files changed
+466 -102

No files matched your search

+43 -6
View File
@@ -1,5 +1,5 @@
import { AndroidImportType, type BatchDownloadType, type NativeImportType } from '~/platform/capabilities';
import { NotImplementedError, NotSupportedMethod } from '~/platform/errors';
import { NotImplementedError, NotSupportedMethod, PlatformNotInitializedError } from '~/platform/errors';
import type { PlatformProvider } from '~/platform/PlatformProvider';
import type {
AndroidAdbImportOptions,
@@ -8,6 +8,7 @@ import type {
NativeImportResult,
PlatformCapabilities,
} from '~/platform/types';
import { loadDecryptWorkerCrypto, type BrowserCrypto } from './browserCrypto';
import { createBrowserSettingsIo, DEFAULT_SETTINGS_STORAGE_KEY, type SettingsStorage } from './browserSettingsIo';
import { detectBrowserDownloadTypes } from './detectDownloadCapabilities';
@@ -24,14 +25,21 @@ export interface BrowserProviderOptions {
settingsStorage?: SettingsStorage;
/** Defaults to `um-react-settings`. */
settingsStorageKey?: string;
/**
* Injected crypto backend (tests). When set, `crypto.*` works without loading the worker
* and `init()` resolves immediately.
*/
crypto?: BrowserCrypto;
/** Defaults to dynamic-importing decrypt-worker/client. Injected in tests. */
loadCrypto?: () => Promise<BrowserCrypto>;
}
/**
* In-browser `PlatformProvider`.
* Capabilities follow runtime File System Access / save-picker probing (no DirectWrite).
* `settings` persists production settings via localStorage (or injected storage).
* crypto / download currently throw `NotImplementedError` (not yet delegated to
* the existing worker / download helpers).
* `crypto` binds to the decrypt worker only inside `init()` (dynamic import; no construct-time Worker).
* `download` currently throws `NotImplementedError` (not yet delegated to download helpers).
* Native and ADB key import throw `NotSupportedMethod` (`nativeKeyAccess` empty, `androidKeyAccess` None).
*/
export function createBrowserProvider(options: BrowserProviderOptions = {}): PlatformProvider {
@@ -46,15 +54,44 @@ export function createBrowserProvider(options: BrowserProviderOptions = {}): Pla
options.settingsStorageKey ?? DEFAULT_SETTINGS_STORAGE_KEY,
);
const loadCrypto = options.loadCrypto ?? loadDecryptWorkerCrypto;
let backend: BrowserCrypto | null = options.crypto ?? null;
let initPromise: Promise<void> | null = options.crypto ? Promise.resolve() : null;
async function requireBackend(capability: string): Promise<BrowserCrypto> {
if (backend) {
return backend;
}
if (initPromise) {
await initPromise;
if (backend) {
return backend;
}
}
throw new PlatformNotInitializedError(capability);
}
const crypto: BrowserCrypto = {
request: (action, payload) => requireBackend('crypto.request').then((api) => api.request(action, payload)),
enqueueDecrypt: (payload, onPreProcess) =>
requireBackend('crypto.enqueueDecrypt').then((api) => api.enqueueDecrypt(payload, onPreProcess)),
};
return {
id: 'browser',
capabilities,
crypto: {
request: () => notImplemented('crypto.request'),
enqueueDecrypt: () => notImplemented('crypto.enqueueDecrypt'),
init(): Promise<void> {
if (!initPromise) {
initPromise = loadCrypto().then((loaded) => {
backend = loaded;
});
}
return initPromise;
},
crypto,
settings: {
load: () => settingsIo.load(),
save: (settings) => settingsIo.save(settings),