Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified service display name #834

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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