Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { installedAppsApi } from 'src/stores/installed-apps-api';
import { testReducer } from 'src/stores/tests/utils/test-reducer';

jest.mock( 'src/lib/get-ipc-api' );
jest.mock( 'src/lib/app-globals' );
jest.mock( 'src/lib/app-globals', () => ( {
getAppGlobals: jest.fn( () => ( {
platform: 'darwin',
} ) ),
isWindows: jest.fn( () => false ),
} ) );

const mockGetIpcApi = getIpcApi as jest.Mock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { useOffline } from 'src/hooks/use-offline';
import { UserSettings } from 'src/modules/user-settings';
import { store } from 'src/stores';

jest.mock( 'src/lib/app-globals' );
jest.mock( 'src/lib/app-globals', () => ( {
getAppGlobals: jest.fn( () => ( {
platform: 'darwin',
} ) ),
isWindows: jest.fn( () => false ),
} ) );
jest.mock( 'src/hooks/use-feature-flags' );
jest.mock( 'src/hooks/use-auth' );
jest.mock( 'src/hooks/use-ipc-listener' );
Expand Down
46 changes: 36 additions & 10 deletions src/modules/user-settings/lib/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
import { __ } from '@wordpress/i18n';
import { isWindows } from 'src/lib/app-globals';
import { getAppGlobals, isWindows } from 'src/lib/app-globals';

export type SupportedTerminal = 'terminal' | 'iterm' | 'warp' | 'ghostty';

export const supportedTerminalNames: Record< SupportedTerminal, string > = {
terminal: __( 'Terminal' ),
// translators: "iTerm" is the brand name for a terminal app and does not need to be translated
iterm: __( 'iTerm' ),
// translators: "Warp" is the brand name for a terminal app and does not need to be translated
warp: __( 'Warp' ),
// translators: "Ghostty" is the brand name for a terminal app and does not need to be translated
ghostty: __( 'Ghostty' ),
type TerminalPlatform = 'darwin' | 'win32' | 'linux';

export type TerminalConfig = {
name: string;
platforms: TerminalPlatform[];
};

export const terminalConfig: Record< SupportedTerminal, TerminalConfig > = {
terminal: {
name: __( 'Terminal' ),
platforms: [ 'darwin', 'linux', 'win32' ],
},
iterm: {
// translators: "iTerm" is the brand name for a terminal app and does not need to be translated
name: __( 'iTerm' ),
platforms: [ 'darwin' ],
},
warp: {
// translators: "Warp" is the brand name for a terminal app and does not need to be translated
name: __( 'Warp' ),
platforms: [ 'darwin', 'win32', 'linux' ],
},
ghostty: {
// translators: "Ghostty" is the brand name for a terminal app and does not need to be translated
name: __( 'Ghostty' ),
platforms: [ 'darwin', 'linux' ],
},
};

export function getTerminalsSupportedOnPlatform(): SupportedTerminal[] {
const platform = getAppGlobals().platform as TerminalPlatform;
return ( Object.keys( terminalConfig ) as SupportedTerminal[] ).filter( ( terminal ) =>
terminalConfig[ terminal ].platforms.includes( platform )
);
}

export function getTerminalName( terminal: SupportedTerminal | undefined ): string {
if ( ! terminal ) {
return '';
Expand All @@ -23,5 +49,5 @@ export function getTerminalName( terminal: SupportedTerminal | undefined ): stri
return __( 'Command Prompt' );
}

return supportedTerminalNames[ terminal ];
return terminalConfig[ terminal ].name;
}
26 changes: 19 additions & 7 deletions src/stores/installed-apps-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
supportedEditorConfig,
SUPPORTED_EDITORS,
} from 'src/modules/user-settings/lib/editor';
import { SupportedTerminal, supportedTerminalNames } from 'src/modules/user-settings/lib/terminal';
import {
SupportedTerminal,
terminalConfig,
getTerminalsSupportedOnPlatform,
} from 'src/modules/user-settings/lib/terminal';

const getFirstInstalledEditor = async (): Promise< SupportedEditor | null > => {
const installedApps = await getIpcApi().getInstalledAppsAndTerminals();
Expand Down Expand Up @@ -107,17 +111,25 @@ export const selectUninstalledEditors = createSelector(
export const selectInstalledTerminals = createSelector(
[ ( data?: InstalledApps ) => data ],
( installedApps ) => {
const entries = Object.entries( supportedTerminalNames ) as [ SupportedTerminal, string ][];

return entries.filter( ( [ terminal ] ) => installedApps && installedApps[ terminal ] );
const supportedTerminals = getTerminalsSupportedOnPlatform();
return supportedTerminals
.filter( ( terminal ) => installedApps && installedApps[ terminal ] )
.map(
( terminal ) =>
[ terminal, terminalConfig[ terminal ].name ] as [ SupportedTerminal, string ]
);
}
);

export const selectUninstalledTerminals = createSelector(
[ ( data?: InstalledApps ) => data ],
( installedApps ) => {
const entries = Object.entries( supportedTerminalNames ) as [ SupportedTerminal, string ][];

return entries.filter( ( [ terminal ] ) => ! installedApps || ! installedApps[ terminal ] );
const supportedTerminals = getTerminalsSupportedOnPlatform();
return supportedTerminals
.filter( ( terminal ) => ! installedApps || ! installedApps[ terminal ] )
.map(
( terminal ) =>
[ terminal, terminalConfig[ terminal ].name ] as [ SupportedTerminal, string ]
);
}
);
6 changes: 6 additions & 0 deletions src/stores/tests/installed-apps-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ jest.mock( 'src/lib/get-ipc-api', () => ( {
getIpcApi: jest.fn(),
} ) );

jest.mock( 'src/lib/app-globals', () => ( {
getAppGlobals: jest.fn( () => ( {
platform: 'darwin',
} ) ),
} ) );

const mockIpcApi = {
getInstalledAppsAndTerminals: jest.fn(),
getUserEditor: jest.fn(),
Expand Down