export class ForegroundTaskManager {
    constructor(container) {
        this.container = container;
        this.activeForegroundTasks = [];
    }
    registerForegroundTask(task) {
        this.activeForegroundTasks.push(task);
    }
    unregisterForegroundTask(id) {
        this.activeForegroundTasks = this.activeForegroundTasks.filter((t) => t.id !== id);
    }
    async backgroundCurrentTask() {
        const tasks = [...this.activeForegroundTasks].reverse();
        this.activeForegroundTasks = [];
        for (const task of tasks) {
            await task.backgroundHandler();
        }
    }
    hasActiveTasks() {
        return this.activeForegroundTasks.length > 0;
    }
}
