"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadStorage = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_connection_1 = require("@opensumi/ide-connection");
const ide_extension_storage_1 = require("@opensumi/ide-extension-storage");
const vscode_1 = require("../../../common/vscode");
let MainThreadStorage = class MainThreadStorage {
    constructor(rpcProtocol) {
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostStorage);
        this.init();
    }
    dispose() { }
    async init() {
        await this.extensionStorageService.whenReady;
        this.proxy.$acceptStoragePath(this.extensionStorageService.extensionStoragePath);
    }
    $setValue(shared, key, value) {
        try {
            this.extensionStorageService.set(key, value, shared);
        }
        catch (err) {
            return Promise.reject(err);
        }
        return Promise.resolve(undefined);
    }
    $getValue(shared, key) {
        try {
            return Promise.resolve(this.extensionStorageService.get(key, shared));
        }
        catch (error) {
            return Promise.reject(error);
        }
    }
};
exports.MainThreadStorage = MainThreadStorage;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_extension_storage_1.IExtensionStorageService),
    tslib_1.__metadata("design:type", Object)
], MainThreadStorage.prototype, "extensionStorageService", void 0);
exports.MainThreadStorage = MainThreadStorage = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__param(0, (0, di_1.Optional)(ide_connection_1.IRPCProtocol)),
    tslib_1.__metadata("design:paramtypes", [Object])
], MainThreadStorage);
//# sourceMappingURL=main.thread.storage.js.map