"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionMetadataService = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
// import { SumiContributesRunner } from './sumi/contributes';
const types_1 = require("./types");
// import { VSCodeContributeRunner } from './vscode/contributes';
let ExtensionMetadataService = class ExtensionMetadataService extends ide_core_browser_1.Disposable {
    initialize(extension) {
        this.eventBus.fire(new ide_core_browser_1.ExtensionEnabledEvent(extension.toJSON()));
        this.addDispose(this.registerActivationEvent(extension));
    }
    registerActivationEvent(extension) {
        const { activationEvents = [] } = extension.packageJSON;
        const activateDisposer = new ide_core_browser_1.Disposable();
        activationEvents.forEach((event) => {
            // https://code.visualstudio.com/api/references/activation-events#onUri
            // 绑定含有当前插件 id 的 onUri activation event
            // 只有打开 uri 的 id 匹配才会触发执行
            if (event === 'onUri') {
                event = `onUri:${extension.id}`;
            }
            activateDisposer.addDispose(this.activationService.onEvent(event, async () => {
                await extension.activate();
            }));
        });
        return activateDisposer;
    }
};
exports.ExtensionMetadataService = ExtensionMetadataService;
tslib_1.__decorate([
    (0, di_1.Autowired)(di_1.INJECTOR_TOKEN),
    tslib_1.__metadata("design:type", di_1.Injector)
], ExtensionMetadataService.prototype, "injector", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(),
    tslib_1.__metadata("design:type", types_1.IActivationEventService)
], ExtensionMetadataService.prototype, "activationService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.ILogger),
    tslib_1.__metadata("design:type", Object)
], ExtensionMetadataService.prototype, "logger", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.IEventBus),
    tslib_1.__metadata("design:type", Object)
], ExtensionMetadataService.prototype, "eventBus", void 0);
exports.ExtensionMetadataService = ExtensionMetadataService = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true })
], ExtensionMetadataService);
//# sourceMappingURL=metadata.service.js.map