2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Throttler } from '../../../base/common/async.js';
7
>
import { IStringDictionary } from '../../../base/common/collections.js';
8
>
import { Emitter } from '../../../base/common/event.js';
9
>
import { Disposable, MutableDisposable } from '../../../base/common/lifecycle.js';
10
>
import { equals } from '../../../base/common/objects.js';
11
>
import { IManagedSettingsPolicyDefinitions, ManagedSettingsData } from '../../../base/common/policy.js';
12
>
import { ILogService } from '../../log/common/log.js';
13
>
import { collectManagedSettingsDefinitions, INativeManagedSettingsService } from '../common/copilotManagedSettings.js';
14
>
import { PolicyDefinition, PolicyValue } from '../common/policy.js';
15
>
import type { Watcher } from '@vscode/policy-watcher';
16
>
17
>
export interface INativePolicyWatcherOptions {
18
>
readonly registryPath?: string;
19
>
}
20
>
21
>
export type NativePolicyWatcherFactory = (
22
>
productName: string,
23
>
policies: Record<string, { type: 'string' | 'number' | 'boolean' }>,
24
>
onDidChange: (update: Record<string, PolicyValue | undefined>) => void,
25
>
options?: INativePolicyWatcherOptions,
26
>
) => Watcher;
27
>
28
>
export class NativeManagedSettingsService extends Disposable implements INativeManagedSettingsService {
29
>
30
>
readonly _serviceBrand: undefined;
31
>
32
>
private readonly throttler = this._register(new Throttler());
33
>
private readonly watcher = this._register(new MutableDisposable<Watcher>());
34
>
private readonly managedSettingsValues = new Map<string, PolicyValue>();
35
>
private watchedSettings: IManagedSettingsPolicyDefinitions = {};
36
>
37
>
private readonly _onDidChangeManagedSettings = this._register(new Emitter<ManagedSettingsData>());
38
>
readonly onDidChangeManagedSettings = this._onDidChangeManagedSettings.event;
39
>
40
>
get managedSettings(): ManagedSettingsData {
41
>
return Object.fromEntries(this.managedSettingsValues);
42
>
}
43
>
44
>
constructor(
45
@ILogService private readonly logService: ILogService,
46
private readonly productName: string,