MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / installPlugin

Method installPlugin

src/lib/acode.js:538–650  ·  view source on GitHub ↗

* Installs an Acode plugin from registry * @param {string} pluginId id of the plugin to install * @param {string} installerPluginName Name of plugin attempting to install * @returns {Promise }

(pluginId, installerPluginName)

Source from the content-addressed store, hash-verified

536 * @returns {Promise<void>}
537 */
538 installPlugin(pluginId, installerPluginName) {
539 return new Promise((resolve, reject) => {
540 fsOperation(Url.join(PLUGIN_DIR, pluginId))
541 .exists()
542 .then((isPluginExists) => {
543 if (isPluginExists) {
544 reject(new Error("Plugin already installed"));
545 return;
546 }
547
548 confirm(
549 strings.install,
550 `Do you want to install plugin '${pluginId}'${installerPluginName ? ` requested by ${installerPluginName}` : ""}?`,
551 ).then((confirmation) => {
552 if (!confirmation) {
553 reject(new Error("User cancelled installation"));
554 return;
555 }
556
557 let purchaseToken;
558 let product;
559 const pluginUrl = Url.join(config.API_BASE, `plugin/${pluginId}`);
560 fsOperation(pluginUrl)
561 .readFile("json")
562 .catch(() => {
563 reject(new Error("Failed to fetch plugin details"));
564 return null;
565 })
566 .then((remotePlugin) => {
567 if (remotePlugin) {
568 const isPaid = remotePlugin.price > 0;
569 helpers
570 .promisify(iap.getProducts, [remotePlugin.sku])
571 .then((products) => {
572 [product] = products;
573 if (product) {
574 return getPurchase(product.productId);
575 }
576 return null;
577 })
578 .then((purchase) => {
579 purchaseToken = purchase?.purchaseToken;
580
581 if (isPaid && !purchaseToken) {
582 if (!product) throw new Error("Product not found");
583 return helpers
584 .checkAPIStatus()
585 .then(async (apiStatus) => {
586 if (!apiStatus) {
587 alert(strings.error, strings.api_error);
588 return;
589 }
590
591 const { default: purchaseListener } = await import(
592 /* webpackChunkName: "purchaseHandler" */ "handlers/purchase"
593 );
594 iap.setPurchaseUpdatedListener(
595 ...purchaseListener(onpurchase, onerror),

Callers

nothing calls this directly

Calls 10

fsOperationFunction · 0.85
confirmFunction · 0.85
alertFunction · 0.85
purchaseListenerFunction · 0.85
resolveFunction · 0.85
getPurchaseFunction · 0.70
installPluginFunction · 0.70
existsMethod · 0.65
readFileMethod · 0.45

Tested by

no test coverage detected