"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadWindowState = 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 vscode_1 = require("../../../common/vscode");
const window_activity_timer_1 = require("./window-activity/window-activity-timer");
let MainThreadWindowState = class MainThreadWindowState {
    constructor(rpcProtocol) {
        this.rpcProtocol = rpcProtocol;
        this.toDispose = new ide_core_browser_1.DisposableCollection();
        this.proxy = this.rpcProtocol.getProxy(vscode_1.ExtHostAPIIdentifier.ExtHostWindowState);
        this.blurHandler = () => {
            this.proxy.$onDidChangeWindowFocus(false);
        };
        this.focusHandler = () => {
            this.proxy.$onDidChangeWindowFocus(true);
        };
        window.addEventListener('blur', this.blurHandler);
        window.addEventListener('focus', this.focusHandler);
        const tracker = new window_activity_timer_1.WindowActivityTimer(window);
        this.toDispose.push(tracker.onDidChangeActiveState((isActive) => this.onActiveStateChanged(isActive)));
        this.toDispose.push(tracker);
    }
    onActiveStateChanged(isActive) {
        this.proxy.$onDidChangeWindowActive(isActive);
    }
    dispose() {
        window.removeEventListener('blur', this.blurHandler);
        window.removeEventListener('focus', this.focusHandler);
        this.toDispose.dispose();
    }
};
exports.MainThreadWindowState = MainThreadWindowState;
exports.MainThreadWindowState = MainThreadWindowState = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true }),
    tslib_1.__param(0, (0, di_1.Optional)(Symbol())),
    tslib_1.__metadata("design:paramtypes", [Object])
], MainThreadWindowState);
//# sourceMappingURL=main.thread.window-state.js.map