Skip to content

Commit 72d44dd

Browse files
authored
fix: plugin passing undefined to plugin item on plugin page (Acode-Foundation#1391)
- Refactor onInstall to accept the full plugin object instead of just pluginId. - Prevent duplicate entries in installed list and DOM. - Fixes issues where plugins installed via search/filter/direct URL would not appear or just appending default in installed list until page reload.
1 parent bf17cf6 commit 72d44dd

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/pages/plugin/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default async function PluginInclude(
188188
loadAd(this),
189189
installPlugin(plugin.source || id, plugin.name, purchaseToken),
190190
]);
191-
if (onInstall) onInstall(plugin.id);
191+
if (onInstall) onInstall(plugin);
192192
installed = true;
193193
update = false;
194194
if (!plugin.price && IS_FREE_VERSION && (await window.iad?.isLoaded())) {

src/pages/plugins/plugins.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,30 +363,53 @@ export default function PluginsInclude(updates) {
363363
$list.owned.setAttribute("empty-msg", strings["no plugins found"]);
364364
}
365365

366-
function onInstall(pluginId) {
366+
function onInstall(plugin) {
367367
if (updates) return;
368-
const plugin = plugins.all.find((plugin) => plugin.id === pluginId);
369-
if (plugin) {
370-
plugin.installed = true;
368+
369+
if (!plugin || !plugin.id) {
370+
console.error("Invalid plugin object passed to onInstall");
371+
return;
372+
}
373+
plugin.installed = true;
374+
375+
const existingIndex = plugins.installed.findIndex(p => p.id === plugin.id);
376+
if (existingIndex === -1) {
371377
plugins.installed.push(plugin);
378+
} else {
379+
// Update existing plugin
380+
plugins.installed[existingIndex] = plugin;
381+
}
382+
383+
const allPluginIndex = plugins.all.findIndex(p => p.id === plugin.id);
384+
if (allPluginIndex !== -1) {
385+
plugins.all[allPluginIndex] = plugin;
386+
}
387+
388+
const existingItem = $list.installed.get(`[data-id="${plugin.id}"]`);
389+
if (!existingItem) {
390+
$list.installed.append(<Item {...plugin} />);
372391
}
373392

374-
$list.installed.append(<Item {...plugin} />);
375393
}
376394

377395
function onUninstall(pluginId) {
378396
if (!updates) {
379-
const plugin = plugins.all.find((plugin) => plugin.id === pluginId);
380397
plugins.installed = plugins.installed.filter(
381398
(plugin) => plugin.id !== pluginId,
382399
);
400+
401+
const plugin = plugins.all.find((plugin) => plugin.id === pluginId);
383402
if (plugin) {
384403
plugin.installed = false;
385404
plugin.localPlugin = null;
386405
}
387406
}
388407

389-
$list.installed.get(`[data-id="${pluginId}"]`).remove();
408+
// Remove from DOM
409+
const existingItem = $list.installed.get(`[data-id="${pluginId}"]`);
410+
if (existingItem) {
411+
existingItem.remove();
412+
}
390413
}
391414

392415
function getLocalRes(id, name) {

0 commit comments

Comments
 (0)