feat: implement platform provider architecture and integrate into AppRoot

- Introduced a new platform provider architecture to manage platform-specific functionalities.
- Created `PlatformProvider`, `PlatformContext`, and related capabilities for handling downloads and key imports.
- Integrated the platform provider into `AppRoot`, allowing for dynamic platform management.
- Added error handling classes for unsupported and unimplemented methods.
- Updated tests to validate the new platform provider functionalities and capabilities.
This commit is contained in:
鲁树人 committed 2026-11-01 10:46:52 +09:00
1 parent d86323e38a
commit cc688b85bd
13 files changed
+483 -45

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import { AndroidImportType, type BatchDownloadType, type NativeImportType } from '~/platform/capabilities';
import { NotImplementedError, NotSupportedMethod } from '~/platform/errors';
import type { PlatformProvider } from '~/platform/PlatformProvider';
import type {
AndroidAdbImportOptions,
DownloadManyInput,
DownloadOneInput,
NativeImportResult,
PlatformCapabilities,
} from '~/platform/types';
import { detectBrowserDownloadTypes } from './detectDownloadCapabilities';
function notImplemented(capability: string): Promise<never> {
return Promise.reject(new NotImplementedError(capability));
}
function notSupported(capability: string): Promise<never> {
return Promise.reject(new NotSupportedMethod(capability));
}
/**
* In-browser `PlatformProvider`.
* Capabilities follow runtime File System Access / save-picker probing (no DirectWrite).
* crypto / settings / download currently throw `NotImplementedError` (not yet delegated to
* the existing worker / localStorage / download helpers).
* Native and ADB key import throw `NotSupportedMethod` (`nativeKeyAccess` empty, `androidKeyAccess` None).
*/
export function createBrowserProvider(): PlatformProvider {
const capabilities: PlatformCapabilities = Object.freeze({
downloadTypes: Object.freeze(detectBrowserDownloadTypes()),
androidKeyAccess: AndroidImportType.None,
nativeKeyAccess: Object.freeze([] as NativeImportType[]),
});
return {
id: 'browser',
capabilities,
crypto: {
request: () => notImplemented('crypto.request'),
enqueueDecrypt: () => notImplemented('crypto.enqueueDecrypt'),
},
settings: {
load: () => notImplemented('settings.load'),
save: () => notImplemented('settings.save'),
},
download: {
saveOne: (_input: DownloadOneInput) => notImplemented('download.saveOne'),
saveMany: (_type: BatchDownloadType, _input: DownloadManyInput) => notImplemented('download.saveMany'),
},
keys: {
importNative: (_targets: readonly NativeImportType[]): Promise<NativeImportResult> =>
notSupported('keys.importNative'),
importAndroidAdb: (_opts: AndroidAdbImportOptions): Promise<NativeImportResult> =>
notSupported('keys.importAndroidAdb'),
},
};
}