/**
 * Contains generalized functionality for managing the Desktop (at the FSBL level rather
 * than at the fin/system level).
 */
import { RouterClient } from "../clients/routerClient";
import { ConfigClient } from "../clients/configClient";
import SystemManagerClient from "../common/systemManagerClient";
import { getMyWindowIdentifier } from "./util";
import { System } from "./system";
import { Startup } from "../clients/Startup/Startup";
/**
 * Returns an FSBLInfo object that provides the current version and git hash.
 *
 * @param {(FSBL) => void} [cb] Optional callback to receive FSBLInfo object. Use promise if possible.
 * @returns {FSBLInfo} Promise that resolves a FSBLInfo object
 */
export const getFSBLInfo = async (cb) => {
    const startup = Startup.getInstance();
    await startup.onReady();
    const feaInfo = await System.getFEAInfo();
    const { err, data: systemInfo } = await ConfigClient.get(["finsemble", "system"]);
    if (err || !systemInfo) {
        return {
            ...feaInfo,
            FSBLVersion: "unknown",
            gitHash: "unknown",
        };
    }
    const info = {
        ...feaInfo,
        FSBLVersion: systemInfo.FSBLVersion,
        gitHash: systemInfo.gitHash,
    };
    if (cb) {
        cb(info);
    }
    return info;
};
/**
 * Shutdown the SmartDesktop (Finsemble).
 */
export const shutdownApplication = () => {
    RouterClient.transmit("Application.shutdown", {});
};
/**
 * Restart the SmartDesktop (Finsemble).
 * @param [params]
 * @param [params.forceRestart]=false Whether to give components a chance to shutdown. ForceRestart is used during the reset sequence.
 */
export const restartApplication = (params) => {
    RouterClient.transmit("Application.restart", params || {});
};
/**
 * @language javascript, java, dotnet
 * This method is an experimental feature in Finsemble Labs. Calling this method automatically arranges all windows on the user's screen into a grid-like pattern.
 *
 * @param params Parameters Unused
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const autoArrange = async (params, cb) => {
    params = params || {};
    await SystemManagerClient.waitForStartup("windowService");
    const myWindowIdentifier = await getMyWindowIdentifier();
    const { err } = await RouterClient.query("DockingService.autoArrange", {
        windowIdentifier: myWindowIdentifier,
    });
    cb === null || cb === void 0 ? void 0 : cb(err);
    return { err };
};
/**
 * @language javascript, java, dotnet
 * Minimizes all windows.
 *
 * ```javascript
 * await FSBL.Clients.WorkspaceClient.minimizeWindows();
 * ```
 * @param params
 * @param params.windowList Optional list of windows to minimize
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const minimizeWindows = async (params, cb) => {
    await SystemManagerClient.waitForStartup("windowService");
    const completeParams = {
        ...params,
    };
    const { err } = await RouterClient.query("LauncherService.minimizeWindows", completeParams);
    cb === null || cb === void 0 ? void 0 : cb(err);
    return { err };
};
/**
 * @language javascript, java, dotnet
 * Brings all windows to the front, revealing any that are minimized.
 *
 * ```javascript
 * await FSBL.Clients.WorkspaceClient.bringWindowsToFront();
 * ```
 * @param params
 * @param params.windowList Optional list of windows to bring to front, otherwise all workspace windows will be brought to front.
 * @param cb The callback to be invoked after the method completes successfully.
 */
export const bringWindowsToFront = async (params, cb) => {
    await SystemManagerClient.waitForStartup("windowService");
    const completeParams = {
        ...params,
    };
    const { err } = await RouterClient.query("LauncherService.bringWindowsToFront", completeParams);
    cb === null || cb === void 0 ? void 0 : cb(err);
    return { err };
};
//# sourceMappingURL=Desktop.js.map