#100346 introduce manual sync task

This commit is contained in:
Sandeep Somavarapu
2020-07-10 19:03:40 +02:00
parent 6a4866acd2
commit a25e2dbb56
6 changed files with 284 additions and 23 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { SyncStatus, SyncResource, IUserDataSyncService, UserDataSyncError, SyncResourceConflicts, ISyncResourceHandle, ISyncTask } from 'vs/platform/userDataSync/common/userDataSync';
import { SyncStatus, SyncResource, IUserDataSyncService, UserDataSyncError, SyncResourceConflicts, ISyncResourceHandle, ISyncTask, IManualSyncTask, IUserDataManifest, ISyncResourcePreview } 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';
@@ -41,7 +41,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
get onSynchronizeResource(): Event<SyncResource> { return this.channel.listen<SyncResource>('onSynchronizeResource'); }
constructor(
@ISharedProcessService sharedProcessService: ISharedProcessService
@ISharedProcessService private readonly sharedProcessService: ISharedProcessService
) {
super();
const userDataSyncChannel = sharedProcessService.getChannel('userDataSync');
@@ -75,6 +75,11 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
throw new Error('not supported');
}
async createManualSyncTask(): Promise<IManualSyncTask> {
const { initialData, channelName } = await this.channel.call<{ initialData: { manifest: IUserDataManifest | null }, channelName: string }>('createManualSyncTask');
return new ManualSyncTask(this.sharedProcessService.getChannel(channelName), initialData.manifest);
}
replace(uri: URI): Promise<void> {
return this.channel.call('replace', [uri]);
}
@@ -91,6 +96,10 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
return this.channel.call('hasPreviouslySynced');
}
hasLocalData(): Promise<boolean> {
return this.channel.call('hasLocalData');
}
isFirstTimeSyncingWithAnotherMachine(): Promise<boolean> {
return this.channel.call('isFirstTimeSyncingWithAnotherMachine');
}
@@ -151,4 +160,46 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
}
}
class ManualSyncTask implements IManualSyncTask {
constructor(private readonly channel: IChannel, readonly manifest: IUserDataManifest | null) { }
async preview(): Promise<[SyncResource, ISyncResourcePreview][]> {
const previews = await this.channel.call<[SyncResource, ISyncResourcePreview][]>('preview');
return previews.map(([syncResource, preview]) =>
([
syncResource,
{
isLastSyncFromCurrentMachine: preview.isLastSyncFromCurrentMachine,
resourcePreviews: preview.resourcePreviews.map(r => ({
...r,
localResource: URI.revive(r.localResource),
remoteResource: URI.revive(r.remoteResource),
previewResource: URI.revive(r.previewResource),
}))
}
]));
}
accept(uri: URI, content: string): Promise<[SyncResource, ISyncResourcePreview][]> {
return this.channel.call('accept', [uri, content]);
}
merge(): Promise<[SyncResource, ISyncResourcePreview][]> {
return this.channel.call('merge');
}
pull(): Promise<void> {
return this.channel.call('pull');
}
push(): Promise<void> {
return this.channel.call('push');
}
stop(): Promise<void> {
return this.channel.call('stop');
}
}
registerSingleton(IUserDataSyncService, UserDataSyncService);