UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

71 lines (64 loc) • 2.85 kB
// ***************************************************************************** // Copyright (C) 2026 EclipseSource and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** import { JSONObject, JSONValue } from '@lumino/coreutils'; import { injectable, postConstruct } from 'inversify'; import { PreferenceProvider, PreferenceProviderDataChange } from './preference-provider.js'; import { PreferenceProviderImpl } from './preference-provider-impl.js'; import { PreferenceScope } from './preference-scope.js'; /** * In-memory preference provider used for process-lifetime overrides such as those * supplied via the `--session-preference` CLI option. Values live in memory only * and are dropped when the process exits. */ @injectable() export class SessionPreferenceProvider extends PreferenceProviderImpl implements PreferenceProvider { protected readonly preferences = new Map<string, JSONValue>(); @postConstruct() protected init(): void { this._ready.resolve(); } override canHandleScope(scope: PreferenceScope): boolean { return scope === PreferenceScope.Session; } getPreferences(): JSONObject { const result: JSONObject = {}; for (const [name, value] of this.preferences) { result[name] = value; } return result; } override async setPreference(key: string, value: JSONValue | undefined, _resourceUri?: string, overrideIdentifier?: string): Promise<boolean> { const storageKey = overrideIdentifier ? `[${overrideIdentifier}].${key}` : key; const oldValue = this.preferences.get(storageKey); if (value === undefined) { if (!this.preferences.has(storageKey)) { return false; } this.preferences.delete(storageKey); } else { this.preferences.set(storageKey, value); } const change: PreferenceProviderDataChange = { preferenceName: key, newValue: value, oldValue, scope: PreferenceScope.Session, overrideIdentifier }; await this.emitPreferencesChangedEvent([change]); return true; } }