@codingame/monaco-vscode-user-data-sync-service-override 1.85.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
  2. package/external/tslib/tslib.es6.js +11 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +1 -0
  5. package/override/vs/platform/dialogs/common/dialogs.js +8 -0
  6. package/override/vs/platform/userDataSync/common/extensionsSync.js +4 -0
  7. package/override/vs/platform/userDataSync/common/globalStateSync.js +5 -0
  8. package/package.json +24 -0
  9. package/userDataSync.d.ts +5 -0
  10. package/userDataSync.js +106 -0
  11. package/vscode/src/vs/base/browser/ui/icons/iconSelectBox.css.js +6 -0
  12. package/vscode/src/vs/base/browser/ui/icons/iconSelectBox.js +248 -0
  13. package/vscode/src/vs/platform/userDataProfile/browser/userDataProfile.js +95 -0
  14. package/vscode/src/vs/platform/userDataProfile/common/userDataProfileStorageService.js +5 -0
  15. package/vscode/src/vs/platform/userDataSync/common/abstractSynchronizer.js +774 -0
  16. package/vscode/src/vs/platform/userDataSync/common/extensionsSync.js +251 -0
  17. package/vscode/src/vs/platform/userDataSync/common/globalStateSync.js +115 -0
  18. package/vscode/src/vs/platform/userDataSync/common/keybindingsMerge.js +277 -0
  19. package/vscode/src/vs/platform/userDataSync/common/keybindingsSync.js +318 -0
  20. package/vscode/src/vs/platform/userDataSync/common/settingsSync.js +316 -0
  21. package/vscode/src/vs/platform/userDataSync/common/snippetsMerge.js +126 -0
  22. package/vscode/src/vs/platform/userDataSync/common/snippetsSync.js +476 -0
  23. package/vscode/src/vs/platform/userDataSync/common/tasksSync.js +244 -0
  24. package/vscode/src/vs/platform/userDataSync/common/userDataAutoSyncService.js +466 -0
  25. package/vscode/src/vs/platform/userDataSync/common/userDataProfilesManifestMerge.js +92 -0
  26. package/vscode/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.js +261 -0
  27. package/vscode/src/vs/platform/userDataSync/common/userDataSyncEnablementService.js +77 -0
  28. package/vscode/src/vs/platform/userDataSync/common/userDataSyncLocalStoreService.js +150 -0
  29. package/vscode/src/vs/platform/userDataSync/common/userDataSyncLog.js +41 -0
  30. package/vscode/src/vs/platform/userDataSync/common/userDataSyncResourceProvider.js +449 -0
  31. package/vscode/src/vs/platform/userDataSync/common/userDataSyncService.js +783 -0
  32. package/vscode/src/vs/platform/userDataSync/common/userDataSyncStoreService.js +553 -0
  33. package/vscode/src/vs/workbench/browser/iconSelectBox.js +98 -0
  34. package/vscode/src/vs/workbench/contrib/userDataSync/browser/userDataSync.contribution.js +111 -0
  35. package/vscode/src/vs/workbench/contrib/userDataSync/browser/userDataSync.js +1467 -0
  36. package/vscode/src/vs/workbench/contrib/userDataSync/browser/userDataSyncConflictsView.js +225 -0
  37. package/vscode/src/vs/workbench/contrib/userDataSync/browser/userDataSyncTrigger.js +61 -0
  38. package/vscode/src/vs/workbench/contrib/userDataSync/browser/userDataSyncViews.js +860 -0
  39. package/vscode/src/vs/workbench/services/userDataProfile/browser/extensionsResource.js +342 -0
  40. package/vscode/src/vs/workbench/services/userDataProfile/browser/globalStateResource.js +147 -0
  41. package/vscode/src/vs/workbench/services/userDataProfile/browser/keybindingsResource.js +119 -0
  42. package/vscode/src/vs/workbench/services/userDataProfile/browser/media/userDataProfileView.css.js +6 -0
  43. package/vscode/src/vs/workbench/services/userDataProfile/browser/settingsResource.js +140 -0
  44. package/vscode/src/vs/workbench/services/userDataProfile/browser/snippetsResource.js +155 -0
  45. package/vscode/src/vs/workbench/services/userDataProfile/browser/tasksResource.js +118 -0
  46. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.js +1753 -0
  47. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileInit.js +150 -0
  48. package/vscode/src/vs/workbench/services/userDataProfile/browser/userDataProfileManagement.js +190 -0
  49. package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncEnablementService.js +10 -0
  50. package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncInit.js +447 -0
  51. package/vscode/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.js +786 -0
  52. package/vscode/src/vs/workbench/services/userDataSync/browser/webUserDataSyncEnablementService.js +40 -0
  53. package/vscode/src/vs/workbench/services/userDataSync/common/userDataSyncUtil.js +48 -0
@@ -0,0 +1,786 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { USER_DATA_SYNC_SCHEME, USER_DATA_SYNC_LOG_ID, isAuthenticationProvider, IUserDataSyncService, IUserDataSyncEnablementService, IUserDataAutoSyncService, IUserDataSyncStoreManagementService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSync';
3
+ import { ITelemetryService } from 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
4
+ import { CONTEXT_SYNC_ENABLEMENT, CONTEXT_SYNC_STATE, CONTEXT_ACCOUNT_STATE, CONTEXT_ENABLE_ACTIVITY_VIEWS, CONTEXT_HAS_CONFLICTS, CONTEXT_ENABLE_SYNC_CONFLICTS_VIEW, SYNC_TITLE, SHOW_SYNC_LOG_COMMAND_ID, SYNC_CONFLICTS_VIEW_ID, SYNC_VIEW_CONTAINER_ID } from 'vscode/vscode/vs/workbench/services/userDataSync/common/userDataSync';
5
+ import { Disposable, DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
6
+ import { Emitter, Event } from 'monaco-editor/esm/vs/base/common/event.js';
7
+ import { getCurrentAuthenticationSessionInfo } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationService';
8
+ import { IAuthenticationService } from 'vscode/vscode/vs/workbench/services/authentication/common/authentication';
9
+ import { IUserDataSyncAccountService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSyncAccount';
10
+ import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
11
+ import { IStorageService } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
12
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
13
+ import { IProductService } from 'monaco-editor/esm/vs/platform/product/common/productService.js';
14
+ import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
15
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
16
+ import { Severity, INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
17
+ import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
18
+ import { IContextKeyService } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
19
+ import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
20
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
21
+ import { IViewsService, IViewDescriptorService } from 'vscode/vscode/vs/workbench/common/views';
22
+ import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
23
+ import { isWeb } from 'monaco-editor/esm/vs/base/common/platform.js';
24
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
25
+ import { UserDataSyncStoreClient } from '../../../../platform/userDataSync/common/userDataSyncStoreService.js';
26
+ import { UserDataSyncStoreTypeSynchronizer } from '../../../../../../../override/vs/platform/userDataSync/common/globalStateSync.js';
27
+ import { CancellationError } from 'monaco-editor/esm/vs/base/common/errors.js';
28
+ import { raceCancellationError } from 'monaco-editor/esm/vs/base/common/async.js';
29
+ import { CancellationTokenSource } from 'monaco-editor/esm/vs/base/common/cancellation.js';
30
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
31
+ import { IUriIdentityService } from 'monaco-editor/esm/vs/platform/uriIdentity/common/uriIdentity.js';
32
+ import { isDiffEditorInput } from 'vscode/vscode/vs/workbench/common/editor';
33
+ import { IBrowserWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/browser/environmentService';
34
+ import { IUserDataInitializationService } from 'vscode/vscode/vs/workbench/services/userData/browser/userDataInit';
35
+ import { ISecretStorageService } from 'vscode/vscode/vs/platform/secrets/common/secrets';
36
+ import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
37
+ import { escapeRegExpCharacters } from 'monaco-editor/esm/vs/base/common/strings.js';
38
+ import { IUserDataSyncMachinesService } from 'vscode/vscode/vs/platform/userDataSync/common/userDataSyncMachines';
39
+ import { IDialogService, IFileDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
40
+
41
+ var UserDataSyncWorkbenchService_1;
42
+ class UserDataSyncAccount {
43
+ constructor(authenticationProviderId, session) {
44
+ this.authenticationProviderId = authenticationProviderId;
45
+ this.session = session;
46
+ }
47
+ get sessionId() { return this.session.id; }
48
+ get accountName() { return this.session.account.label; }
49
+ get accountId() { return this.session.account.id; }
50
+ get token() { return this.session.idToken || this.session.accessToken; }
51
+ }
52
+ function isMergeEditorInput(editor) {
53
+ const candidate = editor;
54
+ return URI.isUri(candidate?.base) && URI.isUri(candidate?.input1?.uri) && URI.isUri(candidate?.input2?.uri) && URI.isUri(candidate?.result);
55
+ }
56
+ let UserDataSyncWorkbenchService = class UserDataSyncWorkbenchService extends Disposable {
57
+ static { UserDataSyncWorkbenchService_1 = this; }
58
+ static { this.DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY = 'userDataSyncAccount.donotUseWorkbenchSession'; }
59
+ static { this.CACHED_AUTHENTICATION_PROVIDER_KEY = 'userDataSyncAccountProvider'; }
60
+ static { this.CACHED_SESSION_STORAGE_KEY = 'userDataSyncAccountPreference'; }
61
+ get enabled() { return !!this.userDataSyncStoreManagementService.userDataSyncStore; }
62
+ get authenticationProviders() { return this._authenticationProviders; }
63
+ get accountStatus() { return this._accountStatus; }
64
+ get current() { return this._current; }
65
+ constructor(userDataSyncService, uriIdentityService, authenticationService, userDataSyncAccountService, quickInputService, storageService, userDataSyncEnablementService, userDataAutoSyncService, telemetryService, logService, productService, extensionService, environmentService, secretStorageService, notificationService, progressService, dialogService, contextKeyService, viewsService, viewDescriptorService, userDataSyncStoreManagementService, lifecycleService, instantiationService, editorService, userDataInitializationService, fileService, fileDialogService, userDataSyncMachinesService) {
66
+ super();
67
+ this.userDataSyncService = userDataSyncService;
68
+ this.uriIdentityService = uriIdentityService;
69
+ this.authenticationService = authenticationService;
70
+ this.userDataSyncAccountService = userDataSyncAccountService;
71
+ this.quickInputService = quickInputService;
72
+ this.storageService = storageService;
73
+ this.userDataSyncEnablementService = userDataSyncEnablementService;
74
+ this.userDataAutoSyncService = userDataAutoSyncService;
75
+ this.telemetryService = telemetryService;
76
+ this.logService = logService;
77
+ this.productService = productService;
78
+ this.extensionService = extensionService;
79
+ this.environmentService = environmentService;
80
+ this.secretStorageService = secretStorageService;
81
+ this.notificationService = notificationService;
82
+ this.progressService = progressService;
83
+ this.dialogService = dialogService;
84
+ this.viewsService = viewsService;
85
+ this.viewDescriptorService = viewDescriptorService;
86
+ this.userDataSyncStoreManagementService = userDataSyncStoreManagementService;
87
+ this.lifecycleService = lifecycleService;
88
+ this.instantiationService = instantiationService;
89
+ this.editorService = editorService;
90
+ this.userDataInitializationService = userDataInitializationService;
91
+ this.fileService = fileService;
92
+ this.fileDialogService = fileDialogService;
93
+ this.userDataSyncMachinesService = userDataSyncMachinesService;
94
+ this._authenticationProviders = [];
95
+ this._accountStatus = "unavailable" ;
96
+ this._onDidChangeAccountStatus = this._register(( new Emitter()));
97
+ this.onDidChangeAccountStatus = this._onDidChangeAccountStatus.event;
98
+ this.turnOnSyncCancellationToken = undefined;
99
+ this._cachedCurrentAuthenticationProviderId = null;
100
+ this._cachedCurrentSessionId = null;
101
+ this.syncEnablementContext = CONTEXT_SYNC_ENABLEMENT.bindTo(contextKeyService);
102
+ this.syncStatusContext = CONTEXT_SYNC_STATE.bindTo(contextKeyService);
103
+ this.accountStatusContext = CONTEXT_ACCOUNT_STATE.bindTo(contextKeyService);
104
+ this.activityViewsEnablementContext = CONTEXT_ENABLE_ACTIVITY_VIEWS.bindTo(contextKeyService);
105
+ this.hasConflicts = CONTEXT_HAS_CONFLICTS.bindTo(contextKeyService);
106
+ this.enableConflictsViewContext = CONTEXT_ENABLE_SYNC_CONFLICTS_VIEW.bindTo(contextKeyService);
107
+ if (this.userDataSyncStoreManagementService.userDataSyncStore) {
108
+ this.syncStatusContext.set(this.userDataSyncService.status);
109
+ this._register(userDataSyncService.onDidChangeStatus(status => this.syncStatusContext.set(status)));
110
+ this.syncEnablementContext.set(userDataSyncEnablementService.isEnabled());
111
+ this._register(userDataSyncEnablementService.onDidChangeEnablement(enabled => this.syncEnablementContext.set(enabled)));
112
+ this.waitAndInitialize();
113
+ }
114
+ }
115
+ updateAuthenticationProviders() {
116
+ this._authenticationProviders = (this.userDataSyncStoreManagementService.userDataSyncStore?.authenticationProviders || []).filter(({ id }) => ( this.authenticationService.declaredProviders.some(provider => provider.id === id)));
117
+ }
118
+ isSupportedAuthenticationProviderId(authenticationProviderId) {
119
+ return ( this.authenticationProviders.some(({ id }) => id === authenticationProviderId));
120
+ }
121
+ async waitAndInitialize() {
122
+ await Promise.all([this.extensionService.whenInstalledExtensionsRegistered(), this.userDataInitializationService.whenInitializationFinished()]);
123
+ try {
124
+ await this.initialize();
125
+ }
126
+ catch (error) {
127
+ if (!this.environmentService.extensionTestsLocationURI) {
128
+ this.logService.error(error);
129
+ }
130
+ }
131
+ }
132
+ async initialize() {
133
+ if (isWeb) {
134
+ const authenticationSession = await getCurrentAuthenticationSessionInfo(this.secretStorageService, this.productService);
135
+ if (this.currentSessionId === undefined && authenticationSession?.id) {
136
+ if (this.environmentService.options?.settingsSyncOptions?.authenticationProvider && this.environmentService.options.settingsSyncOptions.enabled) {
137
+ this.currentSessionId = authenticationSession.id;
138
+ }
139
+ else if (this.useWorkbenchSessionId) {
140
+ this.currentSessionId = authenticationSession.id;
141
+ }
142
+ this.useWorkbenchSessionId = false;
143
+ }
144
+ }
145
+ await this.update();
146
+ this._register(this.authenticationService.onDidChangeDeclaredProviders(() => this.updateAuthenticationProviders()));
147
+ this._register(Event.filter(Event.any(this.authenticationService.onDidRegisterAuthenticationProvider, this.authenticationService.onDidUnregisterAuthenticationProvider), info => this.isSupportedAuthenticationProviderId(info.id))(() => this.update()));
148
+ this._register(Event.filter(this.userDataSyncAccountService.onTokenFailed, isSuccessive => !isSuccessive)(() => this.update('token failure')));
149
+ this._register(Event.filter(this.authenticationService.onDidChangeSessions, e => this.isSupportedAuthenticationProviderId(e.providerId))(({ event }) => this.onDidChangeSessions(event)));
150
+ this._register(this.storageService.onDidChangeValue(-1 , UserDataSyncWorkbenchService_1.CACHED_SESSION_STORAGE_KEY, this._register(( new DisposableStore())))(() => this.onDidChangeStorage()));
151
+ this._register(Event.filter(this.userDataSyncAccountService.onTokenFailed, bailout => bailout)(() => this.onDidAuthFailure()));
152
+ this.hasConflicts.set(this.userDataSyncService.conflicts.length > 0);
153
+ this._register(this.userDataSyncService.onDidChangeConflicts(conflicts => {
154
+ this.hasConflicts.set(conflicts.length > 0);
155
+ if (!conflicts.length) {
156
+ this.enableConflictsViewContext.reset();
157
+ }
158
+ this.editorService.editors.filter(input => {
159
+ const remoteResource = isDiffEditorInput(input) ? input.original.resource : isMergeEditorInput(input) ? input.input1.uri : undefined;
160
+ if (remoteResource?.scheme !== USER_DATA_SYNC_SCHEME) {
161
+ return false;
162
+ }
163
+ return !( this.userDataSyncService.conflicts.some(({ conflicts }) => ( conflicts.some(
164
+ ({ previewResource }) => this.uriIdentityService.extUri.isEqual(previewResource, input.resource)
165
+ ))));
166
+ }).forEach(input => input.dispose());
167
+ }));
168
+ }
169
+ async update(reason) {
170
+ if (reason) {
171
+ this.logService.info(`Settings Sync: Updating due to ${reason}`);
172
+ }
173
+ this.updateAuthenticationProviders();
174
+ await this.updateCurrentAccount();
175
+ if (this._current) {
176
+ this.currentAuthenticationProviderId = this._current.authenticationProviderId;
177
+ }
178
+ await this.updateToken(this._current);
179
+ this.updateAccountStatus(this._current ? "available" : "unavailable" );
180
+ }
181
+ async updateCurrentAccount() {
182
+ const currentSessionId = this.currentSessionId;
183
+ const currentAuthenticationProviderId = this.currentAuthenticationProviderId;
184
+ if (currentSessionId) {
185
+ const authenticationProviders = currentAuthenticationProviderId ? this.authenticationProviders.filter(({ id }) => id === currentAuthenticationProviderId) : this.authenticationProviders;
186
+ for (const { id, scopes } of authenticationProviders) {
187
+ const sessions = (await this.authenticationService.getSessions(id, scopes)) || [];
188
+ for (const session of sessions) {
189
+ if (session.id === currentSessionId) {
190
+ this._current = ( new UserDataSyncAccount(id, session));
191
+ return;
192
+ }
193
+ }
194
+ }
195
+ }
196
+ this._current = undefined;
197
+ }
198
+ async updateToken(current) {
199
+ let value = undefined;
200
+ if (current) {
201
+ try {
202
+ this.logService.trace('Settings Sync: Updating the token for the account', current.accountName);
203
+ const token = current.token;
204
+ this.logService.trace('Settings Sync: Token updated for the account', current.accountName);
205
+ value = { token, authenticationProviderId: current.authenticationProviderId };
206
+ }
207
+ catch (e) {
208
+ this.logService.error(e);
209
+ }
210
+ }
211
+ await this.userDataSyncAccountService.updateAccount(value);
212
+ }
213
+ updateAccountStatus(accountStatus) {
214
+ if (this._accountStatus !== accountStatus) {
215
+ const previous = this._accountStatus;
216
+ this.logService.trace(`Settings Sync: Account status changed from ${previous} to ${accountStatus}`);
217
+ this._accountStatus = accountStatus;
218
+ this.accountStatusContext.set(accountStatus);
219
+ this._onDidChangeAccountStatus.fire(accountStatus);
220
+ }
221
+ }
222
+ async turnOn() {
223
+ if (!this.authenticationProviders.length) {
224
+ throw new Error(localizeWithPath('vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService', 'no authentication providers', "Settings sync cannot be turned on because there are no authentication providers available."));
225
+ }
226
+ if (this.userDataSyncEnablementService.isEnabled()) {
227
+ return;
228
+ }
229
+ if (this.userDataSyncService.status !== "idle" ) {
230
+ throw new Error('Cannot turn on sync while syncing');
231
+ }
232
+ const picked = await this.pick();
233
+ if (!picked) {
234
+ throw new CancellationError();
235
+ }
236
+ if (this.accountStatus !== "available" ) {
237
+ throw new Error(localizeWithPath('vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService', 'no account', "No account available"));
238
+ }
239
+ const turnOnSyncCancellationToken = this.turnOnSyncCancellationToken = ( new CancellationTokenSource());
240
+ const disposable = isWeb ? Disposable.None : this.lifecycleService.onBeforeShutdown(e => e.veto((async () => {
241
+ const { confirmed } = await this.dialogService.confirm({
242
+ type: 'warning',
243
+ message: ( localizeWithPath(
244
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
245
+ 'sync in progress',
246
+ "Settings Sync is being turned on. Would you like to cancel it?"
247
+ )),
248
+ title: ( localizeWithPath(
249
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
250
+ 'settings sync',
251
+ "Settings Sync"
252
+ )),
253
+ primaryButton: ( localizeWithPath(
254
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
255
+ { key: 'yes', comment: ['&& denotes a mnemonic'] },
256
+ "&&Yes"
257
+ )),
258
+ cancelButton: ( localizeWithPath(
259
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
260
+ 'no',
261
+ "No"
262
+ ))
263
+ });
264
+ if (confirmed) {
265
+ turnOnSyncCancellationToken.cancel();
266
+ }
267
+ return !confirmed;
268
+ })(), 'veto.settingsSync'));
269
+ try {
270
+ await this.doTurnOnSync(turnOnSyncCancellationToken.token);
271
+ }
272
+ finally {
273
+ disposable.dispose();
274
+ this.turnOnSyncCancellationToken = undefined;
275
+ }
276
+ await this.userDataAutoSyncService.turnOn();
277
+ if (this.userDataSyncStoreManagementService.userDataSyncStore?.canSwitch) {
278
+ await this.synchroniseUserDataSyncStoreType();
279
+ }
280
+ this.currentAuthenticationProviderId = this.current?.authenticationProviderId;
281
+ if (this.environmentService.options?.settingsSyncOptions?.enablementHandler && this.currentAuthenticationProviderId) {
282
+ this.environmentService.options.settingsSyncOptions.enablementHandler(true, this.currentAuthenticationProviderId);
283
+ }
284
+ this.notificationService.info(( localizeWithPath(
285
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
286
+ 'sync turned on',
287
+ "{0} is turned on",
288
+ SYNC_TITLE.value
289
+ )));
290
+ }
291
+ async turnoff(everywhere) {
292
+ if (this.userDataSyncEnablementService.isEnabled()) {
293
+ await this.userDataAutoSyncService.turnOff(everywhere);
294
+ if (this.environmentService.options?.settingsSyncOptions?.enablementHandler && this.currentAuthenticationProviderId) {
295
+ this.environmentService.options.settingsSyncOptions.enablementHandler(false, this.currentAuthenticationProviderId);
296
+ }
297
+ }
298
+ if (this.turnOnSyncCancellationToken) {
299
+ this.turnOnSyncCancellationToken.cancel();
300
+ }
301
+ }
302
+ async synchroniseUserDataSyncStoreType() {
303
+ if (!this.userDataSyncAccountService.account) {
304
+ throw new Error('Cannot update because you are signed out from settings sync. Please sign in and try again.');
305
+ }
306
+ if (!isWeb || !this.userDataSyncStoreManagementService.userDataSyncStore) {
307
+ return;
308
+ }
309
+ const userDataSyncStoreUrl = this.userDataSyncStoreManagementService.userDataSyncStore.type === 'insiders' ? this.userDataSyncStoreManagementService.userDataSyncStore.stableUrl : this.userDataSyncStoreManagementService.userDataSyncStore.insidersUrl;
310
+ const userDataSyncStoreClient = this.instantiationService.createInstance(UserDataSyncStoreClient, userDataSyncStoreUrl);
311
+ userDataSyncStoreClient.setAuthToken(this.userDataSyncAccountService.account.token, this.userDataSyncAccountService.account.authenticationProviderId);
312
+ await this.instantiationService.createInstance(UserDataSyncStoreTypeSynchronizer, userDataSyncStoreClient).sync(this.userDataSyncStoreManagementService.userDataSyncStore.type);
313
+ }
314
+ syncNow() {
315
+ return this.userDataAutoSyncService.triggerSync(['Sync Now'], false, true);
316
+ }
317
+ async doTurnOnSync(token) {
318
+ const disposables = ( new DisposableStore());
319
+ const manualSyncTask = await this.userDataSyncService.createManualSyncTask();
320
+ try {
321
+ await this.progressService.withProgress({
322
+ location: 10 ,
323
+ title: SYNC_TITLE.value,
324
+ command: SHOW_SYNC_LOG_COMMAND_ID,
325
+ delay: 500,
326
+ }, async (progress) => {
327
+ progress.report({ message: ( localizeWithPath(
328
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
329
+ 'turning on',
330
+ "Turning on..."
331
+ )) });
332
+ disposables.add(this.userDataSyncService.onDidChangeStatus(status => {
333
+ if (status === "hasConflicts" ) {
334
+ progress.report({ message: ( localizeWithPath(
335
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
336
+ 'resolving conflicts',
337
+ "Resolving conflicts..."
338
+ )) });
339
+ }
340
+ else {
341
+ progress.report({ message: ( localizeWithPath(
342
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
343
+ 'syncing...',
344
+ "Turning on..."
345
+ )) });
346
+ }
347
+ }));
348
+ await manualSyncTask.merge();
349
+ if (this.userDataSyncService.status === "hasConflicts" ) {
350
+ await this.handleConflictsWhileTurningOn(token);
351
+ }
352
+ await manualSyncTask.apply();
353
+ });
354
+ }
355
+ catch (error) {
356
+ await manualSyncTask.stop();
357
+ throw error;
358
+ }
359
+ finally {
360
+ disposables.dispose();
361
+ }
362
+ }
363
+ async handleConflictsWhileTurningOn(token) {
364
+ await this.dialogService.prompt({
365
+ type: Severity.Warning,
366
+ message: ( localizeWithPath(
367
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
368
+ 'conflicts detected',
369
+ "Conflicts Detected"
370
+ )),
371
+ detail: ( localizeWithPath(
372
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
373
+ 'resolve',
374
+ "Please resolve conflicts to turn on..."
375
+ )),
376
+ buttons: [
377
+ {
378
+ label: ( localizeWithPath(
379
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
380
+ { key: 'show conflicts', comment: ['&& denotes a mnemonic'] },
381
+ "&&Show Conflicts"
382
+ )),
383
+ run: async () => {
384
+ const waitUntilConflictsAreResolvedPromise = raceCancellationError(Event.toPromise(Event.filter(this.userDataSyncService.onDidChangeConflicts, conficts => conficts.length === 0)), token);
385
+ await this.showConflicts(this.userDataSyncService.conflicts[0]?.conflicts[0]);
386
+ await waitUntilConflictsAreResolvedPromise;
387
+ }
388
+ },
389
+ {
390
+ label: ( localizeWithPath(
391
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
392
+ { key: 'replace local', comment: ['&& denotes a mnemonic'] },
393
+ "Replace &&Local"
394
+ )),
395
+ run: async () => this.replace(true)
396
+ },
397
+ {
398
+ label: ( localizeWithPath(
399
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
400
+ { key: 'replace remote', comment: ['&& denotes a mnemonic'] },
401
+ "Replace &&Remote"
402
+ )),
403
+ run: () => this.replace(false)
404
+ },
405
+ ],
406
+ cancelButton: {
407
+ run: () => {
408
+ throw new CancellationError();
409
+ }
410
+ }
411
+ });
412
+ }
413
+ async replace(local) {
414
+ for (const conflict of this.userDataSyncService.conflicts) {
415
+ for (const preview of conflict.conflicts) {
416
+ await this.accept({ syncResource: conflict.syncResource, profile: conflict.profile }, local ? preview.remoteResource : preview.localResource, undefined, { force: true });
417
+ }
418
+ }
419
+ }
420
+ async accept(resource, conflictResource, content, apply) {
421
+ return this.userDataSyncService.accept(resource, conflictResource, content, apply);
422
+ }
423
+ async showConflicts(conflictToOpen) {
424
+ if (!this.userDataSyncService.conflicts.length) {
425
+ return;
426
+ }
427
+ this.enableConflictsViewContext.set(true);
428
+ const view = await this.viewsService.openView(SYNC_CONFLICTS_VIEW_ID);
429
+ if (view && conflictToOpen) {
430
+ await view.open(conflictToOpen);
431
+ }
432
+ }
433
+ async resetSyncedData() {
434
+ const { confirmed } = await this.dialogService.confirm({
435
+ type: 'info',
436
+ message: ( localizeWithPath(
437
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
438
+ 'reset',
439
+ "This will clear your data in the cloud and stop sync on all your devices."
440
+ )),
441
+ title: ( localizeWithPath(
442
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
443
+ 'reset title',
444
+ "Clear"
445
+ )),
446
+ primaryButton: ( localizeWithPath(
447
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
448
+ { key: 'resetButton', comment: ['&& denotes a mnemonic'] },
449
+ "&&Reset"
450
+ )),
451
+ });
452
+ if (confirmed) {
453
+ await this.userDataSyncService.resetRemote();
454
+ }
455
+ }
456
+ async getAllLogResources() {
457
+ const logsFolders = [];
458
+ const stat = await this.fileService.resolve(this.uriIdentityService.extUri.dirname(this.environmentService.logsHome));
459
+ if (stat.children) {
460
+ logsFolders.push(...( stat.children
461
+ .filter(stat => stat.isDirectory && /^\d{8}T\d{6}$/.test(stat.name))
462
+ .sort()
463
+ .reverse()
464
+ .map(d => d.resource)));
465
+ }
466
+ const result = [];
467
+ for (const logFolder of logsFolders) {
468
+ const folderStat = await this.fileService.resolve(logFolder);
469
+ const childStat = folderStat.children?.find(stat => this.uriIdentityService.extUri.basename(stat.resource).startsWith(`${USER_DATA_SYNC_LOG_ID}.`));
470
+ if (childStat) {
471
+ result.push(childStat.resource);
472
+ }
473
+ }
474
+ return result;
475
+ }
476
+ async showSyncActivity() {
477
+ this.activityViewsEnablementContext.set(true);
478
+ await this.waitForActiveSyncViews();
479
+ await this.viewsService.openViewContainer(SYNC_VIEW_CONTAINER_ID);
480
+ }
481
+ async downloadSyncActivity() {
482
+ const result = await this.fileDialogService.showOpenDialog({
483
+ title: ( localizeWithPath(
484
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
485
+ 'download sync activity dialog title',
486
+ "Select folder to download Settings Sync activity"
487
+ )),
488
+ canSelectFiles: false,
489
+ canSelectFolders: true,
490
+ canSelectMany: false,
491
+ openLabel: ( localizeWithPath(
492
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
493
+ 'download sync activity dialog open label',
494
+ "Save"
495
+ )),
496
+ });
497
+ if (!result?.[0]) {
498
+ return;
499
+ }
500
+ return this.progressService.withProgress({ location: 10 }, async () => {
501
+ const machines = await this.userDataSyncMachinesService.getMachines();
502
+ const currentMachine = machines.find(m => m.isCurrent);
503
+ const name = (currentMachine ? currentMachine.name + ' - ' : '') + 'Settings Sync Activity';
504
+ const stat = await this.fileService.resolve(result[0]);
505
+ const nameRegEx = ( new RegExp(`${escapeRegExpCharacters(name)}\\s(\\d+)`));
506
+ const indexes = [];
507
+ for (const child of stat.children ?? []) {
508
+ if (child.name === name) {
509
+ indexes.push(0);
510
+ }
511
+ else {
512
+ const matches = nameRegEx.exec(child.name);
513
+ if (matches) {
514
+ indexes.push(parseInt(matches[1]));
515
+ }
516
+ }
517
+ }
518
+ indexes.sort((a, b) => a - b);
519
+ const folder = this.uriIdentityService.extUri.joinPath(result[0], indexes[0] !== 0 ? name : `${name} ${indexes[indexes.length - 1] + 1}`);
520
+ await Promise.all([
521
+ this.userDataSyncService.saveRemoteActivityData(this.uriIdentityService.extUri.joinPath(folder, 'remoteActivity.json')),
522
+ (async () => {
523
+ const logResources = await this.getAllLogResources();
524
+ await Promise.all(( logResources.map(
525
+ async (logResource) => this.fileService.copy(logResource, this.uriIdentityService.extUri.joinPath(folder, 'logs', `${this.uriIdentityService.extUri.basename(this.uriIdentityService.extUri.dirname(logResource))}.log`))
526
+ )));
527
+ })(),
528
+ this.fileService.copy(this.environmentService.userDataSyncHome, this.uriIdentityService.extUri.joinPath(folder, 'localActivity')),
529
+ ]);
530
+ return folder;
531
+ });
532
+ }
533
+ async waitForActiveSyncViews() {
534
+ const viewContainer = this.viewDescriptorService.getViewContainerById(SYNC_VIEW_CONTAINER_ID);
535
+ if (viewContainer) {
536
+ const model = this.viewDescriptorService.getViewContainerModel(viewContainer);
537
+ if (!model.activeViewDescriptors.length) {
538
+ await Event.toPromise(Event.filter(model.onDidChangeActiveViewDescriptors, e => model.activeViewDescriptors.length > 0));
539
+ }
540
+ }
541
+ }
542
+ async signIn() {
543
+ const currentAuthenticationProviderId = this.currentAuthenticationProviderId;
544
+ const authenticationProvider = currentAuthenticationProviderId ? this.authenticationProviders.find(p => p.id === currentAuthenticationProviderId) : undefined;
545
+ if (authenticationProvider) {
546
+ await this.doSignIn(authenticationProvider);
547
+ }
548
+ else {
549
+ await this.pick();
550
+ }
551
+ }
552
+ async pick() {
553
+ const result = await this.doPick();
554
+ if (!result) {
555
+ return false;
556
+ }
557
+ await this.doSignIn(result);
558
+ return true;
559
+ }
560
+ async doPick() {
561
+ if (this.authenticationProviders.length === 0) {
562
+ return undefined;
563
+ }
564
+ const authenticationProviders = [...this.authenticationProviders].sort(({ id }) => id === this.currentAuthenticationProviderId ? -1 : 1);
565
+ const allAccounts = ( new Map());
566
+ if (authenticationProviders.length === 1) {
567
+ const accounts = await this.getAccounts(authenticationProviders[0].id, authenticationProviders[0].scopes);
568
+ if (accounts.length) {
569
+ allAccounts.set(authenticationProviders[0].id, accounts);
570
+ }
571
+ else {
572
+ return authenticationProviders[0];
573
+ }
574
+ }
575
+ let result;
576
+ const disposables = ( new DisposableStore());
577
+ const quickPick = disposables.add(this.quickInputService.createQuickPick());
578
+ const promise = ( new Promise(c => {
579
+ disposables.add(quickPick.onDidHide(() => {
580
+ disposables.dispose();
581
+ c(result);
582
+ }));
583
+ }));
584
+ quickPick.title = SYNC_TITLE.value;
585
+ quickPick.ok = false;
586
+ quickPick.ignoreFocusOut = true;
587
+ quickPick.placeholder = ( localizeWithPath(
588
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
589
+ 'choose account placeholder',
590
+ "Select an account to sign in"
591
+ ));
592
+ quickPick.show();
593
+ if (authenticationProviders.length > 1) {
594
+ quickPick.busy = true;
595
+ for (const { id, scopes } of authenticationProviders) {
596
+ const accounts = await this.getAccounts(id, scopes);
597
+ if (accounts.length) {
598
+ allAccounts.set(id, accounts);
599
+ }
600
+ }
601
+ quickPick.busy = false;
602
+ }
603
+ quickPick.items = this.createQuickpickItems(authenticationProviders, allAccounts);
604
+ disposables.add(quickPick.onDidAccept(() => {
605
+ result = quickPick.selectedItems[0]?.account ? quickPick.selectedItems[0]?.account : quickPick.selectedItems[0]?.authenticationProvider;
606
+ quickPick.hide();
607
+ }));
608
+ return promise;
609
+ }
610
+ async getAccounts(authenticationProviderId, scopes) {
611
+ const accounts = ( new Map());
612
+ let currentAccount = null;
613
+ const sessions = (await this.authenticationService.getSessions(authenticationProviderId, scopes)) || [];
614
+ for (const session of sessions) {
615
+ const account = ( new UserDataSyncAccount(authenticationProviderId, session));
616
+ accounts.set(account.accountId, account);
617
+ if (account.sessionId === this.currentSessionId) {
618
+ currentAccount = account;
619
+ }
620
+ }
621
+ if (currentAccount) {
622
+ accounts.set(currentAccount.accountId, currentAccount);
623
+ }
624
+ return currentAccount ? [...( accounts.values())] : [...( accounts.values())].sort(({ sessionId }) => sessionId === this.currentSessionId ? -1 : 1);
625
+ }
626
+ createQuickpickItems(authenticationProviders, allAccounts) {
627
+ const quickPickItems = [];
628
+ if (allAccounts.size) {
629
+ quickPickItems.push({ type: 'separator', label: ( localizeWithPath(
630
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
631
+ 'signed in',
632
+ "Signed in"
633
+ )) });
634
+ for (const authenticationProvider of authenticationProviders) {
635
+ const accounts = (allAccounts.get(authenticationProvider.id) || []).sort(({ sessionId }) => sessionId === this.currentSessionId ? -1 : 1);
636
+ const providerName = this.authenticationService.getLabel(authenticationProvider.id);
637
+ for (const account of accounts) {
638
+ quickPickItems.push({
639
+ label: `${account.accountName} (${providerName})`,
640
+ description: account.sessionId === this.current?.sessionId ? ( localizeWithPath(
641
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
642
+ 'last used',
643
+ "Last Used with Sync"
644
+ )) : undefined,
645
+ account,
646
+ authenticationProvider,
647
+ });
648
+ }
649
+ }
650
+ quickPickItems.push({ type: 'separator', label: ( localizeWithPath(
651
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
652
+ 'others',
653
+ "Others"
654
+ )) });
655
+ }
656
+ for (const authenticationProvider of authenticationProviders) {
657
+ if (!( allAccounts.has(authenticationProvider.id)) || this.authenticationService.supportsMultipleAccounts(authenticationProvider.id)) {
658
+ const providerName = this.authenticationService.getLabel(authenticationProvider.id);
659
+ quickPickItems.push({ label: ( localizeWithPath(
660
+ 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService',
661
+ 'sign in using account',
662
+ "Sign in with {0}",
663
+ providerName
664
+ )), authenticationProvider });
665
+ }
666
+ }
667
+ return quickPickItems;
668
+ }
669
+ async doSignIn(accountOrAuthProvider) {
670
+ let sessionId;
671
+ if (isAuthenticationProvider(accountOrAuthProvider)) {
672
+ if (this.environmentService.options?.settingsSyncOptions?.authenticationProvider?.id === accountOrAuthProvider.id) {
673
+ sessionId = await this.environmentService.options?.settingsSyncOptions?.authenticationProvider?.signIn();
674
+ }
675
+ else {
676
+ sessionId = (await this.authenticationService.createSession(accountOrAuthProvider.id, accountOrAuthProvider.scopes)).id;
677
+ }
678
+ this.currentAuthenticationProviderId = accountOrAuthProvider.id;
679
+ }
680
+ else {
681
+ if (this.environmentService.options?.settingsSyncOptions?.authenticationProvider?.id === accountOrAuthProvider.authenticationProviderId) {
682
+ sessionId = await this.environmentService.options?.settingsSyncOptions?.authenticationProvider?.signIn();
683
+ }
684
+ else {
685
+ sessionId = accountOrAuthProvider.sessionId;
686
+ }
687
+ this.currentAuthenticationProviderId = accountOrAuthProvider.authenticationProviderId;
688
+ }
689
+ this.currentSessionId = sessionId;
690
+ await this.update();
691
+ }
692
+ async onDidAuthFailure() {
693
+ this.telemetryService.publicLog2('sync/successiveAuthFailures');
694
+ this.currentSessionId = undefined;
695
+ await this.update('auth failure');
696
+ }
697
+ onDidChangeSessions(e) {
698
+ if (this.currentSessionId && e.removed.find(session => session.id === this.currentSessionId)) {
699
+ this.currentSessionId = undefined;
700
+ }
701
+ this.update('change in sessions');
702
+ }
703
+ onDidChangeStorage() {
704
+ if (this.currentSessionId !== this.getStoredCachedSessionId() ) {
705
+ this._cachedCurrentSessionId = null;
706
+ this.update('change in storage');
707
+ }
708
+ }
709
+ get currentAuthenticationProviderId() {
710
+ if (this._cachedCurrentAuthenticationProviderId === null) {
711
+ this._cachedCurrentAuthenticationProviderId = this.storageService.get(UserDataSyncWorkbenchService_1.CACHED_AUTHENTICATION_PROVIDER_KEY, -1 );
712
+ }
713
+ return this._cachedCurrentAuthenticationProviderId;
714
+ }
715
+ set currentAuthenticationProviderId(currentAuthenticationProviderId) {
716
+ if (this._cachedCurrentAuthenticationProviderId !== currentAuthenticationProviderId) {
717
+ this._cachedCurrentAuthenticationProviderId = currentAuthenticationProviderId;
718
+ if (currentAuthenticationProviderId === undefined) {
719
+ this.storageService.remove(UserDataSyncWorkbenchService_1.CACHED_AUTHENTICATION_PROVIDER_KEY, -1 );
720
+ }
721
+ else {
722
+ this.storageService.store(UserDataSyncWorkbenchService_1.CACHED_AUTHENTICATION_PROVIDER_KEY, currentAuthenticationProviderId, -1 , 1 );
723
+ }
724
+ }
725
+ }
726
+ get currentSessionId() {
727
+ if (this._cachedCurrentSessionId === null) {
728
+ this._cachedCurrentSessionId = this.getStoredCachedSessionId();
729
+ }
730
+ return this._cachedCurrentSessionId;
731
+ }
732
+ set currentSessionId(cachedSessionId) {
733
+ if (this._cachedCurrentSessionId !== cachedSessionId) {
734
+ this._cachedCurrentSessionId = cachedSessionId;
735
+ if (cachedSessionId === undefined) {
736
+ this.logService.info('Settings Sync: Reset current session');
737
+ this.storageService.remove(UserDataSyncWorkbenchService_1.CACHED_SESSION_STORAGE_KEY, -1 );
738
+ }
739
+ else {
740
+ this.logService.info('Settings Sync: Updated current session', cachedSessionId);
741
+ this.storageService.store(UserDataSyncWorkbenchService_1.CACHED_SESSION_STORAGE_KEY, cachedSessionId, -1 , 1 );
742
+ }
743
+ }
744
+ }
745
+ getStoredCachedSessionId() {
746
+ return this.storageService.get(UserDataSyncWorkbenchService_1.CACHED_SESSION_STORAGE_KEY, -1 );
747
+ }
748
+ get useWorkbenchSessionId() {
749
+ return !this.storageService.getBoolean(UserDataSyncWorkbenchService_1.DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY, -1 , false);
750
+ }
751
+ set useWorkbenchSessionId(useWorkbenchSession) {
752
+ this.storageService.store(UserDataSyncWorkbenchService_1.DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY, !useWorkbenchSession, -1 , 1 );
753
+ }
754
+ };
755
+ UserDataSyncWorkbenchService = UserDataSyncWorkbenchService_1 = ( __decorate([
756
+ ( __param(0, IUserDataSyncService)),
757
+ ( __param(1, IUriIdentityService)),
758
+ ( __param(2, IAuthenticationService)),
759
+ ( __param(3, IUserDataSyncAccountService)),
760
+ ( __param(4, IQuickInputService)),
761
+ ( __param(5, IStorageService)),
762
+ ( __param(6, IUserDataSyncEnablementService)),
763
+ ( __param(7, IUserDataAutoSyncService)),
764
+ ( __param(8, ITelemetryService)),
765
+ ( __param(9, ILogService)),
766
+ ( __param(10, IProductService)),
767
+ ( __param(11, IExtensionService)),
768
+ ( __param(12, IBrowserWorkbenchEnvironmentService)),
769
+ ( __param(13, ISecretStorageService)),
770
+ ( __param(14, INotificationService)),
771
+ ( __param(15, IProgressService)),
772
+ ( __param(16, IDialogService)),
773
+ ( __param(17, IContextKeyService)),
774
+ ( __param(18, IViewsService)),
775
+ ( __param(19, IViewDescriptorService)),
776
+ ( __param(20, IUserDataSyncStoreManagementService)),
777
+ ( __param(21, ILifecycleService)),
778
+ ( __param(22, IInstantiationService)),
779
+ ( __param(23, IEditorService)),
780
+ ( __param(24, IUserDataInitializationService)),
781
+ ( __param(25, IFileService)),
782
+ ( __param(26, IFileDialogService)),
783
+ ( __param(27, IUserDataSyncMachinesService))
784
+ ], UserDataSyncWorkbenchService));
785
+
786
+ export { UserDataSyncWorkbenchService, isMergeEditorInput };