diff --git a/desktop/app/src/comms/ServerController.tsx b/desktop/app/src/comms/ServerController.tsx index 9b7f57948..2daa235a3 100644 --- a/desktop/app/src/comms/ServerController.tsx +++ b/desktop/app/src/comms/ServerController.tsx @@ -46,6 +46,10 @@ import DummyDevice from '../devices/DummyDevice'; import BaseDevice from '../devices/BaseDevice'; import {sideEffect} from '../utils/sideEffect'; import {destroyDevice} from '../reducers/connections'; +import { + appNameWithUpdateHint, + transformCertificateExchangeMediumToType, +} from './Utilities'; type ClientInfo = { connection: ClientConnection | null | undefined; @@ -57,35 +61,12 @@ type ClientCsrQuery = { csr_path?: string | undefined; }; -function transformCertificateExchangeMediumToType( - medium: number | undefined, -): CertificateExchangeMedium { - if (medium == 1) { - return 'FS_ACCESS'; - } else if (medium == 2) { - return 'WWW'; - } else { - return 'FS_ACCESS'; - } -} - declare interface ServerController { on(event: 'new-client', callback: (client: Client) => void): this; on(event: 'error', callback: (err: Error) => void): this; on(event: 'clients-change', callback: () => void): this; } -function appNameWithUpdateHint(query: ClientQuery): string { - // in previous version (before 3), app may not appear in correct device - // section because it refers to the name given by client which is not fixed - // for android emulators, so it is indicated as outdated so that developers - // might want to update SDK to get rid of this connection swap problem - if (query.os === 'Android' && (!query.sdk_version || query.sdk_version < 3)) { - return query.app + ' (Outdated SDK)'; - } - return query.app; -} - class ServerController extends EventEmitter { connections: Map; secureServer: Promise> | null; diff --git a/desktop/app/src/comms/Utilities.tsx b/desktop/app/src/comms/Utilities.tsx new file mode 100644 index 000000000..53a524b07 --- /dev/null +++ b/desktop/app/src/comms/Utilities.tsx @@ -0,0 +1,46 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import {CertificateExchangeMedium} from '../utils/CertificateProvider'; +import {ClientQuery} from '../Client'; + +/** + * Transforms the certificate exchange medium type as number to the + * CertificateExchangeMedium type. + * @param medium A number representing the certificate exchange medium type. + */ +export function transformCertificateExchangeMediumToType( + medium: number | undefined, +): CertificateExchangeMedium { + if (medium == 1) { + return 'FS_ACCESS'; + } else if (medium == 2) { + return 'WWW'; + } else { + return 'FS_ACCESS'; + } +} + +/** + * Returns the app name from a ClientQuery instance. In most cases it should be + * the app name as given in the query. On Android, and for old SDK versions (<3) it + * will returned the app name suffixed by '(Outdated SDK)'. + * + * Reason is, in previous version (<3), app may not appear in correct device + * section because it refers to the name given by client which is not fixed + * for android emulators, so it is indicated as outdated so that developers + * might want to update SDK to get rid of this connection swap problem + * @param query A ClientQuery object. + */ +export function appNameWithUpdateHint(query: ClientQuery): string { + if (query.os === 'Android' && (!query.sdk_version || query.sdk_version < 3)) { + return query.app + ' (Outdated SDK)'; + } + return query.app; +}