mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
adopt to application scope (#152286)
This commit is contained in:
parent
8559324b09
commit
6f7c824a82
|
@ -55,6 +55,7 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
|
|||
return undefined;
|
||||
}
|
||||
|
||||
/* TODO @sandy081: This has to be done across all profiles */
|
||||
static async removeOutdatedExtensionVersions(extensionManagementService: IExtensionManagementService, storageService: IStorageService): Promise<void> {
|
||||
const extensions = await extensionManagementService.getInstalled();
|
||||
const extensionVersionsToRemove: string[] = [];
|
||||
|
@ -193,7 +194,7 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
|
|||
}
|
||||
|
||||
private get migrationList(): [string, string][] {
|
||||
const value = this.storageService.get('extensionStorage.migrationList', StorageScope.GLOBAL, '[]');
|
||||
const value = this.storageService.get('extensionStorage.migrationList', StorageScope.APPLICATION, '[]');
|
||||
try {
|
||||
const migrationList = JSON.parse(value);
|
||||
if (isArray(migrationList)) {
|
||||
|
@ -205,9 +206,9 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
|
|||
|
||||
private set migrationList(migrationList: [string, string][]) {
|
||||
if (migrationList.length) {
|
||||
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
} else {
|
||||
this.storageService.remove('extensionStorage.migrationList', StorageScope.GLOBAL);
|
||||
this.storageService.remove('extensionStorage.migrationList', StorageScope.APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ function stringify(globalState: IGlobalState, format: boolean): string {
|
|||
const GLOBAL_STATE_DATA_VERSION = 1;
|
||||
|
||||
/**
|
||||
* TODO: @sandy081: Sync only global state of default profile
|
||||
*
|
||||
* Synchronises global state that includes
|
||||
* - Global storage with user scope
|
||||
* - Locale from argv properties
|
||||
|
|
|
@ -223,9 +223,9 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
|
||||
public markAsCompleted(experimentId: string): void {
|
||||
const storageKey = 'experiments.' + experimentId;
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
|
||||
experimentState.state = ExperimentState.Complete;
|
||||
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
}
|
||||
|
||||
protected async getExperiments(): Promise<IRawExperiment[] | null> {
|
||||
|
@ -255,11 +255,11 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
return this.getExperiments().then(rawExperiments => {
|
||||
// Offline mode
|
||||
if (!rawExperiments) {
|
||||
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.GLOBAL), []);
|
||||
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.APPLICATION), []);
|
||||
if (Array.isArray(allExperimentIdsFromStorage)) {
|
||||
allExperimentIdsFromStorage.forEach(experimentId => {
|
||||
const storageKey = 'experiments.' + experimentId;
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), null);
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), null);
|
||||
if (experimentState) {
|
||||
this._experiments.push({
|
||||
id: experimentId,
|
||||
|
@ -278,19 +278,19 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
rawExperiments = rawExperiments.filter(e => (e.schemaVersion || 0) <= currentSchemaVersion);
|
||||
|
||||
// Clear disbaled/deleted experiments from storage
|
||||
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.GLOBAL), []);
|
||||
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.APPLICATION), []);
|
||||
const enabledExperiments = rawExperiments.filter(experiment => !!experiment.enabled).map(experiment => experiment.id.toLowerCase());
|
||||
if (Array.isArray(allExperimentIdsFromStorage)) {
|
||||
allExperimentIdsFromStorage.forEach(experiment => {
|
||||
if (enabledExperiments.indexOf(experiment) === -1) {
|
||||
this.storageService.remove(`experiments.${experiment}`, StorageScope.GLOBAL);
|
||||
this.storageService.remove(`experiments.${experiment}`, StorageScope.APPLICATION);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (enabledExperiments.length) {
|
||||
this.storageService.store('allExperiments', JSON.stringify(enabledExperiments), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store('allExperiments', JSON.stringify(enabledExperiments), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
} else {
|
||||
this.storageService.remove('allExperiments', StorageScope.GLOBAL);
|
||||
this.storageService.remove('allExperiments', StorageScope.APPLICATION);
|
||||
}
|
||||
|
||||
const activationEvents = new Set(rawExperiments.map(exp => exp.condition?.activationEvent?.event)
|
||||
|
@ -348,7 +348,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
}
|
||||
|
||||
const storageKey = 'experiments.' + experiment.id;
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
|
||||
if (!experimentState.hasOwnProperty('enabled')) {
|
||||
experimentState.enabled = processedExperiment.enabled;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
|
||||
return this.shouldRunExperiment(experiment, processedExperiment).then((state: ExperimentState) => {
|
||||
experimentState.state = processedExperiment.state = state;
|
||||
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
|
||||
if (state === ExperimentState.Run) {
|
||||
this.fireRunExperiment(processedExperiment);
|
||||
|
@ -372,7 +372,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
|
||||
private fireRunExperiment(experiment: IExperiment) {
|
||||
this._onExperimentEnabled.fire(experiment);
|
||||
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.GLOBAL), []);
|
||||
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.APPLICATION), []);
|
||||
if (runExperimentIdsFromStorage.indexOf(experiment.id) === -1) {
|
||||
runExperimentIdsFromStorage.push(experiment.id);
|
||||
}
|
||||
|
@ -380,14 +380,14 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
// Ensure we dont store duplicates
|
||||
const distinctExperiments = distinct(runExperimentIdsFromStorage);
|
||||
if (runExperimentIdsFromStorage.length !== distinctExperiments.length) {
|
||||
this.storageService.store('currentOrPreviouslyRunExperiments', JSON.stringify(distinctExperiments), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store('currentOrPreviouslyRunExperiments', JSON.stringify(distinctExperiments), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
}
|
||||
}
|
||||
|
||||
private checkExperimentDependencies(experiment: IRawExperiment): boolean {
|
||||
const experimentsPreviouslyRun = experiment.condition?.experimentsPreviouslyRun;
|
||||
if (experimentsPreviouslyRun) {
|
||||
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.GLOBAL), []);
|
||||
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.APPLICATION), []);
|
||||
let includeCheck = true;
|
||||
let excludeCheck = true;
|
||||
const includes = experimentsPreviouslyRun.includes;
|
||||
|
@ -407,9 +407,9 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
|
||||
private recordActivatedEvent(event: string) {
|
||||
const key = experimentEventStorageKey(event);
|
||||
const record = getCurrentActivationRecord(safeParse(this.storageService.get(key, StorageScope.GLOBAL), undefined));
|
||||
const record = getCurrentActivationRecord(safeParse(this.storageService.get(key, StorageScope.APPLICATION), undefined));
|
||||
record.count[0]++;
|
||||
this.storageService.store(key, JSON.stringify(record), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(key, JSON.stringify(record), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
|
||||
this._experiments
|
||||
.filter(e => {
|
||||
|
@ -434,7 +434,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
|
||||
const events = typeof setting.event === 'string' ? [setting.event] : setting.event;
|
||||
for (const event of events) {
|
||||
const { count } = getCurrentActivationRecord(safeParse(this.storageService.get(experimentEventStorageKey(event), StorageScope.GLOBAL), undefined));
|
||||
const { count } = getCurrentActivationRecord(safeParse(this.storageService.get(experimentEventStorageKey(event), StorageScope.APPLICATION), undefined));
|
||||
|
||||
for (const entry of count) {
|
||||
if (entry > 0) {
|
||||
|
@ -532,7 +532,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
}
|
||||
|
||||
const storageKey = 'experiments.' + experiment.id;
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
|
||||
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
|
||||
|
||||
return extensionsCheckPromise.then(success => {
|
||||
const fileEdits = condition.fileEdits;
|
||||
|
@ -549,7 +549,7 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
// Process model-save event every 250ms to reduce load
|
||||
const onModelsSavedWorker = this._register(new RunOnceWorker<ITextFileEditorModel>(models => {
|
||||
const date = new Date().toDateString();
|
||||
const latestExperimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
|
||||
const latestExperimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
|
||||
if (latestExperimentState.state !== ExperimentState.Evaluating) {
|
||||
onSaveHandler.dispose();
|
||||
onModelsSavedWorker.dispose();
|
||||
|
@ -579,12 +579,12 @@ export class ExperimentService extends Disposable implements IExperimentService
|
|||
if (filePathCheck && workspaceCheck) {
|
||||
latestExperimentState.editCount = (latestExperimentState.editCount || 0) + 1;
|
||||
latestExperimentState.lastEditedDate = date;
|
||||
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
}
|
||||
});
|
||||
if (typeof latestExperimentState.editCount === 'number' && latestExperimentState.editCount >= fileEdits.minEditCount) {
|
||||
processedExperiment.state = latestExperimentState.state = (typeof condition.userProbability === 'number' && Math.random() < condition.userProbability && this.checkExperimentDependencies(experiment)) ? ExperimentState.Run : ExperimentState.NoRun;
|
||||
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
if (latestExperimentState.state === ExperimentState.Run && processedExperiment.action && ExperimentActionType[processedExperiment.action.type] === ExperimentActionType.Prompt) {
|
||||
this.fireRunExperiment(processedExperiment);
|
||||
}
|
||||
|
|
|
@ -535,7 +535,7 @@ suite('Experiment Service', () => {
|
|||
didGetCall = true;
|
||||
assert.strictEqual(key, 'experimentEventRecord-my-event');
|
||||
assert.deepStrictEqual(JSON.parse(value).count, [1, 0, 10, 0, 0, 0, 0]);
|
||||
assert.strictEqual(scope, StorageScope.GLOBAL);
|
||||
assert.strictEqual(scope, StorageScope.APPLICATION);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1568,7 +1568,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
|
|||
}).then(undefined, error => this.onError(error));
|
||||
}
|
||||
|
||||
|
||||
/* TODO: @sandy081 Extension version shall be moved to extensions.json file */
|
||||
private _ignoredAutoUpdateExtensions: string[] | undefined;
|
||||
private get ignoredAutoUpdateExtensions(): string[] {
|
||||
if (!this._ignoredAutoUpdateExtensions) {
|
||||
|
|
|
@ -190,7 +190,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
|||
if (requiresInitialization && !this.userDataSyncEnablementService.isEnabled()) {
|
||||
this.updateSyncAfterInitializationContext(true);
|
||||
} else {
|
||||
this.updateSyncAfterInitializationContext(this.storageService.getBoolean(CONTEXT_SYNC_AFTER_INITIALIZATION.key, StorageScope.GLOBAL, false));
|
||||
this.updateSyncAfterInitializationContext(this.storageService.getBoolean(CONTEXT_SYNC_AFTER_INITIALIZATION.key, StorageScope.APPLICATION, false));
|
||||
}
|
||||
const disposable = this._register(this.userDataSyncEnablementService.onDidChangeEnablement(() => {
|
||||
if (this.userDataSyncEnablementService.isEnabled()) {
|
||||
|
@ -201,7 +201,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
|||
}
|
||||
|
||||
private async updateSyncAfterInitializationContext(value: boolean): Promise<void> {
|
||||
this.storageService.store(CONTEXT_SYNC_AFTER_INITIALIZATION.key, value, StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
this.storageService.store(CONTEXT_SYNC_AFTER_INITIALIZATION.key, value, StorageScope.APPLICATION, StorageTarget.MACHINE);
|
||||
this.syncAfterInitializationContext.set(value);
|
||||
this.updateGlobalActivityBadge();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue