Path: blob/main/src/vs/workbench/electron-browser/actions/installActions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize, localize2 } from '../../../nls.js';6import { Action2 } from '../../../platform/actions/common/actions.js';7import { ILocalizedString } from '../../../platform/action/common/action.js';8import product from '../../../platform/product/common/product.js';9import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';10import { ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';11import { INativeHostService } from '../../../platform/native/common/native.js';12import { toErrorMessage } from '../../../base/common/errorMessage.js';13import { IProductService } from '../../../platform/product/common/productService.js';14import { isCancellationError } from '../../../base/common/errors.js';1516const shellCommandCategory: ILocalizedString = localize2('shellCommand', 'Shell Command');1718export class InstallShellScriptAction extends Action2 {1920constructor() {21super({22id: 'workbench.action.installCommandLine',23title: localize2('install', "Install '{0}' command in PATH", product.applicationName),24category: shellCommandCategory,25f1: true26});27}2829async run(accessor: ServicesAccessor): Promise<void> {30const nativeHostService = accessor.get(INativeHostService);31const dialogService = accessor.get(IDialogService);32const productService = accessor.get(IProductService);3334try {35await nativeHostService.installShellCommand();3637dialogService.info(localize('successIn', "Shell command '{0}' successfully installed in PATH.", productService.applicationName));38} catch (error) {39if (isCancellationError(error)) {40return;41}4243dialogService.error(toErrorMessage(error));44}45}46}4748export class UninstallShellScriptAction extends Action2 {4950constructor() {51super({52id: 'workbench.action.uninstallCommandLine',53title: localize2('uninstall', "Uninstall '{0}' command from PATH", product.applicationName),54category: shellCommandCategory,55f1: true56});57}5859async run(accessor: ServicesAccessor): Promise<void> {60const nativeHostService = accessor.get(INativeHostService);61const dialogService = accessor.get(IDialogService);62const productService = accessor.get(IProductService);6364try {65await nativeHostService.uninstallShellCommand();6667dialogService.info(localize('successFrom', "Shell command '{0}' successfully uninstalled from PATH.", productService.applicationName));68} catch (error) {69if (isCancellationError(error)) {70return;71}7273dialogService.error(toErrorMessage(error));74}75}76}777879