Skip to content

Commit

Permalink
Merge pull request #158695 from microsoft/sandy081/yearling-otter
Browse files Browse the repository at this point in the history
Introduce transient profiles
  • Loading branch information
sandy081 committed Aug 22, 2022
2 parents 88519c1 + 97ab35d commit ac6a9ce
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';

export class UserDataProfilesCleaner extends Disposable {

constructor(
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
) {
super();
userDataProfilesService.cleanUp();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/pol
import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile';
import { SharedProcessRequestService } from 'vs/platform/request/electron-browser/sharedProcessRequestService';
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
import { UserDataProfilesCleaner } from 'vs/code/electron-browser/sharedProcess/contrib/userDataProfilesCleaner';

class SharedProcessMain extends Disposable {

Expand Down Expand Up @@ -169,7 +170,8 @@ class SharedProcessMain extends Disposable {
instantiationService.createInstance(StorageDataCleaner, this.configuration.backupWorkspacesPath),
instantiationService.createInstance(LogsDataCleaner),
instantiationService.createInstance(LocalizationsUpdater),
instantiationService.createInstance(ExtensionsCleaner)
instantiationService.createInstance(ExtensionsCleaner),
instantiationService.createInstance(UserDataProfilesCleaner)
));
}

Expand Down
4 changes: 4 additions & 0 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { IRequestService } from 'vs/platform/request/common/request';
import { ExtensionsProfileScannerService, IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService';
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';
import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService';
import { UserDataTransientProfilesHandler } from 'vs/platform/userDataProfile/electron-main/userDataTransientProfilesHandler';

/**
* The main VS Code application. There will only ever be one instance,
Expand Down Expand Up @@ -562,6 +563,9 @@ export class CodeApplication extends Disposable {

// Default Extensions Profile Init Handler
this._register(instantiationService.createInstance(DefaultExtensionsProfileInitHandler));

// Transient profiles handler
this._register(instantiationService.createInstance(UserDataTransientProfilesHandler));
}

private async resolveMachineId(): Promise<string> {
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface NativeParsedArgs {
editSessionId?: string;
'locate-shell-integration-path'?: string;
'profile'?: string;
'profile-transient'?: boolean;

// chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches
'no-proxy-server'?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
'locale': { type: 'string', cat: 'o', args: 'locale', description: localize('locale', "The locale to use (e.g. en-US or zh-TW).") },
'user-data-dir': { type: 'string', cat: 'o', args: 'dir', description: localize('userDataDir', "Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.") },
'profile': { type: 'string', 'cat': 'o', args: 'settingsProfileName', description: localize('settingsProfileName', "Opens the provided folder or workspace with the given profile. If the profile does not exist, a new empty one is created.") },
'profile-transient': { type: 'boolean', 'cat': 'o', description: localize('transientProfile', "Creates an empty transient profile and opens the provided folder or workspace with this profile.") },
'help': { type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") },

'extensions-dir': { type: 'string', deprecates: ['extensionHomePath'], cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") },
Expand Down
32 changes: 29 additions & 3 deletions src/vs/platform/userDataProfile/browser/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,42 @@ export class BrowserUserDataProfilesService extends UserDataProfilesService impl
this._register(this.changesBroadcastChannel.onDidReceiveData(changes => {
try {
this._profilesObject = undefined;
const added = changes.added.map(p => reviveProfile(p, this.profilesHome.scheme));
const removed = changes.removed.map(p => reviveProfile(p, this.profilesHome.scheme));
const updated = changes.updated.map(p => reviveProfile(p, this.profilesHome.scheme));

this.updateTransientProfiles(
added.filter(a => a.isTransient),
removed.filter(a => a.isTransient),
updated.filter(a => a.isTransient)
);

this._onDidChangeProfiles.fire({
added: changes.added.map(p => reviveProfile(p, this.profilesHome.scheme)),
removed: changes.removed.map(p => reviveProfile(p, this.profilesHome.scheme)),
updated: changes.updated.map(p => reviveProfile(p, this.profilesHome.scheme)),
added,
removed,
updated,
all: this.profiles
});
} catch (error) {/* ignore */ }
}));
}

private updateTransientProfiles(added: IUserDataProfile[], removed: IUserDataProfile[], updated: IUserDataProfile[]): void {
if (added.length) {
this.transientProfilesObject.profiles.push(...added);
}
if (removed.length || updated.length) {
const allTransientProfiles = this.transientProfilesObject.profiles;
this.transientProfilesObject.profiles = [];
for (const profile of allTransientProfiles) {
if (removed.some(p => profile.id === p.id)) {
continue;
}
this.transientProfilesObject.profiles.push(updated.find(p => profile.id === p.id) ?? profile);
}
}
}

override setEnablement(enabled: boolean): void {
super.setEnablement(enabled);
window.localStorage.setItem(PROFILES_ENABLEMENT_CONFIG, enabled ? 'true' : 'false');
Expand Down

0 comments on commit ac6a9ce

Please sign in to comment.