"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ChromeLauncher = __importStar(require("chrome-launcher"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const core_1 = require("../../core");
const common_1 = require("../../core/libs/config/common");
const config_1 = __importDefault(require("../utils/config"));
const update_1 = require("../utils/update");
class Account extends core_1.AccountModule {
    [core_1.AccountCmdEnum.IsLogin](environment) {
        if (process.env.OPDEV_TOKEN) {
            return true;
        }
        return super[core_1.AccountCmdEnum.IsLogin](environment);
    }
    async openLoginBrowser(url, server) {
        const chromePath = ChromeLauncher.Launcher.getFirstInstallation();
        if (!chromePath) {
            this.execute(core_1.ModuleName.ui, core_1.UICmdEnum.openPage, url);
        }
        else {
            const ignoreFlags = ['--disable-extensions'];
            const defaultFlags = ChromeLauncher.Launcher.defaultFlags().filter((flag) => !ignoreFlags.includes(flag));
            this.chrome = await ChromeLauncher.launch({
                chromePath,
                startingUrl: url,
                ignoreDefaultFlags: true,
                chromeFlags: defaultFlags,
            });
            this.chrome.process.addListener('exit', () => {
                server === null || server === void 0 ? void 0 : server.close();
            });
        }
    }
    closeBrowser() {
        this.chrome && this.chrome.kill();
    }
    clearUserData() {
        fs_extra_1.default.emptyDirSync(path_1.default.join(config_1.default.CacheRoot, config_1.default.userData));
    }
    async updateFeatureGating() {
        (0, common_1.clearFG)();
        await (0, update_1.writeUpdateData)(this);
        await (0, update_1.writeFGData)();
    }
}
exports.default = Account;
