Skip to content

Commit

Permalink
Increment global activity badge if edit sessions aren't turned on
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Sep 7, 2022
1 parent 4a178fc commit ea9a778
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
});
}

async run(accessor: ServicesAccessor, editSessionId?: string): Promise<void> {
async run(accessor: ServicesAccessor, editSessionId?: string, silent?: boolean): Promise<void> {
await that.progressService.withProgress(resumingProgressOptions, async () => {
type ResumeEvent = {};
type ResumeClassification = {
owner: 'joyceerhl'; comment: 'Reporting when the resume edit session action is invoked.';
};
that.telemetryService.publicLog2<ResumeEvent, ResumeClassification>('editSessions.resume');

await that.resumeEditSession(editSessionId);
await that.resumeEditSession(editSessionId, silent);
});
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
Expand All @@ -26,11 +26,15 @@ import { getCurrentAuthenticationSessionInfo } from 'vs/workbench/services/authe
import { isWeb } from 'vs/base/common/platform';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { Codicon } from 'vs/base/common/codicons';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { WorkspaceFolderCountContext } from 'vs/workbench/common/contextkeys';

type ExistingSession = IQuickPickItem & { session: AuthenticationSession & { providerId: string } };
type AuthenticationProviderOption = IQuickPickItem & { provider: IAuthenticationProvider };

const configureContinueOnPreference = { iconClass: Codicon.settingsGear.classNames, tooltip: localize('configure continue on', 'Configure this preference in settings') };
const turnOnEditSessionsTitle = localize('sign in', 'Turn on Edit Sessions...');

export class EditSessionsWorkbenchService extends Disposable implements IEditSessionsStorageService {

_serviceBrand = undefined;
Expand All @@ -48,6 +52,8 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return this.existingSessionId !== undefined;
}

private globalActivityBadgeDisposable = this._register(new MutableDisposable());

constructor(
@IFileService private readonly fileService: IFileService,
@IStorageService private readonly storageService: IStorageService,
Expand All @@ -61,7 +67,8 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
@IRequestService private readonly requestService: IRequestService,
@IDialogService private readonly dialogService: IDialogService,
@ICredentialsService private readonly credentialsService: ICredentialsService,
@ICommandService private readonly commandService: ICommandService
@ICommandService private readonly commandService: ICommandService,
@IActivityService private readonly activityService: IActivityService,
) {
super();

Expand All @@ -71,11 +78,13 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
// If another window changes the preferred session storage, reset our cached auth state in memory
this._register(this.storageService.onDidChangeValue(e => this.onDidChangeStorage(e)));

this.registerSignInAction();
this.registerTurnOnAction();
this.registerResetAuthenticationAction();

this.signedInContext = EDIT_SESSIONS_SIGNED_IN.bindTo(this.contextKeyService);
this.signedInContext.set(this.existingSessionId !== undefined);

this.updateGlobalActivityBadge();
}

/**
Expand Down Expand Up @@ -156,6 +165,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}
this.initialized = await this.doInitialize(fromContinueOn);
this.signedInContext.set(this.initialized);
this.updateGlobalActivityBadge();
return this.initialized;

}
Expand Down Expand Up @@ -398,13 +408,14 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}
}

private registerSignInAction() {
private registerTurnOnAction() {
const that = this;
this._register(registerAction2(class ResetEditSessionAuthenticationAction extends Action2 {
const when = ContextKeyExpr.equals(EDIT_SESSIONS_SIGNED_IN_KEY, false);
this._register(registerAction2(class TurnOnEditSessionsAction extends Action2 {
constructor() {
super({
id: 'workbench.editSessions.actions.signIn',
title: localize('sign in', 'Turn on Edit Sessions...'),
title: turnOnEditSessionsTitle,
category: EDIT_SESSION_SYNC_CATEGORY,
precondition: ContextKeyExpr.equals(EDIT_SESSIONS_SIGNED_IN_KEY, false),
menu: [{
Expand All @@ -413,7 +424,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
{
id: MenuId.AccountsContext,
group: '2_editSessions',
when: ContextKeyExpr.equals(EDIT_SESSIONS_SIGNED_IN_KEY, false),
when,
}]
});
}
Expand All @@ -422,6 +433,28 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return await that.initialize(false);
}
}));

this._register(registerAction2(class TurnOnEditSessionsAndResumeAction extends Action2 {
constructor() {
super({
id: 'workbench.editSessions.actions.turnOnAndResume',
title: turnOnEditSessionsTitle,
menu: {
group: '6_editSessions',
id: MenuId.GlobalActivity,
// Do not push for edit sessions when there are no workspace folders open
when: ContextKeyExpr.and(when, WorkspaceFolderCountContext.notEqualsTo(0)),
order: 2
}
});
}

async run() {
if (await that.initialize(false)) {
await that.commandService.executeCommand('workbench.experimental.editSessions.actions.resumeLatest', undefined, true);
}
}
}));
}

private registerResetAuthenticationAction() {
Expand Down Expand Up @@ -460,4 +493,13 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}
}));
}

private updateGlobalActivityBadge() {
if (this.initialized) {
return this.globalActivityBadgeDisposable.clear();
}

const badge = new NumberBadge(1, () => turnOnEditSessionsTitle);
this.globalActivityBadgeDisposable.value = this.activityService.showGlobalActivity({ badge, priority: 1 });
}
}

0 comments on commit ea9a778

Please sign in to comment.