Organized all script files

Removed useless things from all files
Added an update notification if there is an update
Updated the directory for the app icon
This commit is contained in:
2025-11-18 13:23:50 -05:00
parent df23040017
commit 7f01bace06
9 changed files with 220 additions and 451 deletions

View File

@@ -0,0 +1,77 @@
const GITHUB_OWNER = 'ItsSkaiya';
const GITHUB_REPO = 'WaifuBoard';
const CURRENT_VERSION = '1.0.0';
let currentVersionDisplay;
let latestVersionDisplay;
let updateToast;
document.addEventListener('DOMContentLoaded', () => {
currentVersionDisplay = document.getElementById('currentVersionDisplay');
latestVersionDisplay = document.getElementById('latestVersionDisplay');
updateToast = document.getElementById('updateToast');
if (currentVersionDisplay) {
currentVersionDisplay.textContent = CURRENT_VERSION;
}
checkForUpdates();
});
function showToast(latestVersion) {
if (latestVersionDisplay && updateToast) {
latestVersionDisplay.textContent = latestVersion;
updateToast.classList.add('update-available');
updateToast.classList.remove('hidden');
} else {
console.error("Error: Cannot display toast because one or more DOM elements were not found.");
}
}
function isVersionOutdated(versionA, versionB) {
const vA = versionA.replace(/^v/, '').split('.').map(Number);
const vB = versionB.replace(/^v/, '').split('.').map(Number);
for (let i = 0; i < Math.max(vA.length, vB.length); i++) {
const numA = vA[i] || 0;
const numB = vB[i] || 0;
if (numA < numB) return true;
if (numA > numB) return false;
}
return false;
}
async function checkForUpdates() {
console.log(`Checking for updates for ${GITHUB_OWNER}/${GITHUB_REPO}...`);
const apiUrl = `https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases/latest`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.statusText}`);
}
const data = await response.json();
const latestVersion = data.tag_name;
console.log(`Latest GitHub Release: ${latestVersion}`);
if (isVersionOutdated(CURRENT_VERSION, latestVersion)) {
console.warn('Update available!');
showToast(latestVersion);
} else {
console.info('Package is up to date.');
hideToast();
}
} catch (error) {
console.error('Failed to fetch GitHub release:', error);
}
}