Skip to content

Commit

Permalink
fix: unified service display name (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtyuns authored Jun 12, 2024
1 parent c1868d5 commit 56b182b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/utils/service_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ export function getServiceName(serviceInstanceKey: string): string {
return serviceInstanceKey.split('@')[0]
}


export function getDisplayInstanceName(instanceName: string, serviceNameSupplier: () => string): string {
return instanceName || serviceNameSupplier()
}

export const INSTANCE_NAME_CONFIG_KEY = 'instanceName'
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';

import * as builtinServices from '../../../../../../services/translate';
import { useConfig } from '../../../../../../hooks';
import { INSTANCE_NAME_CONFIG_KEY, ServiceSourceType, getServiceName, getServiceSouceType } from '../../../../../../utils/service_instance';
import { INSTANCE_NAME_CONFIG_KEY, ServiceSourceType, getDisplayInstanceName, getServiceName, getServiceSouceType } from '../../../../../../utils/service_instance';

export default function ServiceItem(props) {
const { serviceInstanceKey, pluginList, deleteServiceInstance, setCurrentConfigKey, onConfigOpen, ...drag } = props;
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function ServiceItem(props) {
draggable={false}
/>
<Spacer x={2} />
<h2 className='my-auto'>{serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY] || t(`services.translate.${serviceName}.title`)}</h2>
<h2 className='my-auto'>{getDisplayInstanceName(serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY], () => t(`services.translate.${serviceName}.title`))}</h2>
</>
)}
{serviceSourceType === ServiceSourceType.PLUGIN && (
Expand All @@ -50,7 +50,7 @@ export default function ServiceItem(props) {
draggable={false}
/>
<Spacer x={2} />
<h2 className='my-auto'>{`${serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY] || pluginList[serviceName].display} [${t('common.plugin')}]`}</h2>
<h2 className='my-auto'>{getDisplayInstanceName(serviceInstanceConfig[INSTANCE_NAME_CONFIG_KEY], () => pluginList[serviceName].display) + `[${t('common.plugin')}]`}</h2>
</>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/window/Translate/components/TargetArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import * as builtinServices from '../../../../services/translate';
import * as builtinTtsServices from '../../../../services/tts';

import { store } from '../../../../utils/store';
import { INSTANCE_NAME_CONFIG_KEY, getServiceName, whetherPluginService } from '../../../../utils/service_instance';
import { INSTANCE_NAME_CONFIG_KEY, getDisplayInstanceName, getServiceName, whetherPluginService } from '../../../../utils/service_instance';

let translateID = [];

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

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

0 comments on commit 56b182b

Please sign in to comment.