From 75d75780abaf0b672db2dc337eaa3c7bf2f1b5f1 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Fri, 3 Jan 2025 23:41:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/infrastructures/EngineConnector.ts | 48 ++++++++++++++------------ src/store/proxy.ts | 14 ++++---- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/infrastructures/EngineConnector.ts b/src/infrastructures/EngineConnector.ts index 1f97719fc3..be2870b803 100644 --- a/src/infrastructures/EngineConnector.ts +++ b/src/infrastructures/EngineConnector.ts @@ -8,6 +8,7 @@ export interface IEngineConnectorFactory { instance: (host: string) => DefaultApiInterface; } +// 通常エンジン const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => { const instanceMapper: Record = {}; return { @@ -23,11 +24,10 @@ const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => { }, }; }; - -/** エンジン */ export const OpenAPIEngineConnectorFactory = OpenAPIEngineConnectorFactoryImpl(); +// モック用エンジン const OpenAPIMockEngineConnectorFactoryImpl = (): IEngineConnectorFactory => { let mockInstance: DefaultApiInterface | undefined; return { @@ -39,28 +39,30 @@ const OpenAPIMockEngineConnectorFactoryImpl = (): IEngineConnectorFactory => { }, }; }; - -/** モック用エンジン */ export const OpenAPIMockEngineConnectorFactory = OpenAPIMockEngineConnectorFactoryImpl(); -/** モック用エンジンのURLは `mock://mock` とする */ -export const mockUrlParams = { - protocol: "mock:", - hostname: "mock", - port: "", - pathname: "", -} satisfies EngineUrlParams; +// 通常エンジンとモック用エンジンの両対応 +// モック用エンジンのURLのときはモックを、そうじゃないときは通常エンジンを返す。 +const OpenAPIEngineAndMockConnectorFactoryImpl = + (): IEngineConnectorFactory => { + // モック用エンジンのURLは `mock://mock` とする + const mockUrlParams: EngineUrlParams = { + protocol: "mock:", + hostname: "mock", + port: "", + pathname: "", + }; -/** - * モック用エンジンのURLのときはモックを、そうじゃないときは通常エンジンを返す。 - */ -export const OpenAPIEngineAndMockConnectorFactory: IEngineConnectorFactory = { - instance: (host: string) => { - if (host == createEngineUrl(mockUrlParams)) { - return OpenAPIMockEngineConnectorFactory.instance(host); - } else { - return OpenAPIEngineConnectorFactory.instance(host); - } - }, -}; + return { + instance: (host: string) => { + if (host == createEngineUrl(mockUrlParams)) { + return OpenAPIMockEngineConnectorFactory.instance(host); + } else { + return OpenAPIEngineConnectorFactory.instance(host); + } + }, + }; + }; +export const OpenAPIEngineAndMockConnectorFactory = + OpenAPIEngineAndMockConnectorFactoryImpl(); diff --git a/src/store/proxy.ts b/src/store/proxy.ts index 76cd7fa5a0..0873c974a1 100644 --- a/src/store/proxy.ts +++ b/src/store/proxy.ts @@ -71,9 +71,11 @@ export const convertAudioQueryFromEngineToEditor = ( }; }; -// 製品PC版以外はモックエンジンも使えるようする -const ConnectorFactory = - isElectron && isProduction - ? OpenAPIEngineConnectorFactory - : OpenAPIEngineAndMockConnectorFactory; -export const proxyStore = proxyStoreCreator(ConnectorFactory); +// 製品PC版は通常エンジンのみを、それ以外はモックエンジンも使えるようする +const getConnectorFactory = () => { + if (isElectron && isProduction) { + return OpenAPIEngineConnectorFactory; + } + return OpenAPIEngineAndMockConnectorFactory; +}; +export const proxyStore = proxyStoreCreator(getConnectorFactory());