117
118
protected async generateSyncPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, isRemoteDataFromCurrentMachine: boolean): Promise<IGlobalStateResourcePreview[]> {
119
>
const remoteGlobalState: IGlobalState = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null;
globalStateSync.ts
120
>
121
>
// Use remote data as last sync data if last sync data does not exist and remote data is from same machine
122
>
lastSyncUserData = lastSyncUserData === null && isRemoteDataFromCurrentMachine ? remoteUserData : lastSyncUserData;
123
>
const lastSyncGlobalState: IGlobalState | null = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null;
124
>
125
>
const localGlobalState = await this.localGlobalStateProvider.getLocalGlobalState(this.syncResource.profile);
126
>
127
>
if (remoteGlobalState) {
128
this.logService.trace(`${this.syncResourceLogLabel}: Merging remote ui state with local ui state...`);
130
>
this.logService.trace(`${this.syncResourceLogLabel}: Remote ui state does not exist. Synchronizing ui state for the first time.`);
131
>
}
132
>
133
>
const storageKeys = await this.getStorageKeys(lastSyncGlobalState);
134
>
const { local, remote } = merge(localGlobalState.storage, remoteGlobalState ? remoteGlobalState.storage : null, lastSyncGlobalState ? lastSyncGlobalState.storage : null, storageKeys, this.logService);
135
>
const previewResult: IGlobalStateResourceMergeResult = {
136
>
content: null,
137
>
local,
138
>
remote,
139
>
localChange: Object.keys(local.added).length > 0 || Object.keys(local.updated).length > 0 || local.removed.length > 0 ? Change.Modified : Change.None,
140
>
remoteChange: remote.all !== null ? Change.Modified : Change.None,
141
>
};
142
>
143
>
const localContent = stringify(localGlobalState, false);
144
>
return [{
145
>
baseResource: this.baseResource,
146
>
baseContent: lastSyncGlobalState ? stringify(lastSyncGlobalState, false) : localContent,
147
>
localResource: this.localResource,
148
>
localContent,
149
>
localUserData: localGlobalState,
150
>
remoteResource: this.remoteResource,
151
>
remoteContent: remoteGlobalState ? stringify(remoteGlobalState, false) : null,
152
>
previewResource: this.previewResource,
153
>
previewResult,
154
>
localChange: previewResult.localChange,
155
>
remoteChange: previewResult.remoteChange,
156
>
acceptedResource: this.acceptedResource,
157
>
storageKeys
158
>
}];
159
>
}
160
161
protected async hasRemoteChanged(lastSyncUserData: IRemoteUserData): Promise<boolean> {