()
| 672 | } |
| 673 | |
| 674 | async function getOwned() { |
| 675 | $list.owned.setAttribute("empty-msg", strings["loading..."]); |
| 676 | |
| 677 | let iapPurchases = []; |
| 678 | if (helpers.isIapAvailable()) { |
| 679 | iapPurchases = await helpers.promisify(iap.getPurchases); |
| 680 | const disabledMap = settings.value.pluginsDisabled || {}; |
| 681 | |
| 682 | iapPurchases.forEach(async ({ productIds }) => { |
| 683 | const [sku] = productIds; |
| 684 | const url = Url.join(config.API_BASE, "plugin/owned", sku); |
| 685 | const plugin = await fsOperation(url).readFile("json"); |
| 686 | |
| 687 | plugins.owned.push(plugin); |
| 688 | }); |
| 689 | } else if (!(await auth.getLoggedInUser())) { |
| 690 | console.log("Not logged in"); |
| 691 | $list.owned.setAttribute("empty-msg", strings["login-to-view"]); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | try { |
| 696 | const res = await fetch(`${config.API_BASE}/plugins?owned=true`); |
| 697 | if (res.ok) { |
| 698 | const ownedPlugins = await res.json(); |
| 699 | if (Array.isArray(ownedPlugins)) { |
| 700 | ownedPlugins.forEach((plugin) => { |
| 701 | if ( |
| 702 | !iapPurchases.find(({ productIds }) => |
| 703 | productIds.includes(plugin.sku), |
| 704 | ) |
| 705 | ) { |
| 706 | plugins.owned.push(plugin); |
| 707 | } |
| 708 | }); |
| 709 | } |
| 710 | } |
| 711 | } catch (error) {} |
| 712 | |
| 713 | for (const plugin of plugins.owned) { |
| 714 | plugin.installed = Boolean( |
| 715 | plugins.installed.find(({ id }) => id === plugin.id), |
| 716 | ); |
| 717 | |
| 718 | if (plugin.installed) { |
| 719 | plugin.enabled = disabledMap[plugin.id] !== true; |
| 720 | plugin.onToggleEnabled = onToggleEnabled; |
| 721 | } |
| 722 | |
| 723 | $list.owned.append(<Item {...plugin} updates={updates} />); |
| 724 | } |
| 725 | |
| 726 | $list.owned.setAttribute("empty-msg", strings["no plugins found"]); |
| 727 | } |
| 728 | |
| 729 | function onInstall(plugin) { |
| 730 | if (updates) return; |
no test coverage detected