mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { MainContext, MainThreadStorageShape, ExtHostStorageShape } from './extHost.protocol';
|
|
import { Emitter } from 'vs/base/common/event';
|
|
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
|
import { IExtensionIdWithVersion } from 'vs/platform/extensionManagement/common/extensionStorage';
|
|
|
|
export interface IStorageChangeEvent {
|
|
shared: boolean;
|
|
key: string;
|
|
value: object;
|
|
}
|
|
|
|
export class ExtHostStorage implements ExtHostStorageShape {
|
|
|
|
readonly _serviceBrand: undefined;
|
|
|
|
private _proxy: MainThreadStorageShape;
|
|
|
|
private readonly _onDidChangeStorage = new Emitter<IStorageChangeEvent>();
|
|
readonly onDidChangeStorage = this._onDidChangeStorage.event;
|
|
|
|
constructor(mainContext: IExtHostRpcService) {
|
|
this._proxy = mainContext.getProxy(MainContext.MainThreadStorage);
|
|
}
|
|
|
|
registerExtensionStorageKeysToSync(extension: IExtensionIdWithVersion, keys: string[]): void {
|
|
this._proxy.$registerExtensionStorageKeysToSync(extension, keys);
|
|
}
|
|
|
|
initializeExtensionStorage(shared: boolean, key: string, defaultValue?: object): Promise<object | undefined> {
|
|
return this._proxy.$initializeExtensionStorage(shared, key).then(value => value || defaultValue);
|
|
}
|
|
|
|
setValue(shared: boolean, key: string, value: object): Promise<void> {
|
|
return this._proxy.$setValue(shared, key, value);
|
|
}
|
|
|
|
$acceptValue(shared: boolean, key: string, value: object): void {
|
|
this._onDidChangeStorage.fire({ shared, key, value });
|
|
}
|
|
}
|
|
|
|
export interface IExtHostStorage extends ExtHostStorage { }
|
|
export const IExtHostStorage = createDecorator<IExtHostStorage>('IExtHostStorage');
|