From a0e5a71b4b604a16f0621400605e3f7005ac49fb Mon Sep 17 00:00:00 2001
From: Victor Borges <victor1882@outlook.com>
Date: Wed, 30 Apr 2025 00:39:58 -0300
Subject: add more undefined checks

---
 src/PartnerEventStorePatch.tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/PartnerEventStorePatch.tsx')

diff --git a/src/PartnerEventStorePatch.tsx b/src/PartnerEventStorePatch.tsx
index d7ef75b..3aa2a94 100644
--- a/src/PartnerEventStorePatch.tsx
+++ b/src/PartnerEventStorePatch.tsx
@@ -32,7 +32,9 @@ const steamClanSteamID = "103582791470414830";
 const steamClanID = "40893422";
 const steamOSAppId = 1675200;
 const githubReleasesURI = "https://api.github.com/repos/ublue-os/bazzite/releases";
-const generator = fetchReleases();
+let generator: AsyncGenerator<any, undefined, unknown>;
+const mutex = new Mutex();
+const cachedGithubReleases: { gid: string, release: any }[] = [];
 
 enum SteamEventType {
   SmallUpdate = 12,
@@ -50,9 +52,6 @@ enum SteamOSChannel {
   Preview = "previewchannel",
 }
 
-const mutex = new Mutex();
-const cachedGithubReleases: { gid: string, release: any }[] = [];
-
 export function patchPartnerEventStore(): Patch[] {
   const loadAdjacentPartnerEventsPatch = replacePatch(
     PartnerEventStore.prototype,
@@ -244,13 +243,17 @@ async function LoadBazziteReleasesAsPartnerEvents(module: any, gid: any, tags: S
 
 async function fetchMoreReleases(count: number, beta: boolean) {
   const releases = [];
+
+  if (!generator && cachedGithubReleases.length === 0)
+    generator = fetchReleases();
+
   let iterator;
 
   do {
     iterator = await generator.next();
     const release = iterator.value;
 
-    if ((beta && release.prerelease) || (!beta && !release.prerelease))
+    if (release && ((beta && release.prerelease) || (!beta && !release.prerelease)))
       releases.push(release);
   } while (releases.length < count && !iterator.done)
 
-- 
cgit v1.2.3

