From cc688b85bdb0a6e5303aeeede86be7afadbe0112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 1 Nov 2026 10:46:52 +0900 Subject: [PATCH] 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. --- src/components/AppRoot.tsx | 91 ++++++++++--------- src/platform/PlatformContext.tsx | 20 ++++ src/platform/PlatformProvider.ts | 59 ++++++++++++ .../__tests__/BrowserProvider.test.ts | 51 +++++++++++ src/platform/__tests__/capabilities.test.ts | 76 ++++++++++++++++ src/platform/browser/BrowserProvider.ts | 61 +++++++++++++ .../browser/detectDownloadCapabilities.ts | 18 ++++ src/platform/capabilities.ts | 25 +++++ src/platform/createPlatformProvider.ts | 10 ++ src/platform/errors.ts | 32 +++++++ src/platform/platformSingleton.ts | 15 +++ src/platform/types.ts | 50 ++++++++++ src/test-utils/test-helper.tsx | 20 +++- 13 files changed, 483 insertions(+), 45 deletions(-) create mode 100644 src/platform/PlatformContext.tsx create mode 100644 src/platform/PlatformProvider.ts create mode 100644 src/platform/__tests__/BrowserProvider.test.ts create mode 100644 src/platform/__tests__/capabilities.test.ts create mode 100644 src/platform/browser/BrowserProvider.ts create mode 100644 src/platform/browser/detectDownloadCapabilities.ts create mode 100644 src/platform/capabilities.ts create mode 100644 src/platform/createPlatformProvider.ts create mode 100644 src/platform/errors.ts create mode 100644 src/platform/platformSingleton.ts create mode 100644 src/platform/types.ts diff --git a/src/components/AppRoot.tsx b/src/components/AppRoot.tsx index 328dc06..0c2726f 100644 --- a/src/components/AppRoot.tsx +++ b/src/components/AppRoot.tsx @@ -15,9 +15,14 @@ import { Bounce, ToastContainer } from 'react-toastify'; import { SettingsHome } from '~/features/settings/SettingsHome'; import { FAQ_PAGES } from '~/faq/FAQPages'; import { FaqHome } from '~/faq/FaqHome'; +import { createPlatformProvider } from '~/platform/createPlatformProvider'; +import { PlatformProviderHost } from '~/platform/PlatformContext'; +import { setPlatform } from '~/platform/platformSingleton'; // Private to this file only. const store = setupStore(); +const platform = createPlatformProvider(); +setPlatform(platform); const tabClassNames = ({ isActive }: { isActive: boolean }) => `mb-[-2px] tab ${isActive ? 'tab-active' : ''}`; @@ -27,51 +32,53 @@ export function AppRoot() { return ( -
- - - 应用 - - - - 设置 - - - - 答疑 - -
+ +
+ + + 应用 + + + + 设置 + + + + 答疑 + +
-
- - - - - {Object.entries(SETTINGS_TABS).map(([key, { Tab }]) => ( - - ))} - - - - {FAQ_PAGES.map(({ id, Component }) => ( - - ))} - - -
+
+ + + + + {Object.entries(SETTINGS_TABS).map(([key, { Tab }]) => ( + + ))} + + + + {FAQ_PAGES.map(({ id, Component }) => ( + + ))} + + +
- + -