diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 39562fb..1527511 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -36,16 +36,23 @@ export default function TabOneScreen() { async function fetchReleases() { setLoading(true); const awaitedOptions = await AsyncStorage.getItem("prevancedOptions"); - const prevancedOptions: PrevancedOptions | null = JSON.parse(awaitedOptions || "{}"); + const prevancedOptions: PrevancedOptions | null = JSON.parse( + awaitedOptions || "{}" + ); let ghReleaseUrl; - if (prevancedOptions && prevancedOptions.ghRepo && prevancedOptions.ghReleaseTag) { + if ( + prevancedOptions && + prevancedOptions.ghRepo && + prevancedOptions.ghReleaseTag + ) { if (prevancedOptions.ghReleaseTag == "latest") { ghReleaseUrl = `https://api.github.com/repos/${prevancedOptions.ghRepo}/releases/latest`; } else { ghReleaseUrl = `https://api.github.com/repos/${prevancedOptions.ghRepo}/releases/tags/${prevancedOptions.ghReleaseTag}`; } } else { - ghReleaseUrl = "https://api.github.com/repos/Revanced-APKs/build-apps/releases/latest"; + ghReleaseUrl = + "https://api.github.com/repos/Revanced-APKs/build-apps/releases/latest"; } if (!ghReleaseUrl) { toast.show("Empty GitHub release URL", { @@ -53,9 +60,7 @@ export default function TabOneScreen() { }); return; } - const response = await fetch( - ghReleaseUrl - ); + const response = await fetch(ghReleaseUrl); if (!response.ok) { toast.show(`Failed to fetch releases from ${prevancedOptions?.ghRepo}`, { native: true, @@ -63,23 +68,52 @@ export default function TabOneScreen() { return; } const data = await response.json(); - data.assets && setReleases(data.assets.filter((asset: Release) => !asset.name.match("magisk")).map((asset: Release) => { - let name = asset.name.split("-")[0]; - name = name.charAt(0).toUpperCase() + name.slice(1); - let version = asset.name.split("-")[2]; - let arch = asset.name.split("-")[3].split(".")[0]; + data.assets && + setReleases( + data.assets + .filter((asset: Release) => !asset.name.match("magisk")) + .map((asset: Release) => { + let name = ""; + let version = ""; + let arch = ""; + const regex = /(.+)-revanced-(v[\d.]+)-(\S+)\.apk/; + const match = asset.name.match(regex); - if (arch != "all") { - name = name + " " + arch; - } - return { - name, - fileName: asset.name, - version, - arch, - browser_download_url: asset.browser_download_url, - }; - })); + if (match) { + name = match[1].charAt(0).toUpperCase() + match[1].slice(1); + version = match[2]; + arch = match[3]; + + if (arch !== "all") { + name = name + " " + arch; + } + } else { + const regex = /(.+)-revanced-(v[\S.]+)-(\S+)\.apk/; + const match = asset.name.match(regex); + if (match) { + name = match[1].charAt(0).toUpperCase() + match[1].slice(1); + version = match[2]; + if (version.length > 30) { + version = version.slice(0, 30); + version = version + "..."; + } + arch = match[3]; + + if (arch !== "all") { + name = name + " " + arch; + } + } + } + + return { + name, + fileName: asset.name, + version, + arch, + browser_download_url: asset.browser_download_url, + }; + }) + ); } useEffect(() => { async function initRelease() { @@ -91,85 +125,99 @@ export default function TabOneScreen() { return ( {loading ? ( - - - - ) : - <> - - - - - - - {releases - .filter((release) => - release.fileName.toLowerCase().includes(search.toLowerCase()) - ) - .reverse() - .map((release, index) => { - return ( - - - -

{release.name}

- {release.fileName} - - - {release.version} - - {release.arch} - -
- - - -
-
- ); - })} -
-
-
- - } + > + + + ) : ( + <> + + + + + + + {releases + .filter((release) => + release.fileName + .toLowerCase() + .includes(search.toLowerCase()) + ) + .reverse() + .map((release, index) => { + return ( + + + +

{release.name}

+ + {release.fileName} + + + + {release.version} + + {release.arch} + +
+ + + +
+
+ ); + })} +
+
+
+ + + )}
); }