Skip to content

Commit 4a60ab6

Browse files
committed
unified service display name
1 parent c1868d5 commit 4a60ab6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/utils/service_instance.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ export function getServiceName(serviceInstanceKey: string): string {
2929
return serviceInstanceKey.split('@')[0]
3030
}
3131

32+
33+
export function getDisplayInstanceName(instanceName: string, serviceNameSupplier: () => string): string {
34+
return instanceName || serviceNameSupplier()
35+
}
36+
3237
export const INSTANCE_NAME_CONFIG_KEY = 'instanceName'

src/window/Config/pages/Service/Translate/ServiceItem/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77

88
import * as builtinServices from '../../../../../../services/translate';
99
import { useConfig } from '../../../../../../hooks';
10-
import { INSTANCE_NAME_CONFIG_KEY, ServiceSourceType, getServiceName, getServiceSouceType } from '../../../../../../utils/service_instance';
10+
import { INSTANCE_NAME_CONFIG_KEY, ServiceSourceType, getDisplayInstanceName, getServiceName, getServiceSouceType } from '../../../../../../utils/service_instance';
1111

1212
export default function ServiceItem(props) {
1313
const { serviceInstanceKey, pluginList, deleteServiceInstance, setCurrentConfigKey, onConfigOpen, ...drag } = props;
@@ -39,7 +39,7 @@ export default function ServiceItem(props) {
3939
draggable={false}
4040
/>
4141
<Spacer x={2} />
42-
<h2 className='my-auto'>{serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY] || t(`services.translate.${serviceName}.title`)}</h2>
42+
<h2 className='my-auto'>{getDisplayInstanceName(serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY], () => t(`services.translate.${serviceName}.title`))}</h2>
4343
</>
4444
)}
4545
{serviceSourceType === ServiceSourceType.PLUGIN && (
@@ -50,7 +50,7 @@ export default function ServiceItem(props) {
5050
draggable={false}
5151
/>
5252
<Spacer x={2} />
53-
<h2 className='my-auto'>{`${serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY] || pluginList[serviceName].display} [${t('common.plugin')}]`}</h2>
53+
<h2 className='my-auto'>{getDisplayInstanceName(serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY], () => pluginList[serviceName].display) + `[${t('common.plugin')}]`}</h2>
5454
</>
5555
)}
5656
</div>

src/window/Translate/components/TargetArea/index.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import * as builtinServices from '../../../../services/translate';
4040
import * as builtinTtsServices from '../../../../services/tts';
4141

4242
import { store } from '../../../../utils/store';
43-
import { INSTANCE_NAME_CONFIG_KEY, getServiceName, whetherPluginService } from '../../../../utils/service_instance';
43+
import { INSTANCE_NAME_CONFIG_KEY, getDisplayInstanceName, getServiceName, whetherPluginService } from '../../../../utils/service_instance';
4444

4545
let translateID = [];
4646

@@ -50,7 +50,7 @@ export default function TargetArea(props) {
5050
const [currentTranslateServiceInstanceKey, setCurrentTranslateServiceInstanceKey] = useState(name);
5151
function getInstanceName(instanceKey, serviceNameSupplier) {
5252
const instanceConfig = serviceInstanceConfigMap[instanceKey] ?? {}
53-
return instanceConfig[INSTANCE_NAME_CONFIG_KEY] ?? serviceNameSupplier()
53+
return getDisplayInstanceName(instanceConfig[INSTANCE_NAME_CONFIG_KEY], serviceNameSupplier)
5454
}
5555

5656
const [appFontSize] = useConfig('app_font_size', 16);

0 commit comments

Comments
 (0)