mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-01 13:15:22 +01:00
add vscode-policy-watcher dependency, support registerPolicyDefinitions
This commit is contained in:
+1
-1
@@ -81,6 +81,7 @@
|
||||
"tas-client-umd": "0.1.5",
|
||||
"v8-inspect-profiler": "^0.1.0",
|
||||
"vscode-oniguruma": "1.6.1",
|
||||
"vscode-policy-watcher": "^1.1.0",
|
||||
"vscode-proxy-agent": "^0.12.0",
|
||||
"vscode-regexpp": "^3.1.0",
|
||||
"vscode-textmate": "7.0.1",
|
||||
@@ -221,7 +222,6 @@
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@vscode/windows-registry": "1.0.6",
|
||||
"vscode-policy-watcher": "^1.0.0",
|
||||
"windows-foreground-love": "0.4.0",
|
||||
"windows-mutex": "0.4.1",
|
||||
"windows-process-tree": "0.3.3"
|
||||
|
||||
@@ -63,7 +63,7 @@ import { StateMainService } from 'vs/platform/state/electron-main/stateMainServi
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { IThemeMainService, ThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
|
||||
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
|
||||
import { WindowsPolicyService } from 'vs/platform/policy/node/windowsPolicyService';
|
||||
import { NativePolicyService } from 'vs/platform/policy/node/nativePolicyService';
|
||||
import { FilePolicyService } from 'vs/platform/policy/common/filePolicyService';
|
||||
|
||||
/**
|
||||
@@ -170,7 +170,7 @@ class CodeMain {
|
||||
services.set(ILoggerService, new LoggerService(logService, fileService));
|
||||
|
||||
// Policy
|
||||
const policyService = isWindows && productService.win32RegValueName ? new WindowsPolicyService(productService.win32RegValueName)
|
||||
const policyService = isWindows && productService.win32RegValueName ? new NativePolicyService(productService.win32RegValueName)
|
||||
: environmentMainService.policyFile ? new FilePolicyService(environmentMainService.policyFile, fileService, logService)
|
||||
: new NullPolicyService();
|
||||
services.set(IPolicyService, policyService);
|
||||
|
||||
@@ -42,7 +42,7 @@ import { ConsoleLogger, getLogLevel, ILogger, ILogService, LogLevel, MultiplexLo
|
||||
import { SpdLogLogger } from 'vs/platform/log/node/spdlogLog';
|
||||
import { FilePolicyService } from 'vs/platform/policy/common/filePolicyService';
|
||||
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
|
||||
import { WindowsPolicyService } from 'vs/platform/policy/node/windowsPolicyService';
|
||||
import { NativePolicyService } from 'vs/platform/policy/node/nativePolicyService';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
@@ -133,7 +133,9 @@ class CliMain extends Disposable {
|
||||
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
|
||||
|
||||
// Policy
|
||||
const policyService = isWindows && productService.win32RegValueName ? new WindowsPolicyService(productService.win32RegValueName) : environmentService.policyFile ? new FilePolicyService(environmentService.policyFile, fileService, logService) : new NullPolicyService();
|
||||
const policyService = isWindows && productService.win32RegValueName ? new NativePolicyService(productService.win32RegValueName)
|
||||
: environmentService.policyFile ? new FilePolicyService(environmentService.policyFile, fileService, logService)
|
||||
: new NullPolicyService();
|
||||
services.set(IPolicyService, policyService);
|
||||
|
||||
// Configuration
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { IPolicyService, PolicyDefinition, PolicyName, PolicyValue } from 'vs/platform/policy/common/policy';
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
import { Iterable } from 'vs/base/common/iterator';
|
||||
import { Throttler } from 'vs/base/common/async';
|
||||
import type { Watcher } from 'vscode-policy-watcher';
|
||||
|
||||
export class NativePolicyService implements IPolicyService {
|
||||
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
private policyDefinitions: IStringDictionary<PolicyDefinition> = {};
|
||||
private readonly policies = new Map<PolicyName, PolicyValue>();
|
||||
|
||||
private readonly _onDidChange = new Emitter<readonly PolicyName[]>();
|
||||
readonly onDidChange = this._onDidChange.event;
|
||||
|
||||
private throttler = new Throttler();
|
||||
private watcher: Watcher | undefined;
|
||||
|
||||
constructor(private readonly productName: string) { }
|
||||
|
||||
async registerPolicyDefinitions(policyDefinitions: IStringDictionary<PolicyDefinition>): Promise<IStringDictionary<PolicyValue>> {
|
||||
const size = Object.keys(this.policyDefinitions).length;
|
||||
this.policyDefinitions = { ...policyDefinitions, ...this.policyDefinitions };
|
||||
|
||||
if (size !== Object.keys(this.policyDefinitions).length) {
|
||||
await this.throttler.queue(async () => {
|
||||
this.watcher?.dispose();
|
||||
|
||||
const { createWatcher } = await import('vscode-policy-watcher');
|
||||
|
||||
await new Promise<void>(c => {
|
||||
this.watcher = createWatcher(this.productName, policyDefinitions, update => {
|
||||
for (const key in update) {
|
||||
const value = update[key] as any;
|
||||
|
||||
if (value === undefined) {
|
||||
this.policies.delete(key);
|
||||
} else {
|
||||
this.policies.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
this._onDidChange.fire(Object.keys(update));
|
||||
c();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Iterable.reduce(this.policies.entries(), (r, [name, value]) => ({ ...r, [name]: value }), {});
|
||||
}
|
||||
|
||||
getPolicyValue(name: PolicyName): PolicyValue | undefined {
|
||||
return this.policies.get(name);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._onDidChange.dispose();
|
||||
this.watcher?.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IPolicyService, PolicyDefinition, PolicyName, PolicyValue } from 'vs/platform/policy/common/policy';
|
||||
import { createWatcher, Watcher } from 'vscode-policy-watcher';
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
import { Iterable } from 'vs/base/common/iterator';
|
||||
|
||||
export class WindowsPolicyService extends Disposable implements IPolicyService {
|
||||
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
private readonly policies = new Map<PolicyName, PolicyValue>();
|
||||
private init: Promise<Watcher> | undefined;
|
||||
|
||||
private readonly _onDidChange = new Emitter<readonly PolicyName[]>();
|
||||
readonly onDidChange = this._onDidChange.event;
|
||||
|
||||
constructor(private readonly productName: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
async registerPolicyDefinitions(policies: IStringDictionary<PolicyDefinition>): Promise<IStringDictionary<PolicyValue>> {
|
||||
if (!this.init) {
|
||||
this.init = new Promise(c => {
|
||||
let first = true;
|
||||
|
||||
const watcher = createWatcher(this.productName, policies, update => {
|
||||
for (const key in update) {
|
||||
const value = update[key] as any;
|
||||
|
||||
if (value === undefined) {
|
||||
this.policies.delete(key);
|
||||
} else {
|
||||
this.policies.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
c(watcher);
|
||||
} else {
|
||||
this._onDidChange.fire(Object.keys(update));
|
||||
}
|
||||
});
|
||||
|
||||
this._register(watcher);
|
||||
});
|
||||
|
||||
await this.init;
|
||||
} else {
|
||||
const watcher = await this.init;
|
||||
const promise = Event.toPromise(this.onDidChange);
|
||||
watcher.addPolicies(policies);
|
||||
await promise;
|
||||
}
|
||||
|
||||
// TODO@joao: heavy cleanup
|
||||
|
||||
return Iterable.reduce(this.policies.entries(), (r, [name, value]) => ({ ...r, [name]: value }), {});
|
||||
}
|
||||
|
||||
getPolicyValue(name: PolicyName): PolicyValue | undefined {
|
||||
return this.policies.get(name);
|
||||
}
|
||||
}
|
||||
@@ -11796,10 +11796,10 @@ vscode-oniguruma@1.6.1:
|
||||
resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.6.1.tgz#2bf4dfcfe3dd2e56eb549a3068c8ee39e6c30ce5"
|
||||
integrity sha512-vc4WhSIaVpgJ0jJIejjYxPvURJavX6QG41vu0mGhqywMkQqulezEqEQ3cO3gc8GvcOpX6ycmKGqRoROEMBNXTQ==
|
||||
|
||||
vscode-policy-watcher@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-policy-watcher/-/vscode-policy-watcher-1.0.0.tgz#08138a5ab15a1d6c021df51716a4daa97d74b471"
|
||||
integrity sha512-j9nWBInu9wPW+3Uw/flYXP0kTewTqTfM6ADC24stqxURCAGOWxYz3ArBo21o+3zOrxpfCjc5mCbUNfLk+6IHuA==
|
||||
vscode-policy-watcher@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-policy-watcher/-/vscode-policy-watcher-1.1.0.tgz#2921353c5080b3452929f1e350b9fab9ff852cc9"
|
||||
integrity sha512-yPvy3Or66H0l8/FyWbJeGxpWW3GDZf65EIT7fqp1Ethdz4ecEnHThuHti7SlfdRJTf5qnifrX7af02INiHqDMA==
|
||||
dependencies:
|
||||
bindings "^1.5.0"
|
||||
node-addon-api "*"
|
||||
|
||||
Reference in New Issue
Block a user