|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | +import { inject, injectable, named } from 'inversify'; |
| 6 | +import { commands, Memento } from 'vscode'; |
| 7 | +import { IExtensionSyncActivationService } from '../platform/activation/types'; |
| 8 | +import { IApplicationShell } from '../platform/common/application/types'; |
| 9 | +import { GLOBAL_MEMENTO, IBrowserService, IMemento } from '../platform/common/types'; |
| 10 | +import { Common, DataScience } from '../platform/common/utils/localize'; |
| 11 | +import { noop } from '../platform/common/utils/misc'; |
| 12 | +import { TrustedKernelPaths } from './raw/finder/trustedKernelSpecPaths.node'; |
| 13 | + |
| 14 | +const MEMENTO_KEY_NOTIFIED_ABOUT_HIDDEN_KERNEL = 'MEMENTO_KEY_NOTIFIED_ABOUT_HIDDEN_KERNEL_1'; |
| 15 | +@injectable() |
| 16 | +export class HiddenKernelNotification implements IExtensionSyncActivationService { |
| 17 | + private notifiedAboutHiddenKernel?: boolean; |
| 18 | + constructor( |
| 19 | + @inject(IMemento) @named(GLOBAL_MEMENTO) private readonly globalMemento: Memento, |
| 20 | + @inject(IApplicationShell) private readonly appShell: IApplicationShell, |
| 21 | + @inject(IBrowserService) private readonly browser: IBrowserService |
| 22 | + ) {} |
| 23 | + |
| 24 | + public activate(): void { |
| 25 | + TrustedKernelPaths.IsKernelSpecHidden.promise |
| 26 | + .then((hidden) => { |
| 27 | + if ( |
| 28 | + !hidden || |
| 29 | + this.notifiedAboutHiddenKernel || |
| 30 | + this.globalMemento.get<boolean>(MEMENTO_KEY_NOTIFIED_ABOUT_HIDDEN_KERNEL, false) |
| 31 | + ) { |
| 32 | + return; |
| 33 | + } |
| 34 | + this.notifiedAboutHiddenKernel = true; |
| 35 | + this.globalMemento.update(MEMENTO_KEY_NOTIFIED_ABOUT_HIDDEN_KERNEL, true).then(noop, noop); |
| 36 | + this.appShell |
| 37 | + .showWarningMessage( |
| 38 | + DataScience.untrustedKernelSpecsHidden(), |
| 39 | + Common.learnMore(), |
| 40 | + DataScience.updateSettingToTrustKernelSpecs() |
| 41 | + ) |
| 42 | + .then((selection) => { |
| 43 | + switch (selection) { |
| 44 | + case Common.learnMore(): |
| 45 | + this.browser.launch('https://aka.ms/JupyterTrustedKernelPaths'); |
| 46 | + break; |
| 47 | + case DataScience.updateSettingToTrustKernelSpecs(): |
| 48 | + commands |
| 49 | + .executeCommand('workbench.action.openSettings', 'jupyter.kernels.trusted') |
| 50 | + .then(noop, noop); |
| 51 | + break; |
| 52 | + } |
| 53 | + }) |
| 54 | + .then(noop, noop); |
| 55 | + }) |
| 56 | + .catch(noop); |
| 57 | + } |
| 58 | +} |
0 commit comments