@theia/workspace 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/canonical-uri-service.d.ts +11 -11
- package/lib/browser/canonical-uri-service.js +59 -59
- package/lib/browser/diff-service.d.ts +10 -10
- package/lib/browser/diff-service.js +85 -85
- package/lib/browser/index.d.ts +7 -7
- package/lib/browser/index.js +34 -34
- package/lib/browser/quick-open-workspace.d.ts +25 -25
- package/lib/browser/quick-open-workspace.js +137 -137
- package/lib/browser/untitled-workspace-exit-dialog.d.ts +19 -19
- package/lib/browser/untitled-workspace-exit-dialog.js +74 -74
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts +10 -10
- package/lib/browser/workspace-breadcrumbs-contribution.js +66 -66
- package/lib/browser/workspace-commands.d.ts +117 -117
- package/lib/browser/workspace-commands.js +601 -601
- package/lib/browser/workspace-commands.spec.d.ts +1 -1
- package/lib/browser/workspace-commands.spec.js +127 -127
- package/lib/browser/workspace-compare-handler.d.ts +26 -26
- package/lib/browser/workspace-compare-handler.js +66 -66
- package/lib/browser/workspace-delete-handler.d.ts +75 -75
- package/lib/browser/workspace-delete-handler.js +214 -214
- package/lib/browser/workspace-duplicate-handler.d.ts +30 -30
- package/lib/browser/workspace-duplicate-handler.js +86 -86
- package/lib/browser/workspace-frontend-contribution.d.ts +110 -110
- package/lib/browser/workspace-frontend-contribution.js +546 -546
- package/lib/browser/workspace-frontend-contribution.js.map +1 -1
- package/lib/browser/workspace-frontend-module.d.ts +3 -3
- package/lib/browser/workspace-frontend-module.js +91 -91
- package/lib/browser/workspace-input-dialog.d.ts +19 -19
- package/lib/browser/workspace-input-dialog.js +74 -74
- package/lib/browser/workspace-preferences.d.ts +11 -11
- package/lib/browser/workspace-preferences.js +46 -46
- package/lib/browser/workspace-schema-updater.d.ts +34 -34
- package/lib/browser/workspace-schema-updater.js +153 -153
- package/lib/browser/workspace-service.d.ts +184 -184
- package/lib/browser/workspace-service.js +739 -739
- package/lib/browser/workspace-storage-service.d.ts +15 -15
- package/lib/browser/workspace-storage-service.js +80 -80
- package/lib/browser/workspace-trust-preferences.d.ts +21 -21
- package/lib/browser/workspace-trust-preferences.js +65 -65
- package/lib/browser/workspace-trust-service.d.ts +27 -27
- package/lib/browser/workspace-trust-service.js +152 -152
- package/lib/browser/workspace-uri-contribution.d.ts +20 -20
- package/lib/browser/workspace-uri-contribution.js +113 -113
- package/lib/browser/workspace-uri-contribution.spec.d.ts +1 -1
- package/lib/browser/workspace-uri-contribution.spec.js +169 -169
- package/lib/browser/workspace-user-working-directory-provider.d.ts +12 -12
- package/lib/browser/workspace-user-working-directory-provider.js +62 -62
- package/lib/browser/workspace-utils.d.ts +15 -15
- package/lib/browser/workspace-utils.js +54 -54
- package/lib/browser/workspace-variable-contribution.d.ts +23 -23
- package/lib/browser/workspace-variable-contribution.js +237 -237
- package/lib/browser/workspace-window-title-updater.d.ts +7 -7
- package/lib/browser/workspace-window-title-updater.js +57 -57
- package/lib/browser-only/browser-only-workspace-server.d.ts +13 -0
- package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -0
- package/lib/browser-only/browser-only-workspace-server.js +81 -0
- package/lib/browser-only/browser-only-workspace-server.js.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts +4 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.js +30 -0
- package/lib/browser-only/workspace-frontend-only-module.js.map +1 -0
- package/lib/common/index.d.ts +3 -3
- package/lib/common/index.js +30 -30
- package/lib/common/test/mock-workspace-server.d.ts +7 -7
- package/lib/common/test/mock-workspace-server.js +35 -35
- package/lib/common/untitled-workspace-service.d.ts +8 -8
- package/lib/common/untitled-workspace-service.js +60 -60
- package/lib/common/workspace-file-service.d.ts +26 -26
- package/lib/common/workspace-file-service.js +71 -71
- package/lib/common/workspace-protocol.d.ts +26 -26
- package/lib/common/workspace-protocol.js +23 -23
- package/lib/node/default-workspace-server.d.ts +65 -65
- package/lib/node/default-workspace-server.js +248 -248
- package/lib/node/default-workspace-server.spec.d.ts +1 -1
- package/lib/node/default-workspace-server.spec.js +85 -85
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +29 -29
- package/lib/node/workspace-backend-module.d.ts +3 -3
- package/lib/node/workspace-backend-module.js +33 -33
- package/package.json +9 -6
- package/src/browser/canonical-uri-service.ts +57 -57
- package/src/browser/diff-service.ts +62 -62
- package/src/browser/index.ts +23 -23
- package/src/browser/quick-open-workspace.ts +112 -112
- package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
- package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
- package/src/browser/workspace-commands.spec.ts +153 -153
- package/src/browser/workspace-commands.ts +588 -588
- package/src/browser/workspace-compare-handler.ts +56 -56
- package/src/browser/workspace-delete-handler.ts +212 -212
- package/src/browser/workspace-duplicate-handler.ts +75 -75
- package/src/browser/workspace-frontend-contribution.ts +537 -537
- package/src/browser/workspace-frontend-module.ts +118 -118
- package/src/browser/workspace-input-dialog.ts +61 -61
- package/src/browser/workspace-preferences.ts +58 -58
- package/src/browser/workspace-schema-updater.ts +150 -150
- package/src/browser/workspace-service.ts +780 -780
- package/src/browser/workspace-storage-service.ts +67 -67
- package/src/browser/workspace-trust-preferences.ts +76 -76
- package/src/browser/workspace-trust-service.ts +147 -147
- package/src/browser/workspace-uri-contribution.spec.ts +191 -191
- package/src/browser/workspace-uri-contribution.ts +97 -97
- package/src/browser/workspace-user-working-directory-provider.ts +49 -49
- package/src/browser/workspace-utils.ts +45 -45
- package/src/browser/workspace-variable-contribution.ts +222 -222
- package/src/browser/workspace-window-title-updater.ts +45 -45
- package/src/browser-only/browser-only-workspace-server.ts +69 -0
- package/src/browser-only/workspace-frontend-only-module.ts +28 -0
- package/src/common/index.ts +19 -19
- package/src/common/test/mock-workspace-server.ts +29 -29
- package/src/common/untitled-workspace-service.ts +50 -50
- package/src/common/workspace-file-service.ts +72 -72
- package/src/common/workspace-protocol.ts +47 -47
- package/src/node/default-workspace-server.spec.ts +100 -100
- package/src/node/default-workspace-server.ts +244 -244
- package/src/node/index.ts +18 -18
- package/src/node/workspace-backend-module.ts +38 -38
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
-
import { LocalStorageService, StorageService } from '@theia/core/lib/browser/storage-service';
|
|
19
|
-
import { WorkspaceService } from './workspace-service';
|
|
20
|
-
import { FileStat } from '@theia/filesystem/lib/common/files';
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* Prefixes any stored data with the current workspace path.
|
|
24
|
-
*/
|
|
25
|
-
@injectable()
|
|
26
|
-
export class WorkspaceStorageService implements StorageService {
|
|
27
|
-
|
|
28
|
-
private prefix: string;
|
|
29
|
-
private initialized: Promise<void>;
|
|
30
|
-
|
|
31
|
-
@inject(LocalStorageService) protected storageService: StorageService;
|
|
32
|
-
@inject(WorkspaceService) protected workspaceService: WorkspaceService;
|
|
33
|
-
|
|
34
|
-
@postConstruct()
|
|
35
|
-
protected init(): void {
|
|
36
|
-
this.initialized = this.workspaceService.roots.then(() => {
|
|
37
|
-
this.updatePrefix();
|
|
38
|
-
this.workspaceService.onWorkspaceLocationChanged(() => this.updatePrefix());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async setData<T>(key: string, data: T): Promise<void> {
|
|
43
|
-
if (!this.prefix) {
|
|
44
|
-
await this.initialized;
|
|
45
|
-
}
|
|
46
|
-
const fullKey = this.prefixWorkspaceURI(key);
|
|
47
|
-
return this.storageService.setData(fullKey, data);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async getData<T>(key: string, defaultValue?: T): Promise<T | undefined> {
|
|
51
|
-
await this.initialized;
|
|
52
|
-
const fullKey = this.prefixWorkspaceURI(key);
|
|
53
|
-
return this.storageService.getData(fullKey, defaultValue);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected prefixWorkspaceURI(originalKey: string): string {
|
|
57
|
-
return `${this.prefix}:${originalKey}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
protected getPrefix(workspaceStat: FileStat | undefined): string {
|
|
61
|
-
return workspaceStat ? workspaceStat.resource.toString() : '_global_';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private updatePrefix(): void {
|
|
65
|
-
this.prefix = this.getPrefix(this.workspaceService.workspace);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import { LocalStorageService, StorageService } from '@theia/core/lib/browser/storage-service';
|
|
19
|
+
import { WorkspaceService } from './workspace-service';
|
|
20
|
+
import { FileStat } from '@theia/filesystem/lib/common/files';
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Prefixes any stored data with the current workspace path.
|
|
24
|
+
*/
|
|
25
|
+
@injectable()
|
|
26
|
+
export class WorkspaceStorageService implements StorageService {
|
|
27
|
+
|
|
28
|
+
private prefix: string;
|
|
29
|
+
private initialized: Promise<void>;
|
|
30
|
+
|
|
31
|
+
@inject(LocalStorageService) protected storageService: StorageService;
|
|
32
|
+
@inject(WorkspaceService) protected workspaceService: WorkspaceService;
|
|
33
|
+
|
|
34
|
+
@postConstruct()
|
|
35
|
+
protected init(): void {
|
|
36
|
+
this.initialized = this.workspaceService.roots.then(() => {
|
|
37
|
+
this.updatePrefix();
|
|
38
|
+
this.workspaceService.onWorkspaceLocationChanged(() => this.updatePrefix());
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async setData<T>(key: string, data: T): Promise<void> {
|
|
43
|
+
if (!this.prefix) {
|
|
44
|
+
await this.initialized;
|
|
45
|
+
}
|
|
46
|
+
const fullKey = this.prefixWorkspaceURI(key);
|
|
47
|
+
return this.storageService.setData(fullKey, data);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async getData<T>(key: string, defaultValue?: T): Promise<T | undefined> {
|
|
51
|
+
await this.initialized;
|
|
52
|
+
const fullKey = this.prefixWorkspaceURI(key);
|
|
53
|
+
return this.storageService.getData(fullKey, defaultValue);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected prefixWorkspaceURI(originalKey: string): string {
|
|
57
|
+
return `${this.prefix}:${originalKey}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected getPrefix(workspaceStat: FileStat | undefined): string {
|
|
61
|
+
return workspaceStat ? workspaceStat.resource.toString() : '_global_';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private updatePrefix(): void {
|
|
65
|
+
this.prefix = this.getPrefix(this.workspaceService.workspace);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2021 EclipseSource and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
createPreferenceProxy, PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService
|
|
19
|
-
} from '@theia/core/lib/browser/preferences';
|
|
20
|
-
import { nls } from '@theia/core/lib/common/nls';
|
|
21
|
-
import { interfaces } from '@theia/core/shared/inversify';
|
|
22
|
-
|
|
23
|
-
export const WORKSPACE_TRUST_ENABLED = 'security.workspace.trust.enabled';
|
|
24
|
-
export const WORKSPACE_TRUST_STARTUP_PROMPT = 'security.workspace.trust.startupPrompt';
|
|
25
|
-
export const WORKSPACE_TRUST_EMPTY_WINDOW = 'security.workspace.trust.emptyWindow';
|
|
26
|
-
|
|
27
|
-
export enum WorkspaceTrustPrompt {
|
|
28
|
-
ALWAYS = 'always',
|
|
29
|
-
ONCE = 'once',
|
|
30
|
-
NEVER = 'never'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const workspaceTrustPreferenceSchema: PreferenceSchema = {
|
|
34
|
-
type: 'object',
|
|
35
|
-
properties: {
|
|
36
|
-
[WORKSPACE_TRUST_ENABLED]: {
|
|
37
|
-
description: nls.localize('theia/workspace/trustEnabled', 'Controls whether or not workspace trust is enabled. If disabled, all workspaces are trusted.'),
|
|
38
|
-
type: 'boolean',
|
|
39
|
-
defaultValue: true
|
|
40
|
-
},
|
|
41
|
-
[WORKSPACE_TRUST_STARTUP_PROMPT]: {
|
|
42
|
-
description: nls.localizeByDefault('Controls when the startup prompt to trust a workspace is shown.'),
|
|
43
|
-
enum: Object.values(WorkspaceTrustPrompt),
|
|
44
|
-
defaultValue: WorkspaceTrustPrompt.ALWAYS
|
|
45
|
-
},
|
|
46
|
-
[WORKSPACE_TRUST_EMPTY_WINDOW]: {
|
|
47
|
-
description: nls.localize('theia/workspace/trustEmptyWindow', 'Controls whether or not the empty workspace is trusted by default.'),
|
|
48
|
-
type: 'boolean',
|
|
49
|
-
defaultValue: true
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export interface WorkspaceTrustConfiguration {
|
|
55
|
-
[WORKSPACE_TRUST_ENABLED]: boolean,
|
|
56
|
-
[WORKSPACE_TRUST_STARTUP_PROMPT]: WorkspaceTrustPrompt;
|
|
57
|
-
[WORKSPACE_TRUST_EMPTY_WINDOW]: boolean;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const WorkspaceTrustPreferenceContribution = Symbol('WorkspaceTrustPreferenceContribution');
|
|
61
|
-
export const WorkspaceTrustPreferences = Symbol('WorkspaceTrustPreferences');
|
|
62
|
-
export type WorkspaceTrustPreferences = PreferenceProxy<WorkspaceTrustConfiguration>;
|
|
63
|
-
|
|
64
|
-
export function createWorkspaceTrustPreferences(preferences: PreferenceService, schema: PreferenceSchema = workspaceTrustPreferenceSchema): WorkspaceTrustPreferences {
|
|
65
|
-
return createPreferenceProxy(preferences, schema);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function bindWorkspaceTrustPreferences(bind: interfaces.Bind): void {
|
|
69
|
-
bind(WorkspaceTrustPreferences).toDynamicValue(ctx => {
|
|
70
|
-
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
|
71
|
-
const contribution = ctx.container.get<PreferenceContribution>(WorkspaceTrustPreferenceContribution);
|
|
72
|
-
return createWorkspaceTrustPreferences(preferences, contribution.schema);
|
|
73
|
-
}).inSingletonScope();
|
|
74
|
-
bind(WorkspaceTrustPreferenceContribution).toConstantValue({ schema: workspaceTrustPreferenceSchema });
|
|
75
|
-
bind(PreferenceContribution).toService(WorkspaceTrustPreferenceContribution);
|
|
76
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2021 EclipseSource and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
createPreferenceProxy, PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService
|
|
19
|
+
} from '@theia/core/lib/browser/preferences';
|
|
20
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
21
|
+
import { interfaces } from '@theia/core/shared/inversify';
|
|
22
|
+
|
|
23
|
+
export const WORKSPACE_TRUST_ENABLED = 'security.workspace.trust.enabled';
|
|
24
|
+
export const WORKSPACE_TRUST_STARTUP_PROMPT = 'security.workspace.trust.startupPrompt';
|
|
25
|
+
export const WORKSPACE_TRUST_EMPTY_WINDOW = 'security.workspace.trust.emptyWindow';
|
|
26
|
+
|
|
27
|
+
export enum WorkspaceTrustPrompt {
|
|
28
|
+
ALWAYS = 'always',
|
|
29
|
+
ONCE = 'once',
|
|
30
|
+
NEVER = 'never'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const workspaceTrustPreferenceSchema: PreferenceSchema = {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
[WORKSPACE_TRUST_ENABLED]: {
|
|
37
|
+
description: nls.localize('theia/workspace/trustEnabled', 'Controls whether or not workspace trust is enabled. If disabled, all workspaces are trusted.'),
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
defaultValue: true
|
|
40
|
+
},
|
|
41
|
+
[WORKSPACE_TRUST_STARTUP_PROMPT]: {
|
|
42
|
+
description: nls.localizeByDefault('Controls when the startup prompt to trust a workspace is shown.'),
|
|
43
|
+
enum: Object.values(WorkspaceTrustPrompt),
|
|
44
|
+
defaultValue: WorkspaceTrustPrompt.ALWAYS
|
|
45
|
+
},
|
|
46
|
+
[WORKSPACE_TRUST_EMPTY_WINDOW]: {
|
|
47
|
+
description: nls.localize('theia/workspace/trustEmptyWindow', 'Controls whether or not the empty workspace is trusted by default.'),
|
|
48
|
+
type: 'boolean',
|
|
49
|
+
defaultValue: true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export interface WorkspaceTrustConfiguration {
|
|
55
|
+
[WORKSPACE_TRUST_ENABLED]: boolean,
|
|
56
|
+
[WORKSPACE_TRUST_STARTUP_PROMPT]: WorkspaceTrustPrompt;
|
|
57
|
+
[WORKSPACE_TRUST_EMPTY_WINDOW]: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const WorkspaceTrustPreferenceContribution = Symbol('WorkspaceTrustPreferenceContribution');
|
|
61
|
+
export const WorkspaceTrustPreferences = Symbol('WorkspaceTrustPreferences');
|
|
62
|
+
export type WorkspaceTrustPreferences = PreferenceProxy<WorkspaceTrustConfiguration>;
|
|
63
|
+
|
|
64
|
+
export function createWorkspaceTrustPreferences(preferences: PreferenceService, schema: PreferenceSchema = workspaceTrustPreferenceSchema): WorkspaceTrustPreferences {
|
|
65
|
+
return createPreferenceProxy(preferences, schema);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function bindWorkspaceTrustPreferences(bind: interfaces.Bind): void {
|
|
69
|
+
bind(WorkspaceTrustPreferences).toDynamicValue(ctx => {
|
|
70
|
+
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
|
|
71
|
+
const contribution = ctx.container.get<PreferenceContribution>(WorkspaceTrustPreferenceContribution);
|
|
72
|
+
return createWorkspaceTrustPreferences(preferences, contribution.schema);
|
|
73
|
+
}).inSingletonScope();
|
|
74
|
+
bind(WorkspaceTrustPreferenceContribution).toConstantValue({ schema: workspaceTrustPreferenceSchema });
|
|
75
|
+
bind(PreferenceContribution).toService(WorkspaceTrustPreferenceContribution);
|
|
76
|
+
}
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2021 EclipseSource and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ConfirmDialog, Dialog, PreferenceChange, StorageService } from '@theia/core/lib/browser';
|
|
18
|
-
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
|
|
19
|
-
import { MessageService } from '@theia/core/lib/common/message-service';
|
|
20
|
-
import { nls } from '@theia/core/lib/common/nls';
|
|
21
|
-
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
22
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
23
|
-
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
|
24
|
-
import {
|
|
25
|
-
WorkspaceTrustPreferences, WORKSPACE_TRUST_EMPTY_WINDOW, WORKSPACE_TRUST_ENABLED, WORKSPACE_TRUST_STARTUP_PROMPT, WorkspaceTrustPrompt
|
|
26
|
-
} from './workspace-trust-preferences';
|
|
27
|
-
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
28
|
-
import { WorkspaceService } from './workspace-service';
|
|
29
|
-
|
|
30
|
-
const STORAGE_TRUSTED = 'trusted';
|
|
31
|
-
|
|
32
|
-
@injectable()
|
|
33
|
-
export class WorkspaceTrustService {
|
|
34
|
-
@inject(WorkspaceService)
|
|
35
|
-
protected readonly workspaceService: WorkspaceService;
|
|
36
|
-
|
|
37
|
-
@inject(PreferenceService)
|
|
38
|
-
protected readonly preferences: PreferenceService;
|
|
39
|
-
|
|
40
|
-
@inject(StorageService)
|
|
41
|
-
protected readonly storage: StorageService;
|
|
42
|
-
|
|
43
|
-
@inject(MessageService)
|
|
44
|
-
protected readonly messageService: MessageService;
|
|
45
|
-
|
|
46
|
-
@inject(WorkspaceTrustPreferences)
|
|
47
|
-
protected readonly workspaceTrustPref: WorkspaceTrustPreferences;
|
|
48
|
-
|
|
49
|
-
@inject(WindowService)
|
|
50
|
-
protected readonly windowService: WindowService;
|
|
51
|
-
|
|
52
|
-
protected workspaceTrust = new Deferred<boolean>();
|
|
53
|
-
|
|
54
|
-
@postConstruct()
|
|
55
|
-
protected init(): void {
|
|
56
|
-
this.doInit();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected async doInit(): Promise<void> {
|
|
60
|
-
await this.workspaceService.ready;
|
|
61
|
-
await this.resolveWorkspaceTrust();
|
|
62
|
-
this.preferences.onPreferenceChanged(change => this.handlePreferenceChange(change));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getWorkspaceTrust(): Promise<boolean> {
|
|
66
|
-
return this.workspaceTrust.promise;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
protected async resolveWorkspaceTrust(givenTrust?: boolean): Promise<void> {
|
|
70
|
-
if (!this.isWorkspaceTrustResolved()) {
|
|
71
|
-
const trust = givenTrust ?? await this.calculateWorkspaceTrust();
|
|
72
|
-
if (trust !== undefined) {
|
|
73
|
-
await this.storeWorkspaceTrust(trust);
|
|
74
|
-
this.workspaceTrust.resolve(trust);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
protected isWorkspaceTrustResolved(): boolean {
|
|
80
|
-
return this.workspaceTrust.state !== 'unresolved';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
protected async calculateWorkspaceTrust(): Promise<boolean | undefined> {
|
|
84
|
-
if (!this.workspaceTrustPref[WORKSPACE_TRUST_ENABLED]) {
|
|
85
|
-
// in VS Code if workspace trust is disabled, we implicitly trust the workspace
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (this.workspaceTrustPref[WORKSPACE_TRUST_EMPTY_WINDOW] && !this.workspaceService.workspace) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.NEVER) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return this.loadWorkspaceTrust();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
protected async loadWorkspaceTrust(): Promise<boolean | undefined> {
|
|
101
|
-
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.ONCE) {
|
|
102
|
-
return this.storage.getData<boolean>(STORAGE_TRUSTED);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
protected async storeWorkspaceTrust(trust: boolean): Promise<void> {
|
|
107
|
-
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.ONCE) {
|
|
108
|
-
return this.storage.setData(STORAGE_TRUSTED, trust);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
protected async handlePreferenceChange(change: PreferenceChange): Promise<void> {
|
|
113
|
-
if (change.preferenceName === WORKSPACE_TRUST_STARTUP_PROMPT && change.newValue !== WorkspaceTrustPrompt.ONCE) {
|
|
114
|
-
this.storage.setData(STORAGE_TRUSTED, undefined);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (change.preferenceName === WORKSPACE_TRUST_ENABLED && this.isWorkspaceTrustResolved() && await this.confirmRestart()) {
|
|
118
|
-
this.windowService.setSafeToShutDown();
|
|
119
|
-
this.windowService.reload();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (change.preferenceName === WORKSPACE_TRUST_ENABLED || change.preferenceName === WORKSPACE_TRUST_EMPTY_WINDOW) {
|
|
123
|
-
this.resolveWorkspaceTrust();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected async confirmRestart(): Promise<boolean> {
|
|
128
|
-
const shouldRestart = await new ConfirmDialog({
|
|
129
|
-
title: nls.localizeByDefault('A setting has changed that requires a restart to take effect.'),
|
|
130
|
-
msg: nls.localizeByDefault('Press the restart button to restart {0} and enable the setting.', FrontendApplicationConfigProvider.get().applicationName),
|
|
131
|
-
ok: nls.localizeByDefault('Restart'),
|
|
132
|
-
cancel: Dialog.CANCEL,
|
|
133
|
-
}).open();
|
|
134
|
-
return shouldRestart === true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async requestWorkspaceTrust(): Promise<boolean | undefined> {
|
|
138
|
-
if (!this.isWorkspaceTrustResolved()) {
|
|
139
|
-
const isTrusted = await this.messageService.info(nls.localize('theia/workspace/trustRequest',
|
|
140
|
-
'An extension requests workspace trust but the corresponding API is not yet fully supported. Do you want to trust this workspace?'),
|
|
141
|
-
Dialog.YES, Dialog.NO);
|
|
142
|
-
const trusted = isTrusted === Dialog.YES;
|
|
143
|
-
this.resolveWorkspaceTrust(trusted);
|
|
144
|
-
}
|
|
145
|
-
return this.workspaceTrust.promise;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2021 EclipseSource and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ConfirmDialog, Dialog, PreferenceChange, StorageService } from '@theia/core/lib/browser';
|
|
18
|
+
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
|
|
19
|
+
import { MessageService } from '@theia/core/lib/common/message-service';
|
|
20
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
21
|
+
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
22
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
23
|
+
import { WindowService } from '@theia/core/lib/browser/window/window-service';
|
|
24
|
+
import {
|
|
25
|
+
WorkspaceTrustPreferences, WORKSPACE_TRUST_EMPTY_WINDOW, WORKSPACE_TRUST_ENABLED, WORKSPACE_TRUST_STARTUP_PROMPT, WorkspaceTrustPrompt
|
|
26
|
+
} from './workspace-trust-preferences';
|
|
27
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
28
|
+
import { WorkspaceService } from './workspace-service';
|
|
29
|
+
|
|
30
|
+
const STORAGE_TRUSTED = 'trusted';
|
|
31
|
+
|
|
32
|
+
@injectable()
|
|
33
|
+
export class WorkspaceTrustService {
|
|
34
|
+
@inject(WorkspaceService)
|
|
35
|
+
protected readonly workspaceService: WorkspaceService;
|
|
36
|
+
|
|
37
|
+
@inject(PreferenceService)
|
|
38
|
+
protected readonly preferences: PreferenceService;
|
|
39
|
+
|
|
40
|
+
@inject(StorageService)
|
|
41
|
+
protected readonly storage: StorageService;
|
|
42
|
+
|
|
43
|
+
@inject(MessageService)
|
|
44
|
+
protected readonly messageService: MessageService;
|
|
45
|
+
|
|
46
|
+
@inject(WorkspaceTrustPreferences)
|
|
47
|
+
protected readonly workspaceTrustPref: WorkspaceTrustPreferences;
|
|
48
|
+
|
|
49
|
+
@inject(WindowService)
|
|
50
|
+
protected readonly windowService: WindowService;
|
|
51
|
+
|
|
52
|
+
protected workspaceTrust = new Deferred<boolean>();
|
|
53
|
+
|
|
54
|
+
@postConstruct()
|
|
55
|
+
protected init(): void {
|
|
56
|
+
this.doInit();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async doInit(): Promise<void> {
|
|
60
|
+
await this.workspaceService.ready;
|
|
61
|
+
await this.resolveWorkspaceTrust();
|
|
62
|
+
this.preferences.onPreferenceChanged(change => this.handlePreferenceChange(change));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getWorkspaceTrust(): Promise<boolean> {
|
|
66
|
+
return this.workspaceTrust.promise;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected async resolveWorkspaceTrust(givenTrust?: boolean): Promise<void> {
|
|
70
|
+
if (!this.isWorkspaceTrustResolved()) {
|
|
71
|
+
const trust = givenTrust ?? await this.calculateWorkspaceTrust();
|
|
72
|
+
if (trust !== undefined) {
|
|
73
|
+
await this.storeWorkspaceTrust(trust);
|
|
74
|
+
this.workspaceTrust.resolve(trust);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected isWorkspaceTrustResolved(): boolean {
|
|
80
|
+
return this.workspaceTrust.state !== 'unresolved';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected async calculateWorkspaceTrust(): Promise<boolean | undefined> {
|
|
84
|
+
if (!this.workspaceTrustPref[WORKSPACE_TRUST_ENABLED]) {
|
|
85
|
+
// in VS Code if workspace trust is disabled, we implicitly trust the workspace
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (this.workspaceTrustPref[WORKSPACE_TRUST_EMPTY_WINDOW] && !this.workspaceService.workspace) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.NEVER) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return this.loadWorkspaceTrust();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected async loadWorkspaceTrust(): Promise<boolean | undefined> {
|
|
101
|
+
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.ONCE) {
|
|
102
|
+
return this.storage.getData<boolean>(STORAGE_TRUSTED);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected async storeWorkspaceTrust(trust: boolean): Promise<void> {
|
|
107
|
+
if (this.workspaceTrustPref[WORKSPACE_TRUST_STARTUP_PROMPT] === WorkspaceTrustPrompt.ONCE) {
|
|
108
|
+
return this.storage.setData(STORAGE_TRUSTED, trust);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected async handlePreferenceChange(change: PreferenceChange): Promise<void> {
|
|
113
|
+
if (change.preferenceName === WORKSPACE_TRUST_STARTUP_PROMPT && change.newValue !== WorkspaceTrustPrompt.ONCE) {
|
|
114
|
+
this.storage.setData(STORAGE_TRUSTED, undefined);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (change.preferenceName === WORKSPACE_TRUST_ENABLED && this.isWorkspaceTrustResolved() && await this.confirmRestart()) {
|
|
118
|
+
this.windowService.setSafeToShutDown();
|
|
119
|
+
this.windowService.reload();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (change.preferenceName === WORKSPACE_TRUST_ENABLED || change.preferenceName === WORKSPACE_TRUST_EMPTY_WINDOW) {
|
|
123
|
+
this.resolveWorkspaceTrust();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
protected async confirmRestart(): Promise<boolean> {
|
|
128
|
+
const shouldRestart = await new ConfirmDialog({
|
|
129
|
+
title: nls.localizeByDefault('A setting has changed that requires a restart to take effect.'),
|
|
130
|
+
msg: nls.localizeByDefault('Press the restart button to restart {0} and enable the setting.', FrontendApplicationConfigProvider.get().applicationName),
|
|
131
|
+
ok: nls.localizeByDefault('Restart'),
|
|
132
|
+
cancel: Dialog.CANCEL,
|
|
133
|
+
}).open();
|
|
134
|
+
return shouldRestart === true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async requestWorkspaceTrust(): Promise<boolean | undefined> {
|
|
138
|
+
if (!this.isWorkspaceTrustResolved()) {
|
|
139
|
+
const isTrusted = await this.messageService.info(nls.localize('theia/workspace/trustRequest',
|
|
140
|
+
'An extension requests workspace trust but the corresponding API is not yet fully supported. Do you want to trust this workspace?'),
|
|
141
|
+
Dialog.YES, Dialog.NO);
|
|
142
|
+
const trusted = isTrusted === Dialog.YES;
|
|
143
|
+
this.resolveWorkspaceTrust(trusted);
|
|
144
|
+
}
|
|
145
|
+
return this.workspaceTrust.promise;
|
|
146
|
+
}
|
|
147
|
+
}
|