"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadCommon = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_connection_1 = require("@opensumi/ide-connection");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const sumi_1 = require("../../common/sumi");
const types_1 = require("../types");
/**
 * 通用 Sumi Main Api
 * 对于一些比较小的零碎功能, 不单独开main.thread.xxx.ts了，这样方便快速开发
 */
let MainThreadCommon = class MainThreadCommon extends ide_core_browser_1.WithEventBus {
    constructor(rpcProtocol, injector) {
        super();
        this.rpcProtocol = rpcProtocol;
        this.injector = injector;
        this.subscribedEvent = new Set();
        this._proxy = this.rpcProtocol.getProxy(sumi_1.ExtHostSumiAPIIdentifier.ExtHostCommon);
    }
    onExtHostEvent(e) {
        if (this.subscribedEvent.has(e.payload.eventName)) {
            return this._proxy.$acceptEvent(e.payload.eventName, e.payload.eventArgs);
        }
    }
    async $subscribeEvent(eventName) {
        this.subscribedEvent.add(eventName);
        this.addDispose(ide_core_common_1.Disposable.create(() => {
            this.$unSubscribeEvent(eventName);
        }));
    }
    async $unSubscribeEvent(eventName) {
        this.subscribedEvent.delete(eventName);
    }
};
exports.MainThreadCommon = MainThreadCommon;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.IEventBus),
    tslib_1.__metadata("design:type", Object)
], MainThreadCommon.prototype, "themeService", void 0);
tslib_1.__decorate([
    (0, ide_core_browser_1.OnEvent)(types_1.ExtHostEvent),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [types_1.ExtHostEvent]),
    tslib_1.__metadata("design:returntype", void 0)
], MainThreadCommon.prototype, "onExtHostEvent", null);
exports.MainThreadCommon = MainThreadCommon = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__metadata("design:paramtypes", [Object, di_1.Injector])
], MainThreadCommon);
//# sourceMappingURL=main.thread.common.js.map