UNPKG

@theia/core

Version:

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

80 lines 3.27 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2025 STMicroelectronics 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 // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingServiceImpl = exports.SettingService = void 0; const tslib_1 = require("tslib"); const inversify_1 = require("inversify"); const env_variables_1 = require("../common/env-variables"); const promise_util_1 = require("../common/promise-util"); const fs_1 = require("fs"); const common_1 = require("../common"); exports.SettingService = Symbol('SettingService'); let SettingServiceImpl = class SettingServiceImpl { constructor() { this.ready = new promise_util_1.Deferred(); this.values = {}; } init() { const asyncInit = async () => { const configDir = new common_1.URI(await this.envVarServer.getConfigDirUri()); const path = configDir.resolve('backend-settings.json').path.fsPath(); try { const contents = await fs_1.promises.readFile(path, { encoding: 'utf-8' }); this.values = JSON.parse(contents); } catch (e) { console.log(e); } finally { this.ready.resolve(); } }; asyncInit(); } async set(key, value) { await this.ready.promise; this.values[key] = value; await this.writeFile(); } async writeFile() { const configDir = new common_1.URI(await this.envVarServer.getConfigDirUri()); const path = configDir.resolve('backend-settings.json').path.fsPath(); const values = JSON.stringify(this.values); await fs_1.promises.writeFile(path, values); } async get(key) { await this.ready.promise; return this.values[key]; } }; exports.SettingServiceImpl = SettingServiceImpl; tslib_1.__decorate([ (0, inversify_1.inject)(env_variables_1.EnvVariablesServer), tslib_1.__metadata("design:type", Object) ], SettingServiceImpl.prototype, "envVarServer", void 0); tslib_1.__decorate([ (0, inversify_1.postConstruct)(), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", []), tslib_1.__metadata("design:returntype", void 0) ], SettingServiceImpl.prototype, "init", null); exports.SettingServiceImpl = SettingServiceImpl = tslib_1.__decorate([ (0, inversify_1.injectable)() ], SettingServiceImpl); //# sourceMappingURL=setting-service.js.map