Skip to content

Commit

Permalink
hide invalid services
Browse files Browse the repository at this point in the history
  • Loading branch information
xtyuns committed Jun 14, 2024
1 parent 56b182b commit 2e053e6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/utils/service_instance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export enum ServiceType {
TRANSLATE = 'translate',
}

export enum ServiceSourceType {
BUILDIN = 'buildin',
PLUGIN = 'plugin',
Expand Down Expand Up @@ -29,9 +33,14 @@ 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'
export const INSTANCE_NAME_CONFIG_KEY = 'instanceName'

export function whetherAvailableService(serviceInstanceKey: string, availableServiceNames: Record<ServiceSourceType, string[]>) {
const serviceSourceType = getServiceSouceType(serviceInstanceKey)
const serviceName = getServiceName(serviceInstanceKey)
return availableServiceNames[serviceSourceType].findIndex((it: string) => it === serviceName) != -1
}
6 changes: 5 additions & 1 deletion src/window/Config/pages/History/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useConfig, useToastStyle } from '../../../../hooks';
import { LanguageFlag } from '../../../../utils/language';
import { store } from '../../../../utils/store';
import { osType } from '../../../../utils/env';
import { ServiceSourceType, whetherAvailableService } from '../../../../utils/service_instance';

export default function History() {
const [collectionServiceList] = useConfig('collection_service_list', []);
Expand Down Expand Up @@ -145,7 +146,10 @@ export default function History() {
emptyContent={'No History to display.'}
items={items}
>
{(item) => (
{(item) => whetherAvailableService(item.service, {
[ServiceSourceType.BUILDIN]: builtinServices,
[ServiceSourceType.PLUGIN]: pluginList
}) && (
<TableRow key={item.id}>
<TableCell>
{item.service.startsWith('[plugin]') ? (
Expand Down
10 changes: 9 additions & 1 deletion src/window/Config/pages/Service/Translate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import ServiceItem from './ServiceItem';
import SelectModal from './SelectModal';
import ConfigModal from './ConfigModal';

import * as builtinTranslateServices from '../../../../services/translate';
import { ServiceSourceType, whetherAvailableService } from '../../../../../utils/service_instance';

export default function Translate(props) {
const { pluginList } = props;
const {
Expand Down Expand Up @@ -81,7 +84,12 @@ export default function Translate(props) {
{...provided.droppableProps}
>
{translateServiceInstanceList !== null &&
translateServiceInstanceList.map((x, i) => {
translateServiceInstanceList.filter(instanceKey => {
return whetherAvailableService(instanceKey, {
[ServiceSourceType.BUILDIN]: builtinTranslateServices,
[ServiceSourceType.PLUGIN]: pluginList
})
}).map((x, i) => {
return (
<Draggable
key={x}
Expand Down
12 changes: 11 additions & 1 deletion src/window/Translate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { osType } from '../../utils/env';
import { useConfig } from '../../hooks';
import { store } from '../../utils/store';
import { info } from 'tauri-plugin-log-api';

import * as builtinTranslateServices from '../../../../services/translate';
import { ServiceSourceType, whetherAvailableService } from '../../utils/service_instance';

let blurTimeout = null;
let resizeTimeout = null;
let moveTimeout = null;
Expand Down Expand Up @@ -272,7 +276,13 @@ export default function Translate() {
const config = serviceInstanceConfigMap[serviceInstanceKey] ?? {};
const enable = config['enable'] ?? true;

return enable ? (
return enable && whetherAvailableService(
serviceInstanceKey,
{
[ServiceSourceType.PLUGIN]: pluginList,
[ServiceSourceType.BUILDIN]: builtinTranslateServices
}
) ? (
<Draggable
key={serviceInstanceKey}
draggableId={serviceInstanceKey}
Expand Down

0 comments on commit 2e053e6

Please sign in to comment.