Merge pull request #3 from million1156/dev

Add support for Android downloads
This commit is contained in:
nullptr 2024-03-28 13:41:16 +00:00 committed by GitHub
commit ed16668f63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 82 additions and 107 deletions

View file

@ -20,28 +20,19 @@ async function fetchServerSideData() {
}, },
}) })
: Promise.resolve({ json: () => roleMembers }), : Promise.resolve({ json: () => roleMembers }),
GITLAB_API_TOKEN fetch("https://git.suyu.dev/api/v1/repos/suyu/suyu"),
? fetch("https://gitlab.com/api/v4/projects/suyu-emu%2Fsuyu/", {
headers: {
Authorization: `Bearer ${GITLAB_API_TOKEN}`,
},
})
: Promise.resolve({ json: () => ({ star_count: 0 }) }), // Default to 0 if no token is provided
fetch('https://git.suyu.dev/api/v1/repos/suyu/suyu/commits?stat=false&verification=false&files=false&limit=1')
]; ];
const [res, roles, gitlabRes, suyuGitRes] = await Promise.all(promises); const [res, roles, gitlabRes, suyuGitRes] = await Promise.all(promises);
const jsonPromises = [res.json(), roles.json(), gitlabRes.json()]; const jsonPromises = [res.json(), roles.json(), gitlabRes.json()];
const [resJson, rolesJson, gitlabResJson] = await Promise.all(jsonPromises); const [resJson, rolesJson, gitResJson] = await Promise.all(jsonPromises);
memberCount = resJson.approximate_member_count; memberCount = resJson.approximate_member_count;
starCount = gitlabResJson.star_count;
gitCommits = parseInt(suyuGitRes?.headers?.get('x-total'), 10) || 0; gitCommits = parseInt(suyuGitRes?.headers?.get('x-total'), 10) || 0;
if (DISCORD_USER_TOKEN) roleMembers = rolesJson; if (DISCORD_USER_TOKEN) roleMembers = rolesJson;
console.log("Member count:", memberCount); console.log("Member count:", memberCount);
console.log("Stars count:", starCount);
console.log('Git commit count', gitCommits); console.log('Git commit count', gitCommits);
} }

View file

@ -1,74 +1,80 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte"; // Allow for us to use client-sided code when needed
onMount(async () => { import { onMount } from "svelte";
const UA = navigator.userAgent;
const url = `https://gitlab.com/api/v4/projects/55919530/repository/tree`;
async function getTag() {
try {
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
},
});
// Convert to JSON
let files = await response.json();
files = files.filter((f) => f.name.startsWith("v") && f.type === "tree");
// get the latest release using the version number
// thanks, copilot!!
const latestRelease = files.reduce((a, b) => {
const aVersion = a.name.replace("v", "").split(".");
const bVersion = b.name.replace("v", "").split(".");
if (aVersion[0] > bVersion[0]) {
return a;
} else if (aVersion[0] < bVersion[0]) {
return b;
} else {
if (aVersion[1] > bVersion[1]) {
return a;
} else if (aVersion[1] < bVersion[1]) {
return b;
} else {
if (aVersion[2] > bVersion[2]) {
return a;
} else if (aVersion[2] < bVersion[2]) {
return b;
} else {
return a;
}
}
}
});
// Release found // cool moving dots :3
if (latestRelease) { // NOTE: This is required to be ran on the server due to issues with Svelte
console.log("Latest release tag:", latestRelease.name); let text = "Downloading Suyu";
return latestRelease.name; // Assuming the first result is the latest const textLength = text.length
} else { setInterval(() => {
console.log("No releases found."); text += ".";
return null; // Text length + 3 is essentially the length of the text above + the 3 dots
} if (text.length > textLength + 3) {
} catch (error) { text = "Downloading Suyu";
console.error("Error fetching latest release tag:", error); }
return null; }, 500);
}
} $: htmlContent = `${text}`;
const latestRelease = await getTag();
setTimeout(() => { onMount(async () => {
if (UA.includes("Windows")) { // Variables
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/Suyu-Windows_x64.7z`; const UA = navigator.userAgent;
} else if (UA.includes("Linux")) { const url = `https://git.suyu.dev/api/v1/repos/suyu/suyu/tags`;
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/suyu-mainline--.AppImage`; const fakeVersionTag = false; // Fake version tag? (for debugging)
} else if (UA.includes("Macintosh;")) { let latestRelease = "";
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/suyu-macOS-arm64.dmg?inline=false`;
} else { async function getTag() {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/blob/master/${latestRelease}/`; try {
} // Get the latest release tag
}, 3000); const response = await fetch(url, {
}) headers: {
"Content-Type": "application/json",
},
});
// Sort the response & get the first release (usually the latest)
/* TODO: Make the process way cleaner */
const releases = await response.json();
const latestRelease = releases[0].name;
console.log(latestRelease);
// Release found
if (latestRelease) {
console.log("Latest release tag:", latestRelease);
return latestRelease; // Assuming the first result is the latest
} else {
console.log("No releases found.");
return null;
}
} catch (error) {
console.error("Error fetching latest release tag:", error);
return null;
}
}
if (!fakeVersionTag) {
latestRelease = await getTag();
} else {
latestRelease = "v0.0.1";
console.log(latestRelease);
}
setTimeout(() => {
if (UA.includes("Windows")) {
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Windows_x86_64.7z`;
// Android is above Linux because Android UA's also contain "Linux"
} else if (UA.includes("Android")) {
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Android_Arm64.apk`;
} else if (UA.includes("Linux")) {
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Linux_x86_64.AppImage`;
} else if (UA.includes("Macintosh;")) {
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-macOS-Arm64.dmg`;
} else {
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/${latestRelease}/`;
}
}, 3000);
});
</script> </script>
<svelte:head> <svelte:head>
<title>Downloading Suyu</title> <title>Downloading Suyu</title>
</svelte:head> </svelte:head>
@ -94,36 +100,14 @@
stroke="white" stroke="white"
/> />
</svg> </svg>
<script>
onMount(() => {
let text = "Downloading Suyu";
let interval = setInterval(() => {
text += ".";
if (text.length > 16) {
text = "Downloading Suyu";
}
$text = text;
}, 500);
$: clearInterval(interval);
});
</script>
<!-- TODO: Have the 3 dots loop (e.g . -> .. -> ...) -->
<h1 class="text-[24px] leading-[1.41] md:text-[60px] md:leading-[1.1]">
Downloading Suyu...
</h1>
<!-- <h1 class="text-[24px] leading-[1.41] md:text-[60px] md:leading-[1.1]">
{#if $text}
{$text}
{:else}
Downloading Suyu
{/if}
</h1> -->
<h1 class="text-[24px] leading-[1.41] md:text-[60px] md:leading-[1.1]">
{@html htmlContent}
</h1>
<p class="max-w-[36rem] text-lg leading-relaxed text-[#A6A5A7]"> <p class="max-w-[36rem] text-lg leading-relaxed text-[#A6A5A7]">
Your download should start shortly. If it doesn't, click <a Your download should start shortly. If it doesn't, click <a
href="https://gitlab.suyu.dev/suyu/suyu/releases">here</a href="https://git.suyu.dev/suyu/suyu/releases"><u>here</u></a
>. >.
</p> </p>
</div> </div>

View file

@ -39,11 +39,11 @@
<p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: What is the purpose of Suyu?</p> <p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: What is the purpose of Suyu?</p>
<p class= "text-m text-[15px]">A: The purpose of this project is to provide a free, open-source alternative to the now-dead Yuzu emulator. We believe that the community should be able to emulate their Switch device (legally) and be able to enjoy their favorite game titles.</p> <p class= "text-m text-[15px]">A: The purpose of this project is to provide a free, open-source alternative to the now-dead Yuzu emulator. We believe that the community should be able to emulate their Switch device (legally) and be able to enjoy their favorite game titles.</p>
<p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: How can I contribute to Suyu?</p> <p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: How can I contribute to Suyu?</p>
<p class= "text-m text-[15px]">A: You can contribute to this project by submitting a pull request on our <a href="https://git.suyu.dev/suyu/suyu">Git</a> page. We are always looking for new contributors to help us improve the project!</p> <p class= "text-m text-[15px]">A: You can contribute to this project by submitting a pull request on our <a href="https://git.suyu.dev/suyu/suyu"><u>Git</u></a> page. We are always looking for new contributors to help us improve the project!</p>
<p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: Where can I download Suyu?</p> <p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: Where can I download Suyu?</p>
<p class= "text-m text-[15px]">A: You can download the latest build of Suyu from our <a href="https://git.suyu.dev/suyu/suyu/releases">Git</a>. Please make sure you are using the right URL!</p> <p class= "text-m text-[15px]">A: You can download the latest build of Suyu from our <a href="https://git.suyu.dev/suyu/suyu/releases"><u>Git</u></a>. Please make sure you are using the right URL!</p>
<p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: What is the current progress for Suyu?</p> <p class="text-[15px] leading-[1.41] md:text-[19px] md:leading-[1.1]">Q: What is the current progress for Suyu?</p>
<p class= "text-m text-[15px]">A: As of 3/20/2024, we have released our first Windows binary 🎉! You can find it <a href="https://git.suyu.dev/suyu/suyu/releases">here</a>. We are always trying to make more and more progress, so please feel free to <a href="https://discord.gg/suyu">join the Discord!</a></p> <p class= "text-m text-[15px]">A: As of 3/20/2024, we have released our first Windows binary 🎉! You can find it <a href="https://git.suyu.dev/suyu/suyu/releases"><u>here</u></a>. We are always trying to make more and more progress, so please feel free to <a href="https://discord.gg/suyu"><u>join the Discord!</u></a></p>
<br /> <br />
<div class="leading-[1.41] items-center text-[15px] md:leading-[1.1] flex gap-2 text-gray-600">Email hosting lovingly provided by <div class="leading-[1.41] items-center text-[15px] md:leading-[1.1] flex gap-2 text-gray-600">Email hosting lovingly provided by
<a href="https://tuta.com" target="_blank"> <a href="https://tuta.com" target="_blank">