Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cloud Changes enablement placeholder #187761

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
) {
// store the fact that we prompted the user
this.storageService.store(EditSessionsContribution.APPLICATION_LAUNCHED_VIA_CONTINUE_ON_STORAGE_KEY, true, StorageScope.APPLICATION, StorageTarget.MACHINE);
await this.editSessionsStorageService.initialize();
await this.editSessionsStorageService.initialize('read');
if (this.editSessionsStorageService.isSignedIn) {
await this.progressService.withProgress(resumeProgressOptions, async (progress) => await this.resumeEditSession(undefined, true, undefined, undefined, progress));
} else {
Expand Down Expand Up @@ -491,7 +491,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

this.logService.info(ref !== undefined ? `Resuming changes from cloud with ref ${ref}...` : 'Checking for pending cloud changes...');

if (silent && !(await this.editSessionsStorageService.initialize(true))) {
if (silent && !(await this.editSessionsStorageService.initialize('read', true))) {
return;
}

Expand Down Expand Up @@ -838,7 +838,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
return continueWithCloudChanges;
}

const initialized = await this.editSessionsStorageService.initialize();
const initialized = await this.editSessionsStorageService.initialize('write');
if (!initialized) {
this.telemetryService.publicLog2<EditSessionsAuthCheckEvent, EditSessionsAuthCheckClassification>('continueOn.editSessions.canStore.outcome', { outcome: 'didNotEnableEditSessionsWhenPrompted' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
* @returns The ref of the stored state.
*/
async write(resource: SyncResource, content: string | EditSession): Promise<string> {
await this.initialize(false);
await this.initialize('write', false);
if (!this.initialized) {
throw new Error('Please sign in to store your edit session.');
}
Expand All @@ -131,7 +131,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
* @returns An object representing the requested or latest state, if any.
*/
async read(resource: SyncResource, ref: string | undefined): Promise<{ ref: string; content: string } | undefined> {
await this.initialize(false);
await this.initialize('read', false);
if (!this.initialized) {
throw new Error('Please sign in to apply your latest edit session.');
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}

async delete(resource: SyncResource, ref: string | null) {
await this.initialize(false);
await this.initialize('write', false);
if (!this.initialized) {
throw new Error(`Unable to delete edit session with ref ${ref}.`);
}
Expand All @@ -172,7 +172,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}

async list(resource: SyncResource): Promise<IResourceRefHandle[]> {
await this.initialize(false);
await this.initialize('read', false);
if (!this.initialized) {
throw new Error(`Unable to list edit sessions.`);
}
Expand All @@ -186,11 +186,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return [];
}

public async initialize(silent: boolean = false) {
public async initialize(reason: 'read' | 'write', silent: boolean = false) {
if (this.initialized) {
return true;
}
this.initialized = await this.doInitialize(silent);
this.initialized = await this.doInitialize(reason, silent);
this.signedInContext.set(this.initialized);
if (this.initialized) {
this._didSignIn.fire();
Expand All @@ -205,7 +205,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
* meaning that authentication is configured and it
* can be used to communicate with the remote storage service
*/
private async doInitialize(silent: boolean): Promise<boolean> {
private async doInitialize(reason: 'read' | 'write', silent: boolean): Promise<boolean> {
// Wait for authentication extensions to be registered
await this.extensionService.whenInstalledExtensionsRegistered();

Expand All @@ -231,7 +231,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return true;
}

const authenticationSession = await this.getAuthenticationSession(silent);
const authenticationSession = await this.getAuthenticationSession(reason, silent);
if (authenticationSession !== undefined) {
this.authenticationInfo = authenticationSession;
this.storeClient.setAuthToken(authenticationSession.token, authenticationSession.providerId);
Expand All @@ -243,7 +243,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
private cachedMachines: Map<string, string> | undefined;

async getMachineById(machineId: string) {
await this.initialize(false);
await this.initialize('read', false);

if (!this.cachedMachines) {
const machines = await this.machineClient!.getMachines();
Expand All @@ -264,7 +264,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return currentMachineId;
}

private async getAuthenticationSession(silent: boolean) {
private async getAuthenticationSession(reason: 'read' | 'write', silent: boolean) {
// If the user signed in previously and the session is still available, reuse that without prompting the user again
if (this.existingSessionId) {
this.logService.info(`Searching for existing authentication session with ID ${this.existingSessionId}`);
Expand Down Expand Up @@ -295,7 +295,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}

// Ask the user to pick a preferred account
const authenticationSession = await this.getAccountPreference();
const authenticationSession = await this.getAccountPreference(reason);
if (authenticationSession !== undefined) {
this.existingSessionId = authenticationSession.id;
return { sessionId: authenticationSession.id, token: authenticationSession.idToken ?? authenticationSession.accessToken, providerId: authenticationSession.providerId };
Expand All @@ -312,10 +312,10 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
*
* Prompts the user to pick an authentication option for storing and getting edit sessions.
*/
private async getAccountPreference(): Promise<AuthenticationSession & { providerId: string } | undefined> {
private async getAccountPreference(reason: 'read' | 'write'): Promise<AuthenticationSession & { providerId: string } | undefined> {
const quickpick = this.quickInputService.createQuickPick<ExistingSession | AuthenticationProviderOption | IQuickPickItem>();
quickpick.ok = false;
quickpick.placeholder = localize('choose account placeholder', "Select an account to store your working changes in the cloud");
quickpick.placeholder = reason === 'read' ? localize('choose account read placeholder', "Select an account to restore your working changes from the cloud") : localize('choose account placeholder', "Select an account to store your working changes in the cloud");
quickpick.ignoreFocusOut = true;
quickpick.items = await this.createQuickpickItems();

Expand Down Expand Up @@ -482,7 +482,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}

async run() {
return await that.initialize(false);
return await that.initialize('write', false);
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IEditSessionsStorageService {
lastReadResources: Map<SyncResource, { ref: string; content: string }>;
lastWrittenResources: Map<SyncResource, { ref: string; content: string }>;

initialize(silent?: boolean): Promise<boolean>;
initialize(reason: 'read' | 'write', silent?: boolean): Promise<boolean>;
read(resource: SyncResource, ref: string | undefined): Promise<{ ref: string; content: string } | undefined>;
write(resource: SyncResource, content: string | EditSession): Promise<string>;
delete(resource: SyncResource, ref: string | null): Promise<void>;
Expand Down