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

Function installPlugin

src/lib/installPlugin.js:25–283  ·  view source on GitHub ↗
(
	id,
	name,
	purchaseToken,
	isDependency,
)

Source from the content-addressed store, hash-verified

23 * @param {boolean} isDependency
24 */
25export default async function installPlugin(
26 id,
27 name,
28 purchaseToken,
29 isDependency,
30) {
31 if (!isDependency) {
32 loaderDialog = loader.create(name || "Plugin", strings.installing, {
33 timeout: 6000,
34 });
35 depsLoaders = [];
36 }
37
38 let pluginDir;
39 let pluginUrl;
40 let state;
41
42 try {
43 if (!(await fsOperation(PLUGIN_DIR).exists())) {
44 await fsOperation(DATA_STORAGE).createDirectory("plugins");
45 }
46 } catch (error) {
47 window.log("error", error);
48 }
49
50 if (!/^(https?|file|content):/.test(id)) {
51 pluginUrl = Url.join(
52 config.API_BASE,
53 "plugin/download/",
54 `${id}?device=${device.uuid}`,
55 );
56 if (purchaseToken) pluginUrl += `&token=${purchaseToken}`;
57 pluginUrl += `&package=${BuildInfo.packageName}`;
58 pluginUrl += `&version=${device.version}`;
59
60 pluginDir = Url.join(PLUGIN_DIR, id);
61 } else {
62 pluginUrl = id;
63 }
64
65 try {
66 if (!isDependency) loaderDialog.show();
67
68 let plugin;
69 if (
70 pluginUrl.includes(config.API_BASE) ||
71 pluginUrl.startsWith("file:") ||
72 pluginUrl.startsWith("content:")
73 ) {
74 // Use fsOperation for Acode registry URL
75 plugin = await fsOperation(pluginUrl).readFile(
76 undefined,
77 (loaded, total) => {
78 loaderDialog.setMessage(
79 `${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`,
80 );
81 },
82 );

Callers 1

resolveDepFunction · 0.70

Calls 15

loadPluginWithTimeoutFunction · 0.90
fsOperationFunction · 0.85
resolveFunction · 0.85
resolveDepsManifestFunction · 0.85
confirmFunction · 0.85
resolveDepFunction · 0.85
deleteRedundantFilesFunction · 0.85
logMethod · 0.80
newMethod · 0.80
saveMethod · 0.80
createMethod · 0.65
existsMethod · 0.65

Tested by

no test coverage detected