UNPKG

@theia/workspace

Version:
124 lines 6.57 kB
import { StorageService } from '@theia/core/lib/browser'; import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string'; import { StatusBar } from '@theia/core/lib/browser/status-bar/status-bar'; import { ContributionProvider, DisposableCollection } from '@theia/core'; import { Emitter, Event } from '@theia/core/lib/common'; import URI from '@theia/core/lib/common/uri'; import { PreferenceChange, PreferenceSchemaService, PreferenceService } from '@theia/core/lib/common/preferences'; import { MessageService } from '@theia/core/lib/common/message-service'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { WorkspaceTrustPreferences } from '../common/workspace-trust-preferences'; import { WorkspaceService } from './workspace-service'; import { ContextKeyService } from '@theia/core/lib/browser/context-key-service'; import { UntitledWorkspaceService } from '../common/untitled-workspace-service'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; export declare const WORKSPACE_TRUST_STATUS_BAR_ID = "workspace-trust-status"; /** * Contribution interface for features that are restricted in untrusted workspaces. * Implementations can provide information about what is being restricted. */ export declare const WorkspaceRestrictionContribution: unique symbol; export interface WorkspaceRestrictionContribution { /** * Returns the restrictions currently active due to workspace trust. * Called when building the restricted mode status bar tooltip. */ getRestrictions(): WorkspaceRestriction[]; /** * Returns whether a window reload is required when workspace trust changes to `newTrust`. * Called before reloading on trust change to avoid unnecessary reloads when no * trust-restricted items are actually affected. * If not implemented, the contribution is assumed not to require a reload. */ requiresReloadOnTrustChange?(newTrust: boolean): boolean; } export interface WorkspaceRestriction { /** Display name of the feature being restricted */ label: string; /** Optional details (e.g., list of blocked items) */ details?: string[]; } export declare class WorkspaceTrustService { protected readonly workspaceService: WorkspaceService; protected readonly preferences: PreferenceService; protected readonly storage: StorageService; protected readonly messageService: MessageService; protected readonly workspaceTrustPref: WorkspaceTrustPreferences; protected readonly preferenceSchemaService: PreferenceSchemaService; protected readonly windowService: WindowService; protected readonly contextKeyService: ContextKeyService; protected readonly statusBar: StatusBar; protected readonly restrictionContributions: ContributionProvider<WorkspaceRestrictionContribution>; protected readonly untitledWorkspaceService: UntitledWorkspaceService; protected readonly envVariablesServer: EnvVariablesServer; protected workspaceTrust: Deferred<boolean>; protected currentTrust: boolean | undefined; protected pendingTrustDialog: Deferred<boolean> | undefined; protected pendingTrustRequest: Deferred<boolean | undefined> | undefined; protected readonly onDidChangeWorkspaceTrustEmitter: Emitter<boolean>; readonly onDidChangeWorkspaceTrust: Event<boolean>; protected readonly toDispose: DisposableCollection; protected init(): void; protected doInit(): Promise<void>; protected onStop(): void; getWorkspaceTrust(): Promise<boolean>; protected resolveWorkspaceTrust(givenTrust?: boolean): Promise<void>; setWorkspaceTrust(trusted: boolean, reload?: boolean): Promise<void>; protected shouldReloadForTrustChange(newTrust: boolean): boolean; protected isWorkspaceTrustResolved(): boolean; protected calculateWorkspaceTrust(): Promise<boolean | undefined>; /** * Check if the workspace is empty (no workspace or folder opened, or * an untitled workspace with no folders). * A saved workspace file with 0 folders is NOT empty - it still needs trust * evaluation because it could have tasks defined. */ protected isEmptyWorkspace(): Promise<boolean>; /** * Get the URIs that need to be trusted for the current workspace. * This includes all workspace folder URIs, plus the workspace file URI * for saved workspaces (since workspace files can contain tasks/settings). */ protected getWorkspaceUris(): URI[]; /** * Check if all workspace URIs are trusted. * A workspace is trusted only if ALL of its folders (and the workspace * file for saved workspaces) are trusted. */ protected areAllWorkspaceUrisTrusted(): Promise<boolean>; /** * Check if a URI is trusted. A URI is trusted if it or any of its * parent folders is in the trusted folders list. */ protected isUriTrusted(uri: URI): boolean; protected showTrustPromptDialog(): Promise<boolean>; addToTrustedFolders(): Promise<void>; removeFromTrustedFolders(): Promise<void>; protected loadWorkspaceTrust(): Promise<boolean | undefined>; protected storeWorkspaceTrust(trust: boolean): Promise<void>; protected handlePreferenceChange(change: PreferenceChange): Promise<void>; protected handleWorkspaceChanged(): Promise<void>; protected confirmRestart(): Promise<boolean>; protected updateRestrictedModeIndicator(trusted: boolean): void; protected showRestrictedModeStatusBarItem(): void; protected createRestrictedModeTooltip(): MarkdownString; protected collectRestrictions(): WorkspaceRestriction[]; protected hideRestrictedModeStatusBarItem(): void; /** * Refreshes the restricted mode status bar item. * Call this when restriction contributions change. */ refreshRestrictedModeIndicator(): void; /** * Request workspace trust from the user. This method follows VS Code's pattern: * - If already trusted, returns true immediately * - If there's already a pending trust request, returns the same promise (avoiding duplicate dialogs) * - Otherwise, shows a dialog and waits for the user's response * * Unlike the initial trust resolution, this can be called multiple times and will * prompt the user each time (unless a dialog is already open). */ requestWorkspaceTrust(): Promise<boolean | undefined>; } //# sourceMappingURL=workspace-trust-service.d.ts.map