import { AppModule } from '../../app-modules/app-module.js';
import { EventEmitter } from '@kano/common/index.js';
import { transformLegacy } from './legacy.js';
export class ApplicationModule extends AppModule {
    constructor(output) {
        super(output);
        this._onDidStart = new EventEmitter();
        this._justRestarted = false;
        this.userSubscriptions = [];
        this.addMethod('onStart', '_onStart');
        this.addMethod('restart', '_restart');
        this.addLifecycleStep('stop', '_reset');
        this.addLifecycleStep('afterRun', '_start');
    }
    static transformLegacy(app) {
        transformLegacy(app);
    }
    static get id() { return 'app'; }
    _onStart(callback) {
        this._onDidStart.event(callback, null, this.userSubscriptions);
    }
    _start() {
        this._onDidStart.fire();
    }
    _reset() {
        this.userSubscriptions.forEach(d => d.dispose());
        this.userSubscriptions.length = 0;
    }
    _restart() {
        if (this._justRestarted) {
            return;
        }
        this._justRestarted = true;
        this.output.restart();
        setTimeout(() => {
            this._justRestarted = false;
        });
    }
}
export default ApplicationModule;
//# sourceMappingURL=app.js.map