mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { SyncStatus, SyncSource, IUserDataSyncService } from 'vs/platform/userDataSync/common/userDataSync';
|
|
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
|
|
import { Disposable } from 'vs/base/common/lifecycle';
|
|
import { Emitter, Event } from 'vs/base/common/event';
|
|
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
|
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
|
import { IExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
|
|
|
export class UserDataSyncService extends Disposable implements IUserDataSyncService {
|
|
|
|
_serviceBrand: undefined;
|
|
|
|
private readonly channel: IChannel;
|
|
|
|
private _status: SyncStatus = SyncStatus.Uninitialized;
|
|
get status(): SyncStatus { return this._status; }
|
|
private _onDidChangeStatus: Emitter<SyncStatus> = this._register(new Emitter<SyncStatus>());
|
|
readonly onDidChangeStatus: Event<SyncStatus> = this._onDidChangeStatus.event;
|
|
|
|
get onDidChangeLocal(): Event<void> { return this.channel.listen('onDidChangeLocal'); }
|
|
|
|
private _conflictsSource: SyncSource | null = null;
|
|
get conflictsSource(): SyncSource | null { return this._conflictsSource; }
|
|
|
|
constructor(
|
|
@ISharedProcessService sharedProcessService: ISharedProcessService
|
|
) {
|
|
super();
|
|
this.channel = sharedProcessService.getChannel('userDataSync');
|
|
this.channel.call<SyncStatus>('_getInitialStatus').then(status => {
|
|
this.updateStatus(status);
|
|
this._register(this.channel.listen<SyncStatus>('onDidChangeStatus')(status => this.updateStatus(status)));
|
|
});
|
|
}
|
|
|
|
pull(): Promise<void> {
|
|
return this.channel.call('pull');
|
|
}
|
|
|
|
push(): Promise<void> {
|
|
return this.channel.call('push');
|
|
}
|
|
|
|
sync(_continue?: boolean): Promise<boolean> {
|
|
return this.channel.call('sync', [_continue]);
|
|
}
|
|
|
|
reset(): Promise<void> {
|
|
return this.channel.call('reset');
|
|
}
|
|
|
|
resetLocal(): Promise<void> {
|
|
return this.channel.call('resetLocal');
|
|
}
|
|
|
|
stop(): void {
|
|
this.channel.call('stop');
|
|
}
|
|
|
|
hasPreviouslySynced(): Promise<boolean> {
|
|
return this.channel.call('hasPreviouslySynced');
|
|
}
|
|
|
|
hasRemote(): Promise<boolean> {
|
|
return this.channel.call('hasRemote');
|
|
}
|
|
|
|
removeExtension(identifier: IExtensionIdentifier): Promise<void> {
|
|
return this.channel.call('removeExtension', [identifier]);
|
|
}
|
|
|
|
private async updateStatus(status: SyncStatus): Promise<void> {
|
|
this._conflictsSource = await this.channel.call<SyncSource>('getConflictsSource');
|
|
this._status = status;
|
|
this._onDidChangeStatus.fire(status);
|
|
}
|
|
|
|
}
|
|
|
|
registerSingleton(IUserDataSyncService, UserDataSyncService);
|