Skip to content

Commit be528ee

Browse files
committed
newest iteration; 3/12
1 parent 2273800 commit be528ee

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/features/packageManagement.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { window } from 'vscode';
21
import { traceInfo } from '../common/logging';
32
import { getCallingExtension } from '../common/utils/frameUtils';
43
import { getConfiguration } from '../common/workspace.apis';
@@ -49,10 +48,9 @@ export async function packageManagementFlow(packages: string[]): Promise<void> {
4948
if (!isConfigured) {
5049
// calling extension has no config, user has no wildcard setup
5150
// prompt user to "alwaysAsk" or "alwaysAllow"
52-
const selectedOption = await promptForInstallPermissions(callingExtension, packages.join(', '));
51+
const selectedOption = await promptForInstallPermissions(callingExtension, packages);
5352
if (selectedOption === InstallPermissionEnum.Cancel) {
5453
// user cancelled the prompt, exit
55-
window.showErrorMessage(`Installation of ${packages.join(', ')} was canceled by the user.`);
5654
return Promise.reject('User cancelled the package installation.');
5755
}
5856
if (selectedOption !== InstallPermissionEnum.InstallNoConfigure) {
@@ -65,10 +63,9 @@ export async function packageManagementFlow(packages: string[]): Promise<void> {
6563
if (callingExtensionTrustLevel === InstallPermissionEnum.AlwaysAsk) {
6664
traceInfo('Installation is pending user confirmation due to permission settings.');
6765
// prompt user to allow or deny package installation
68-
const simpleResponse = await promptForAlwaysAsk(callingExtension, packages.join(', '));
66+
const simpleResponse = await promptForAlwaysAsk(callingExtension, packages);
6967
if (simpleResponse === SimpleResponseEnum.NoInstall || simpleResponse === SimpleResponseEnum.Cancel) {
7068
// user cancelled the prompt, exit
71-
window.showErrorMessage(`Installation of ${packages.join(', ')} was canceled by the user.`);
7269
return Promise.reject('User cancelled the package installation.');
7370
}
7471
}

src/features/utils.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,53 @@ export type SettingsPackageTrust = {
55
[key: string]: InstallPermissionEnum.AlwaysAllow | InstallPermissionEnum.AlwaysAsk;
66
};
77

8-
export const ALWAYS_ALLOW = 'Always allow installs';
9-
export const ALWAYS_ASK = 'Always ask before installing';
8+
export const ALWAYS_ALLOW = 'Always allow';
9+
export const ALWAYS_ASK = 'Ask every time';
1010
export const INSTALL_NO_CONFIGURE = 'Install without configuring permissions';
1111

1212
export const YES_INSTALL = 'Yes, Install';
1313
export const NO_INSTALL = 'Do Not Install';
1414

15-
export function promptForInstallPermissions(extensionName: string, packages: string): Thenable<InstallPermissionEnum> {
15+
export function promptForInstallPermissions(
16+
extensionName: string,
17+
packages: string[],
18+
): Thenable<InstallPermissionEnum> {
19+
const extName = extensionName.split('.')[1];
20+
if (packages.length < 1) {
21+
return Promise.reject('No packages to install.');
22+
}
23+
let detailStr = `'${extensionName}' wants to install the package '${packages[0]}'.`;
24+
if (packages.length > 1) {
25+
detailStr = `'${extensionName}' wants to install packages '${packages.join(', ')}'.`;
26+
}
27+
detailStr = `Set permissions for this and future package installations from '${extensionName}'.`;
1628
return new Promise((resolve) => {
1729
window
1830
.showInformationMessage(
19-
'Would you like to set permissions for future package installs from the ' + extensionName + ' extension?',
31+
`Allow extension '${extName}' to install packages?`,
2032
{
21-
detail: `package/s: "${packages}"`,
33+
detail: detailStr,
2234
modal: true,
2335
},
2436
ALWAYS_ASK,
2537
ALWAYS_ALLOW,
26-
INSTALL_NO_CONFIGURE,
2738
)
2839
.then((selectedOption) => {
2940
switch (selectedOption) {
3041
case ALWAYS_ALLOW:
42+
window.showInformationMessage(
43+
`${extName} extension installed ${packages.join(', ')} package and is always allowed to install in the future.`,
44+
'Configure'
45+
).then((selection) => {
46+
if (selection === 'Configure') {
47+
// Add logic to open the configuration settings
48+
}
49+
});
3150
resolve(InstallPermissionEnum.AlwaysAllow);
3251
break;
3352
case ALWAYS_ASK:
3453
resolve(InstallPermissionEnum.AlwaysAsk);
3554
break;
36-
case INSTALL_NO_CONFIGURE:
37-
resolve(InstallPermissionEnum.InstallNoConfigure);
38-
break;
3955
default:
4056
resolve(InstallPermissionEnum.Cancel);
4157
break;
@@ -44,13 +60,21 @@ export function promptForInstallPermissions(extensionName: string, packages: str
4460
});
4561
}
4662

47-
export function promptForAlwaysAsk(extensionName: string, packages: string): Thenable<string | undefined> {
63+
export function promptForAlwaysAsk(extensionName: string, packages: string[]): Thenable<string | undefined> {
64+
const extName = extensionName.split('.')[1];
65+
if (packages.length < 1) {
66+
return Promise.reject('No packages to install.');
67+
}
68+
let detailStr = `${extName} wants to install '${packages[0]}' package.`;
69+
if (packages.length > 1) {
70+
detailStr = `${extName} wants to install '${packages.join(', ')}' packages.`;
71+
}
4872
return new Promise((resolve) => {
4973
window
5074
.showInformationMessage(
51-
'Do you want to install the following package/s from the ' + extensionName + ' extension?',
75+
`Allow ${extName} to Install Packages?`,
5276
{
53-
detail: `package/s: "${packages}"`,
77+
detail: detailStr,
5478
modal: true,
5579
},
5680
YES_INSTALL,

0 commit comments

Comments
 (0)