Skip to content

Commit

Permalink
sync status
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Aug 26, 2019
1 parent 2be6618 commit 42d1bb1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
26 changes: 16 additions & 10 deletions src/vs/workbench/contrib/userData/common/userData.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IUserIdentityService, IUserDataProviderService, IUserIdentity } from 'vs/workbench/services/userData/common/userData';
import { IUserIdentityService, IUserDataProviderService, IUserIdentity, IUserDataSyncService, SyncStatus } from 'vs/workbench/services/userData/common/userData';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
import { localize } from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -37,21 +37,24 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
}
});

class UserDataExtensionActivationContribution extends Disposable implements IWorkbenchContribution {
class AutoSyncUserDataContribution extends Disposable implements IWorkbenchContribution {

constructor(
@IConfigurationService private readonly configurationService: IConfigurationService,
@IUserIdentityService private readonly userIdentityService: IUserIdentityService,
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
@IExtensionService private readonly extensionService: IExtensionService,
) {
super();
this.activateUserDataExtensionsOnAutoSync();
this._register(Event.any<any>(this.userIdentityService.onDidDeregisterUserIdentities, this.configurationService.onDidChangeConfiguration)(() => this.activateUserDataExtensionsOnAutoSync()));
this.autoSync();
this._register(Event.any<any>(this.userIdentityService.onDidDeregisterUserIdentities, this.configurationService.onDidChangeConfiguration)(() => this.autoSync()));
}

private activateUserDataExtensionsOnAutoSync(): void {
private async autoSync(): Promise<void> {
if (this.configurationService.getValue<boolean>('userData.autoSync')) {
this.userIdentityService.getUserIndetities().forEach(({ identity }) => this.extensionService.activateByEvent(`onUserData:${identity}`));
const userIdentity = this.userIdentityService.getUserIndetities()[0];
await this.extensionService.activateByEvent(`onUserData:${userIdentity.identity}`);
this.userDataSyncService.synchronise();
}
}

Expand All @@ -63,7 +66,8 @@ class UserDataSyncStatusContribution extends Disposable implements IWorkbenchCon

constructor(
@IUserIdentityService private userIdentityService: IUserIdentityService,
@IStatusbarService private statusbarService: IStatusbarService
@IStatusbarService private statusbarService: IStatusbarService,
@IUserDataSyncService private userDataSyncService: IUserDataSyncService,
) {
super();
this.userDataSyncStatusAccessor = this.statusbarService.addEntry({
Expand All @@ -73,7 +77,8 @@ class UserDataSyncStatusContribution extends Disposable implements IWorkbenchCon
this.updateUserDataSyncStatusAccessor();
this._register(Event.any<any>(
this.userIdentityService.onDidRegisterUserIdentities, this.userIdentityService.onDidDeregisterUserIdentities,
this.userIdentityService.onDidRegisterUserLoginProvider, this.userIdentityService.onDidDeregisterUserLoginProvider)
this.userIdentityService.onDidRegisterUserLoginProvider, this.userIdentityService.onDidDeregisterUserLoginProvider,
this.userDataSyncService.onDidChangeSyncStatus)
(() => this.updateUserDataSyncStatusAccessor()));
this._register(this.userIdentityService.onDidRegisterUserLoginProvider((identity => this.onDidRegisterUserLoginProvider(identity))));
}
Expand Down Expand Up @@ -104,15 +109,16 @@ class UserDataSyncStatusContribution extends Disposable implements IWorkbenchCon
return userIdentity.iconText ? `${userIdentity.iconText} ${signinText}` : signinText;
}
if (userIdentity.iconText) {
return `${userIdentity.iconText} ${localize('sync user data', "{0}: Sync", userIdentity.title)}`;
const syncText = this.userDataSyncService.syncStatus === SyncStatus.Syncing ? localize('syncing', "{0}: Synchronosing...", userIdentity.title) : localize('sync user data', "{0}: Sync", userIdentity.title);
return `${userIdentity.iconText} ${syncText}`;
}
return userIdentity.title;
}
}

const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(UserDataSyncStatusContribution, LifecyclePhase.Starting);
workbenchRegistry.registerWorkbenchContribution(UserDataExtensionActivationContribution, LifecyclePhase.Ready);
workbenchRegistry.registerWorkbenchContribution(AutoSyncUserDataContribution, LifecyclePhase.Ready);

export class ShowUserDataSyncActions extends Action {

Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/services/userData/common/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,19 @@ export interface IUserDataExtension {
version?: string;
}

export enum SyncStatus {
Syncing = 1,
SyncDone
}

export interface IUserDataSyncService {

_serviceBrand: any;

readonly syncStatus: SyncStatus;

readonly onDidChangeSyncStatus: Event<SyncStatus>;

synchronise(): Promise<void>;

getExtensions(): Promise<IUserDataExtension[]>;
Expand Down
25 changes: 22 additions & 3 deletions src/vs/workbench/services/userData/common/userDataSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,41 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IUserDataSyncService, IUserDataProviderService, IUserDataExtension } from 'vs/workbench/services/userData/common/userData';
import { IUserDataSyncService, IUserDataProviderService, IUserDataExtension, SyncStatus } from 'vs/workbench/services/userData/common/userData';
import { Disposable } from 'vs/base/common/lifecycle';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Emitter, Event } from 'vs/base/common/event';
import { timeout } from 'vs/base/common/async';

export class UserDataSyncService extends Disposable implements IUserDataSyncService {

_serviceBrand: any;

private _onDidChangeSyncStatus: Emitter<SyncStatus> = this._register(new Emitter<SyncStatus>());
readonly onDidChangeSyncStatus: Event<SyncStatus> = this._onDidChangeSyncStatus.event;

private _syncStatus: SyncStatus = SyncStatus.SyncDone;
get syncStatus(): SyncStatus {
return this._syncStatus;
}
set syncStatus(status: SyncStatus) {
if (this._syncStatus !== status) {
this._syncStatus = status;
this._onDidChangeSyncStatus.fire(status);
}
}

constructor(
@IUserDataProviderService private readonly userDataProviderService: IUserDataProviderService
) {
super();
}

synchronise(): Promise<void> {
return Promise.resolve();

async synchronise(): Promise<void> {
this.syncStatus = SyncStatus.Syncing;
await timeout(5000);
this.syncStatus = SyncStatus.SyncDone;
}

getExtensions(): Promise<IUserDataExtension[]> {
Expand Down

0 comments on commit 42d1bb1

Please sign in to comment.