()
| 597 | } |
| 598 | |
| 599 | async function getAllPlugins() { |
| 600 | if (currentFilter) return; |
| 601 | if (isLoading || !hasMore) return; |
| 602 | |
| 603 | try { |
| 604 | isLoading = true; |
| 605 | |
| 606 | $list.all.setAttribute("empty-msg", strings["loading..."]); |
| 607 | |
| 608 | const response = await fetch( |
| 609 | withSupportedEditor( |
| 610 | `${config.API_BASE}/plugins?page=${currentPage}&limit=${LIMIT}`, |
| 611 | ), |
| 612 | ); |
| 613 | const newPlugins = await response.json(); |
| 614 | |
| 615 | if (newPlugins.length < LIMIT) { |
| 616 | hasMore = false; |
| 617 | } |
| 618 | |
| 619 | const installed = await fsOperation(PLUGIN_DIR).lsDir(); |
| 620 | const disabledMap = settings.value.pluginsDisabled || {}; |
| 621 | |
| 622 | installed.forEach(({ url }) => { |
| 623 | const plugin = newPlugins.find(({ id }) => id === Url.basename(url)); |
| 624 | if (plugin) { |
| 625 | plugin.installed = true; |
| 626 | plugin.enabled = disabledMap[plugin.id] !== true; |
| 627 | plugin.onToggleEnabled = onToggleEnabled; |
| 628 | plugin.localPlugin = getLocalRes(plugin.id, "plugin.json"); |
| 629 | } |
| 630 | }); |
| 631 | |
| 632 | // Add plugins to the all plugins array |
| 633 | plugins.all.push(...newPlugins); |
| 634 | |
| 635 | const fragment = document.createDocumentFragment(); |
| 636 | newPlugins.forEach((plugin) => { |
| 637 | fragment.append(<Item {...plugin} updates={updates} />); |
| 638 | }); |
| 639 | $list.all.append(fragment); |
| 640 | |
| 641 | currentPage++; |
| 642 | $list.all.setAttribute("empty-msg", strings["no plugins found"]); |
| 643 | } catch (error) { |
| 644 | window.log("error", error); |
| 645 | } finally { |
| 646 | isLoading = false; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | async function getInstalledPlugins(updates) { |
| 651 | $list.installed.setAttribute("empty-msg", strings["loading..."]); |
no test coverage detected