/********************************************************************************
 * Copyright (C) 2021 Ericsson and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the Eclipse
 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/ import * as cp from 'child_process' ; import { injectable } from '@theia/core/shared/inversify' ; import { FileUri } from '@theia/core/lib/node/file-uri' ; import { ExternalTerminalService , ExternalTerminalConfiguration } from '../common/external-terminal' ; @ injectable ( ) export class MacExternalTerminalService implements ExternalTerminalService { protected osxOpener = '/usr/bin/open' ; protected defaultTerminalApp = 'Terminal.app' ; async openTerminal ( configuration , cwd ) { await this . spawnTerminal ( configuration , FileUri . fsPath ( cwd ) ) ; } async getDefaultExec ( ) { return this . getDefaultTerminalOSX ( ) ; } param configuration param cwd protected async spawnTerminal ( configuration , cwd ? ) { const terminalConfig = configuration [ 'terminal.external.osxExec' ] ; const terminalApp = terminalConfig || this . getDefaultTerminalOSX ( ) ; return new Promise < void > ( ( resolve , reject ) => { const args = [ '-a' , terminalApp ] ; if ( cwd ) { args . push ( cwd ) ; } const child = cp . spawn ( this . osxOpener , args ) ; child . on ( 'error' , reject ) ; child . on ( 'exit' , ( ) => resolve ( ) ) ; } ) ; } /**
     * Get the default terminal app on OSX.
     */ protected getDefaultTerminalOSX ( ) { return this . defaultTerminalApp ; } }