Add little "animation" (. -> .. -> ...), cleanup, & add support for the gitea instance

This commit is contained in:
million1156 2024-03-22 17:24:30 -05:00
parent bdd7b1d134
commit 4f108a602b

View file

@ -1,45 +1,49 @@
<script lang="ts">
// Allow for us to use client-sided code when needed
import { onMount } from "svelte";
// cool moving dots :3
// NOTE: This is required to be ran on the server due to issues with Svelte
let text = "Downloading Suyu";
setInterval(() => {
text += ".";
if (text.length > 19) {
text = "Downloading Suyu";
}
//console.log(text);
}, 500);
$: htmlContent = `${text}`;
onMount(async () => {
// Variables
const UA = navigator.userAgent;
const url = `https://gitlab.com/api/v4/projects/55919530/repository/tree`;
const url = `https://git.suyu.dev/api/v1/repos/suyu/suyu/tags`;
const developerMode = false;
let timeout = 3000;
let latestRelease = "";
// Infinite timeout to test download workflow, comment out or disable developerMode if you don't want this
// nvm this was bugging out lmao
/* if (developerMode) {
timeout = 9999;
return;
} */
// NOTE: I have no idea if this works.. Shoutout to the very smart person who blocked ALL API requests to the git server...
async function getTag() {
try {
// Get the latest release tag
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) => {
// what in the FUCK.. null, i HATE you officially
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;
}
}
}
});
// 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;
// Release found
if (latestRelease) {
@ -54,18 +58,24 @@
return null;
}
}
const latestRelease = await getTag();
if (!developerMode) {
latestRelease = await getTag();
} else {
latestRelease = "v0.0.1";
console.log(latestRelease)
}
setTimeout(() => {
if (UA.includes("Windows")) {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/Suyu-Windows_x64.7z`;
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Windows_x64.7z`;
} else if (UA.includes("Android")) {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/app-mainline-release.apk`;
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/app-mainline-release.apk`;
} else if (UA.includes("Linux")) {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/suyu-mainline--.AppImage`;
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/suyu-mainline--.AppImage`;
} else if (UA.includes("Macintosh;")) {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/raw/master/${latestRelease}/suyu-macOS-arm64.dmg?inline=false`;
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/suyu-macOS-arm64.dmg?inline=false`;
} else {
window.location.href = `https://gitlab.com/suyu-emu/suyu-releases/-/blob/master/${latestRelease}/`;
window.location.href = `https://git.suyu.dev/suyu/suyu/releases/${latestRelease}/`;
}
}, 3000);
});
@ -96,28 +106,10 @@
stroke="white"
/>
</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]">
Your download should start shortly. If it doesn't, click <a