(filterState, isInitial = false)
| 384 | } |
| 385 | |
| 386 | async function getFilteredPlugins(filterState, isInitial = false) { |
| 387 | if (!filterState) return; |
| 388 | if (isLoading || !hasMore) return; |
| 389 | |
| 390 | try { |
| 391 | isLoading = true; |
| 392 | $list.all.setAttribute("empty-msg", strings["loading..."]); |
| 393 | |
| 394 | const { items, hasMore: hasMoreResults } = |
| 395 | await retrieveFilteredPlugins(filterState); |
| 396 | |
| 397 | if (currentFilter !== filterState) { |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | const installed = await fsOperation(PLUGIN_DIR).lsDir(); |
| 402 | const disabledMap = settings.value.pluginsDisabled || {}; |
| 403 | |
| 404 | installed.forEach(({ url }) => { |
| 405 | const plugin = items.find(({ id }) => id === Url.basename(url)); |
| 406 | if (plugin) { |
| 407 | plugin.installed = true; |
| 408 | plugin.enabled = disabledMap[plugin.id] !== true; |
| 409 | plugin.onToggleEnabled = onToggleEnabled; |
| 410 | plugin.localPlugin = getLocalRes(plugin.id, "plugin.json"); |
| 411 | } |
| 412 | }); |
| 413 | |
| 414 | if (isInitial) { |
| 415 | $list.all |
| 416 | .querySelectorAll(".filter-empty") |
| 417 | .forEach((el) => el.remove()); |
| 418 | } |
| 419 | |
| 420 | plugins.all.push(...items); |
| 421 | |
| 422 | const fragment = document.createDocumentFragment(); |
| 423 | items.forEach((plugin) => { |
| 424 | fragment.append(<Item {...plugin} updates={updates} />); |
| 425 | }); |
| 426 | |
| 427 | if (fragment.childNodes.length) { |
| 428 | $list.all.append(fragment); |
| 429 | } else if (isInitial) { |
| 430 | $list.all.append( |
| 431 | <div className="filter-empty"> |
| 432 | {strings["no plugins found"] || "No plugins found"} |
| 433 | </div>, |
| 434 | ); |
| 435 | } |
| 436 | |
| 437 | hasMore = hasMoreResults; |
| 438 | if (!hasMore) { |
| 439 | $list.all.setAttribute("empty-msg", strings["no plugins found"]); |
| 440 | } |
| 441 | } catch (error) { |
| 442 | $list.all.setAttribute("empty-msg", strings["error"]); |
| 443 | console.error("Failed to filter plugins:", error); |
no test coverage detected