Implement IExtensionRuntimeService

This commit is contained in:
Sandeep Somavarapu
2016-10-12 16:57:55 +02:00
parent 1e6c1e692f
commit 5103b15943
9 changed files with 95 additions and 69 deletions

View File

@@ -7,14 +7,12 @@
import * as fs from 'fs';
import * as crypto from 'crypto';
import * as paths from 'vs/base/common/paths';
import { IDisposable } from 'vs/base/common/lifecycle';
import types = require('vs/base/common/types');
import errors = require('vs/base/common/errors');
import strings = require('vs/base/common/strings');
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ConfigWatcher } from 'vs/base/node/config';
// Browser localStorage interface
export interface IStorage {
@@ -200,7 +198,7 @@ export class Storage implements IStorageService {
public getStoragePath(scope: StorageScope): string {
if (StorageScope.GLOBAL === scope) {
return void 0;
return this.environmentService.appSettingsHome;
}
const workspace = this.contextService.getWorkspace();
@@ -255,18 +253,6 @@ export class Storage implements IStorageService {
return this.workspaceStoragePath;
}
getStorageData<T>(module: string, scope: StorageScope = StorageScope.GLOBAL, defaultValue: T = Object.create(null)): T {
const storagePath = this.getStoragePath(scope);
if (!storagePath) {
return defaultValue;
}
const path = paths.join(storagePath, module + '.json');
const storageData = new StorageData<T>(path, defaultValue);
const data: T = storageData.getData();
storageData.dispose();
return data;
}
private toStorageKey(key: string, scope: StorageScope): string {
if (scope === StorageScope.GLOBAL) {
return Storage.GLOBAL_PREFIX + key.toLowerCase();
@@ -319,21 +305,4 @@ export class InMemoryLocalStorage implements IStorage {
}
}
export const inMemoryLocalStorageInstance = new InMemoryLocalStorage();
export class StorageData<T> implements IDisposable {
private _rawConfig: ConfigWatcher<T>;
constructor(path: string, defaultValue: T) {
this._rawConfig = new ConfigWatcher(path, { changeBufferDelay: 300, defaultConfig: defaultValue });
}
public getData(): T {
return this._rawConfig.getConfig();
}
public dispose() {
this._rawConfig.dispose();
}
}
export const inMemoryLocalStorageInstance = new InMemoryLocalStorage();