Skip to content

Commit d890075

Browse files
authored
fix: Acode ignoring main, readme and icon fields in plugin manifest (#1085)
* fix: Acode ignoring main, readme and icon fields in plugin manifest * removed hardcoded values, used manifest file values * Update installPlugin.js * Update loadPlugin.js * removed fs test for plugin.main, use try/catch instead * Revert "removed fs test for plugin.main, use try/catch instead" This reverts commit 1ff70a5.
1 parent 89e1320 commit d890075

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

src/lib/installPlugin.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default async function installPlugin(
101101
const zip = new JSZip();
102102
await zip.loadAsync(plugin);
103103

104-
if (!zip.files["plugin.json"] || !zip.files["main.js"]) {
104+
if (!zip.files["plugin.json"]) {
105105
throw new Error(strings["invalid plugin"]);
106106
}
107107

@@ -110,6 +110,25 @@ export default async function installPlugin(
110110
await zip.files["plugin.json"].async("text"),
111111
);
112112

113+
/** patch main in manifest */
114+
if (!zip.files[pluginJson.main]) {
115+
pluginJson.main = "main.js";
116+
}
117+
118+
/** patch icon in manifest */
119+
if (!zip.files[pluginJson.icon]) {
120+
pluginJson.icon = "icon.png";
121+
}
122+
123+
/** patch readme in manifest */
124+
if (!zip.files[pluginJson.readme]) {
125+
pluginJson.readme = "readme.md";
126+
}
127+
128+
if (!zip.files[pluginJson.main]) {
129+
throw new Error(strings["invalid plugin"]);
130+
}
131+
113132
if (!isDependency && pluginJson.dependencies) {
114133
const manifests = await resolveDepsManifest(pluginJson.dependencies);
115134

src/lib/loadPlugin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
88
const baseUrl = await helpers.toInternalUri(Url.join(PLUGIN_DIR, pluginId));
99
const cacheFile = Url.join(CACHE_STORAGE, pluginId);
1010

11+
const pluginJson = await fsOperation(
12+
Url.join(PLUGIN_DIR, pluginId, "plugin.json"),
13+
).readFile("json");
14+
15+
let mainUrl;
16+
if (
17+
await fsOperation(Url.join(PLUGIN_DIR, pluginId, pluginJson.main)).exists()
18+
) {
19+
mainUrl = Url.join(baseUrl, pluginJson.main);
20+
} else {
21+
mainUrl = Url.join(baseUrl, "main.js");
22+
}
23+
1124
return new Promise((resolve, reject) => {
12-
const $script = <script src={Url.join(baseUrl, "main.js")}></script>;
25+
const $script = <script src={mainUrl}></script>;
1326

1427
$script.onerror = (error) => {
1528
reject(

src/pages/plugin/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default async function PluginInclude(
7777
).readFile("json");
7878
const { author } = installedPlugin;
7979
const description = await fsOperation(
80-
Url.join(PLUGIN_DIR, id, "readme.md"),
80+
Url.join(PLUGIN_DIR, id, installedPlugin.readme),
8181
).readFile("utf8");
8282
let changelogs = "";
8383
if (installedPlugin.changelogs) {
@@ -93,7 +93,7 @@ export default async function PluginInclude(
9393
}
9494

9595
const iconUrl = await helpers.toInternalUri(
96-
Url.join(PLUGIN_DIR, id, "icon.png"),
96+
Url.join(PLUGIN_DIR, id, installedPlugin.icon),
9797
);
9898
const iconData = await fsOperation(iconUrl).readFile();
9999
const icon = URL.createObjectURL(

src/pages/plugins/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export default function PluginsInclude(updates) {
337337
if (!((updates && updates.includes(id)) || !updates)) return;
338338
const url = Url.join(item.url, "plugin.json");
339339
const plugin = await fsOperation(url).readFile("json");
340-
const iconUrl = getLocalRes(id, "icon.png");
340+
const iconUrl = getLocalRes(id, plugin.icon);
341341
plugin.icon = await helpers.toInternalUri(iconUrl);
342342
plugin.installed = true;
343343
plugins.installed.push(plugin);

src/sidebarApps/extensions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async function listInstalledPlugins() {
306306
const id = Url.basename(item.url);
307307
const url = Url.join(item.url, "plugin.json");
308308
const plugin = await fsOperation(url).readFile("json");
309-
const iconUrl = getLocalRes(id, "icon.png");
309+
const iconUrl = getLocalRes(id, plugin.icon);
310310
plugin.icon = await helpers.toInternalUri(iconUrl);
311311
plugin.installed = true;
312312
return plugin;

0 commit comments

Comments
 (0)