Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "accept local" and "accept remote" buttons to setting conflict notification #90190

Merged
merged 3 commits into from
Feb 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add "accept local" and "accept remote" buttons to setting conflict no…
…tification
  • Loading branch information
roblourens committed Feb 11, 2020
commit 55e5c3cf73a3b0a36100054cd2ce687c8d2f0a2c
27 changes: 26 additions & 1 deletion src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IUserDataSyncService, SyncStatus, SyncSource, CONTEXT_SYNC_STATE, IUserDataSyncStore, registerConfiguration, getUserDataSyncStore, ISyncConfiguration, IUserDataAuthTokenService, IUserDataAutoSyncService, USER_DATA_SYNC_SCHEME, toRemoteContentResource, getSyncSourceFromRemoteContentResource, UserDataSyncErrorCode, UserDataSyncError, getSyncSourceFromPreviewResource, IUserDataSyncEnablementService, ResourceKey } from 'vs/platform/userDataSync/common/userDataSync';
import { IUserDataSyncService, SyncStatus, SyncSource, CONTEXT_SYNC_STATE, IUserDataSyncStore, registerConfiguration, getUserDataSyncStore, ISyncConfiguration, IUserDataAuthTokenService, IUserDataAutoSyncService, USER_DATA_SYNC_SCHEME, toRemoteContentResource, getSyncSourceFromRemoteContentResource, UserDataSyncErrorCode, UserDataSyncError, getSyncSourceFromPreviewResource, IUserDataSyncEnablementService, ResourceKey, ISettingsSyncService } from 'vs/platform/userDataSync/common/userDataSync';
import { localize } from 'vs/nls';
import { Disposable, MutableDisposable, toDisposable, DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
@@ -44,6 +44,7 @@ import type { IEditorInput } from 'vs/workbench/common/editor';
import { Action } from 'vs/base/common/actions';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IFileService } from 'vs/platform/files/common/files';

const enum AuthStatus {
Initializing = 'Initializing',
@@ -85,6 +86,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
constructor(
@IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService,
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
@ISettingsSyncService private readonly settingsSyncService: ISettingsSyncService,
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
@IContextKeyService contextKeyService: IContextKeyService,
@IActivityService private readonly activityService: IActivityService,
@@ -101,6 +103,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
@ITextModelService textModelResolverService: ITextModelService,
@IPreferencesService private readonly preferencesService: IPreferencesService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IFileService private readonly fileService: IFileService,
) {
super();
this.userDataSyncStore = getUserDataSyncStore(configurationService);
@@ -256,6 +259,14 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
const conflictsArea = getSyncAreaLabel(conflictsSource);
const handle = this.notificationService.prompt(Severity.Warning, localize('conflicts detected', "Unable to sync due to conflicts in {0}. Please resolve them to continue.", conflictsArea),
[
{
label: localize('accept remote', "Accept Remote"),
run: () => this.acceptSettingConflicts('remote')
},
{
label: localize('accept local', "Accept Local"),
run: () => this.acceptSettingConflicts('local')
},
{
label: localize('show conflicts', "Show Conflicts"),
run: () => {
@@ -543,6 +554,20 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
});
}

private async acceptSettingConflicts(resolutionSource: 'local' | 'remote'): Promise<void> {
let contents: string | undefined;
if (resolutionSource === 'local') {
const fileContent = await this.fileService.readFile(this.workbenchEnvironmentService.settingsResource);
contents = fileContent.value.toString();
} else {
contents = await this.settingsSyncService.getRemoteContent() || undefined;
}

if (contents) {
this.userDataSyncService.accept(SyncSource.Settings, contents);
}
}

private async handleConflicts(source: SyncSource): Promise<void> {
let previewResource: URI | undefined = undefined;
let label: string = '';