Allow globalState to be synchronized across multiple windows (#61024)

* Allow globalState to be synchronized across multiple windows (fixes #55834)

* address some feedback
This commit is contained in:
Benjamin Pasero
2018-10-16 18:52:50 +02:00
committed by GitHub
parent c8e7e58cd0
commit 2ce9665b30
5 changed files with 74 additions and 20 deletions

View File

@@ -3,12 +3,22 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { MainContext, MainThreadStorageShape, IMainContext } from './extHost.protocol';
import { MainContext, MainThreadStorageShape, IMainContext, ExtHostStorageShape } from './extHost.protocol';
import { Emitter } from 'vs/base/common/event';
export class ExtHostStorage {
export interface IStorageChangeEvent {
shared: boolean;
key: string;
value: object;
}
export class ExtHostStorage implements ExtHostStorageShape {
private _proxy: MainThreadStorageShape;
private _onDidChangeStorage = new Emitter<IStorageChangeEvent>();
readonly onDidChangeStorage = this._onDidChangeStorage.event;
constructor(mainContext: IMainContext) {
this._proxy = mainContext.getProxy(MainContext.MainThreadStorage);
}
@@ -17,7 +27,11 @@ export class ExtHostStorage {
return this._proxy.$getValue<T>(shared, key).then(value => value || defaultValue);
}
setValue(shared: boolean, key: string, value: any): Thenable<void> {
setValue(shared: boolean, key: string, value: object): Thenable<void> {
return this._proxy.$setValue(shared, key, value);
}
$acceptValue(shared: boolean, key: string, value: object): void {
this._onDidChangeStorage.fire({ shared, key, value });
}
}