/* * GNU AGPL-3.0 License * * Copyright (c) 2021 - present core.ai . All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License * for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. * */ /*global less */ // jshint ignore: start // @INCLUDE_IN_API_DOCS /** * ExtensionInterface defines utility methods for communicating between extensions safely. * A global `window.ExtensionInterface` object is made available in phoenix that can be called anytime after AppStart. * * ## Usage * For Eg. You may have two extensions installed say `angular` extension which has to call functions made available by * `angular-cli` Extension. * * For Making this possible, the `angular-cli` extension makes a named interface available with the ExtensionInterface * module and `angular` extension can get hold of the interface as and when the extension gets loaded. * * ```js * // in angular-cli extension, make a file say cli-interface.js module within the extension, do the following: * const ExtensionInterface = brackets.getModule("utils/ExtensionInterface"), * // You can replace exports with any object you want to expose outside the extension really. * ExtensionInterface.registerExtensionInterface("angularCli", exports); * ``` * Once the interface is registered, the angular extension can get hold of the interface with the following code * (inside or outside the extension) by using: * * ```js * let angularCli; * ExtensionInterface.waitAndGetExtensionInterface("angularCli").then(interfaceObj=> angularCli = interfaceObj); * ... * if(angularCli){ // check if angular cli is avilable * angularCli.callSomeFunction(); * } * ... * ``` * * **Note** that the `angularCli` interface is async populated as and when the cli extension is loaded and the * interface made available. * * **NBB:** Do Not use `await waitAndGetExtensionInterface` on tol level require as the module loading might fail. * * @module utils/ExtensionInterface */ define(function (require, exports, module) { const EVENT_EXTENSION_INTERFACE_REGISTERED = "extensionInterfaceRegistered"; /* standard named interfaces registered by default extensions*/ const _DEFAULT_EXTENSIONS_INTERFACE_NAMES = { PHOENIX_LIVE_PREVIEW: "Extn.Phoenix.livePreview" }; let EventDispatcher = require("utils/EventDispatcher"); let _extensionInterfaceMap = {}; /** * Registers a named extension interface. Will overwrite if an interface of the same name is already present. * * @example