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,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { dispose } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { join } from 'path';
import { mkdirp, dirExists, realpath, writeFile } from 'vs/base/node/pfs';
import Severity from 'vs/base/common/severity';
@@ -30,6 +30,7 @@ class ExtensionMemento implements IExtensionMemento {
private readonly _init: Thenable<ExtensionMemento>;
private _value: { [n: string]: any; };
private readonly _storageListener: IDisposable;
constructor(id: string, global: boolean, storage: ExtHostStorage) {
this._id = id;
@@ -40,6 +41,12 @@ class ExtensionMemento implements IExtensionMemento {
this._value = value;
return this;
});
this._storageListener = this._storage.onDidChangeStorage(e => {
if (e.shared === this._shared && e.key === this._id) {
this._value = e.value;
}
});
}
get whenReady(): Thenable<ExtensionMemento> {
@@ -60,6 +67,10 @@ class ExtensionMemento implements IExtensionMemento {
.setValue(this._shared, this._id, this._value)
.then(() => true);
}
dispose(): void {
this._storageListener.dispose();
}
}
class ExtensionStoragePath {
@@ -150,7 +161,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
this._activator = null;
// initialize API first (i.e. do not release barrier until the API is initialized)
const apiFactory = createApiFactory(initData, extHostContext, extHostWorkspace, extHostConfiguration, this, this._extHostLogService);
const apiFactory = createApiFactory(initData, extHostContext, extHostWorkspace, extHostConfiguration, this, this._extHostLogService, this._storage);
initializeExtensionApi(this, apiFactory).then(() => {