Path: blob/main/src/vs/workbench/contrib/editSessions/common/editSessions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { decodeBase64, VSBuffer } from '../../../../base/common/buffer.js';6import { Codicon } from '../../../../base/common/codicons.js';7import { localize, localize2 } from '../../../../nls.js';8import { ILocalizedString } from '../../../../platform/action/common/action.js';9import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';10import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';11import { ILogService } from '../../../../platform/log/common/log.js';12import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';13import { IResourceRefHandle } from '../../../../platform/userDataSync/common/userDataSync.js';14import { Event } from '../../../../base/common/event.js';15import { StringSHA1 } from '../../../../base/common/hash.js';16import { EditSessionsStoreClient } from './editSessionsStorageClient.js';1718export const EDIT_SESSION_SYNC_CATEGORY = localize2('cloud changes', 'Cloud Changes');1920export type SyncResource = 'editSessions' | 'workspaceState';2122export const IEditSessionsStorageService = createDecorator<IEditSessionsStorageService>('IEditSessionsStorageService');23export interface IEditSessionsStorageService {24_serviceBrand: undefined;2526readonly SIZE_LIMIT: number;2728readonly isSignedIn: boolean;29readonly onDidSignIn: Event<void>;30readonly onDidSignOut: Event<void>;3132storeClient: EditSessionsStoreClient | undefined;3334lastReadResources: Map<SyncResource, { ref: string; content: string }>;35lastWrittenResources: Map<SyncResource, { ref: string; content: string }>;3637initialize(reason: 'read' | 'write', silent?: boolean): Promise<boolean>;38read(resource: SyncResource, ref: string | undefined): Promise<{ ref: string; content: string } | undefined>;39write(resource: SyncResource, content: string | EditSession): Promise<string>;40delete(resource: SyncResource, ref: string | null): Promise<void>;41list(resource: SyncResource): Promise<IResourceRefHandle[]>;42getMachineById(machineId: string): Promise<string | undefined>;43}4445export const IEditSessionsLogService = createDecorator<IEditSessionsLogService>('IEditSessionsLogService');46export interface IEditSessionsLogService extends ILogService { }4748export enum ChangeType {49Addition = 1,50Deletion = 2,51}5253export enum FileType {54File = 1,55}5657interface Addition {58relativeFilePath: string;59fileType: FileType.File;60contents: string;61type: ChangeType.Addition;62}6364interface Deletion {65relativeFilePath: string;66fileType: FileType.File;67contents: undefined;68type: ChangeType.Deletion;69}7071export type Change = Addition | Deletion;7273export interface Folder {74name: string;75canonicalIdentity: string | undefined;76workingChanges: Change[];77absoluteUri: string | undefined;78}7980export const EditSessionSchemaVersion = 3;8182export interface EditSession {83version: number;84workspaceStateId?: string;85machine?: string;86folders: Folder[];87}8889export const EDIT_SESSIONS_SIGNED_IN_KEY = 'editSessionsSignedIn';90export const EDIT_SESSIONS_SIGNED_IN = new RawContextKey<boolean>(EDIT_SESSIONS_SIGNED_IN_KEY, false);9192export const EDIT_SESSIONS_PENDING_KEY = 'editSessionsPending';93export const EDIT_SESSIONS_PENDING = new RawContextKey<boolean>(EDIT_SESSIONS_PENDING_KEY, false);9495export const EDIT_SESSIONS_CONTAINER_ID = 'workbench.view.editSessions';96export const EDIT_SESSIONS_DATA_VIEW_ID = 'workbench.views.editSessions.data';97export const EDIT_SESSIONS_TITLE: ILocalizedString = localize2('cloud changes', 'Cloud Changes');9899export const EDIT_SESSIONS_VIEW_ICON = registerIcon('edit-sessions-view-icon', Codicon.cloudDownload, localize('editSessionViewIcon', 'View icon of the cloud changes view.'));100101export const EDIT_SESSIONS_SHOW_VIEW = new RawContextKey<boolean>('editSessionsShowView', false);102103export const EDIT_SESSIONS_SCHEME = 'vscode-edit-sessions';104105export function decodeEditSessionFileContent(version: number, content: string): VSBuffer {106switch (version) {107case 1:108return VSBuffer.fromString(content);109case 2:110return decodeBase64(content);111default:112throw new Error('Upgrade to a newer version to decode this content.');113}114}115116export function hashedEditSessionId(editSessionId: string) {117const sha1 = new StringSHA1();118sha1.update(editSessionId);119return sha1.digest();120}121122export const editSessionsLogId = 'editSessions';123124125