From a2b27112043974e0687c9954c9ba6b216a99d210 Mon Sep 17 00:00:00 2001 From: didirus4 Date: Tue, 8 Jul 2025 01:12:16 +0300 Subject: [PATCH] refactor: Improve update.js and RunningAppBar.vue. Bump to v0.10.302 --- .../src/components/ui/RunningAppBar.vue | 54 ++++-- apps/app-frontend/src/helpers/update.js | 175 +++++++----------- apps/app/tauri.conf.json | 2 +- 3 files changed, 106 insertions(+), 125 deletions(-) diff --git a/apps/app-frontend/src/components/ui/RunningAppBar.vue b/apps/app-frontend/src/components/ui/RunningAppBar.vue index d5112309..8d400b85 100644 --- a/apps/app-frontend/src/components/ui/RunningAppBar.vue +++ b/apps/app-frontend/src/components/ui/RunningAppBar.vue @@ -38,7 +38,7 @@
-
- + @@ -129,18 +145,22 @@ const version = await getVersion() import { installState, getRemote, updateState } from '@/helpers/update.js' import ModalWrapper from './modal/ModalWrapper.vue' -const confirmUpdate = ref(null) +const updateModalView = ref(null) +const updateRequestFailView = ref(null) -const confirmUpdating = async () => { - confirmUpdate.value.show() +const initUpdateModal = async () => { + updateModalView.value.show() } -const approveUpdate = async () => { - confirmUpdate.value.hide() - await getRemote(true, true) +const initDownload = async () => { + updateModalView.value.hide() + const result = await getRemote(true); + if (!result) { + updateRequestFailView.value.show() + } } -await getRemote(true, false) +await getRemote(false) const router = useRouter() const card = ref(null) @@ -375,7 +395,7 @@ onBeforeUnmount(() => { text-shadow: #26065e; } -.download-modal { +.updater-modal { color: #3e8cde; padding: var(--gap-sm) var(--gap-lg); text-decoration: none; @@ -386,9 +406,9 @@ onBeforeUnmount(() => { transition: color 0.35s ease; } -.download-modal:hover, -.download-modal:focus, -.download-modal:active { +.updater-modal:hover, +.updater-modal:focus, +.updater-modal:active { color: #10fae5; text-shadow: #26065e; } diff --git a/apps/app-frontend/src/helpers/update.js b/apps/app-frontend/src/helpers/update.js index 8581190b..855b89e6 100644 --- a/apps/app-frontend/src/helpers/update.js +++ b/apps/app-frontend/src/helpers/update.js @@ -2,21 +2,19 @@ import { ref } from 'vue' import { getVersion } from '@tauri-apps/api/app' import { getArtifact, getOS } from '@/helpers/utils.js' - export const allowState = ref(false) export const installState = ref(false) export const updateState = ref(false) -export const latestBetaCommitTruncatedSha = ref('') -export const latestBetaCommitLink = ref('') -export const launcherUrl = 'https://www.astralium.su/get/ar' -const os = ref('') +const currentOS = ref('') const releaseLink = `https://git.astralium.su/api/v1/repos/didirus/AstralRinth/releases/latest` const failedFetch = [`Failed to fetch remote releases:`, `Failed to fetch remote commits:`] -const osNames = ['macos', 'windows', 'linux'] -const macExtension = `.dmg` // MacOS file type for download -const windowsExtension = `.msi` // Windows file type for download -const blacklistedBuilds = [ + +const osList = ['macos', 'windows', 'linux'] +const macExtensionList = ['.app', '.dmg'] +const windowsExtensionList = ['.exe', '.msi'] + +const blacklistPrefixes = [ `dev`, `nightly`, `dirty`, @@ -26,110 +24,73 @@ const blacklistedBuilds = [ `dirty_nightly`, ] // This is blacklisted builds for download. For example, file.startsWith('dev') is not allowed. -/** - * Asynchronous function to get remote data and handle updates and downloads. - * - * @param {boolean} elementIdBool - Indicates whether to disable an element ID. - * @param {boolean} downloadArtifactBool - Indicates whether to download an artifact. - */ -export async function getRemote(elementIdBool, downloadArtifactBool) { - fetch(releaseLink) - .then((response) => { - if (!response.ok) { - throw new Error(response.status) - } - return response.json() - }) - .then(async (data) => { - os.value = await getOS() - const latestRelease = data.name - let remoteVersion = undefined +export async function getRemote(isDownloadState) { + var releaseData = null; + var result = false; + try { + const response = await fetch(releaseLink); + if (!response.ok) { + throw new Error(response.status); + } + const remoteData = await response.json(); + currentOS.value = await getOS(); + const remoteLatestReleaseTag = remoteData.tag_name; + releaseData = document.getElementById('releaseData'); + const remoteVersion = releaseData ? (releaseData.textContent = remoteLatestReleaseTag) : remoteLatestReleaseTag; - if (!elementIdBool) { - const releaseData = document.getElementById('releaseData') - if (releaseData == null) { - console.error('Release data element not found.') - return false - } - releaseData.textContent = latestRelease - remoteVersion = `${releaseData.textContent}` - } else { - remoteVersion = latestRelease - } - if (osNames.includes(os.value.toLowerCase())) { - if (remoteVersion.startsWith('v' + await getVersion())) { - updateState.value = false - allowState.value = false - } else { - updateState.value = true - allowState.value = true - } - } else { - updateState.value = false - allowState.value = false - } - console.log('Update available state is', updateState.value) - console.log('Remote version is', remoteVersion) - console.log('Local version is', await getVersion()) - console.log('Operating System is', os.value) + if (osList.includes(currentOS.value.toLowerCase())) { + const localVersion = await getVersion(); + const isUpdateAvailable = !remoteVersion.includes(localVersion); - if (downloadArtifactBool) { - installState.value = true - const builds = data.assets - const fileName = getInstaller(getExtension(), builds) - if (fileName != null) { - await getArtifact(fileName[1], fileName[0], os.value, true) - } - installState.value = false - } - }) - .catch((error) => { - console.error(failedFetch[0], error) - if (!elementIdBool) { - const errorData = document.getElementById('releaseData') - if (errorData) { - errorData.textContent = `${error.message}` - } - updateState.value = false - allowState.value = false - installState.value = false - } - }) -} + updateState.value = isUpdateAvailable; + allowState.value = isUpdateAvailable; + } else { + updateState.value = false; + allowState.value = false; + } + if (isDownloadState) { + installState.value = true; + const builds = remoteData.assets; + const fileName = getInstaller(getExtension(), builds); + result = !fileName ? await getArtifact(fileName[1], fileName[0], currentOS.value, true) : false; + installState.value = false; + } -/** - * Retrieves the installer for a specific operating system. - * - * @param {string} osExtension - The file extension of the installer. - * @param {Array} builds - The list of builds. - * @return {Array|null} An array containing the installer name and URL if found, or null if not found. - */ -function getInstaller(osExtension, builds) { - for (let i of builds) { - let blacklistedItem = false - blacklistedBuilds.forEach((item) => { - if (i.name.startsWith(item)) { - return (blacklistedItem = true) + console.log('Update available state is', updateState.value); + console.log('Remote version is', remoteVersion); + console.log('Local version is', await getVersion()); + console.log('Operating System is', currentOS.value); + return result; + } catch (error) { + console.error(failedFetch[0], error); + if (!releaseData) { + const errorData = document.getElementById('releaseData'); + if (errorData) { + errorData.textContent = `${error.message}`; } - }) - if (i.name.endsWith(osExtension) && !blacklistedItem) { - console.log(i.browser_download_url) - return [i.name, i.browser_download_url] + updateState.value = false; + allowState.value = false; + installState.value = false; } } - return null } -/** - * A function to get the extension based on the operating system. - * - * @return {string} The extension based on the operating system. - */ -function getExtension() { - if (os.value.toLowerCase() == osNames[0]) { - return macExtension - } else if (os.value.toLowerCase() == osNames[1]) { - return windowsExtension +function getInstaller(osExtension, builds) { + console.log(osExtension, builds) + for (const build of builds) { + if (blacklistPrefixes.some(prefix => build.name.startsWith(prefix))) { + continue; + } + if (osExtension.some(ext => build.name.endsWith(ext))) { + console.log(build.name, build.browser_download_url); + return [build.name, build.browser_download_url]; + } } - return null -} \ No newline at end of file + return null; +} + +function getExtension() { + return osList.find(osName => osName === currentOS.value.toLowerCase())?.endsWith('macos') + ? macExtensionList + : windowsExtensionList; +} diff --git a/apps/app/tauri.conf.json b/apps/app/tauri.conf.json index f90278ae..26021c70 100644 --- a/apps/app/tauri.conf.json +++ b/apps/app/tauri.conf.json @@ -41,7 +41,7 @@ ] }, "productName": "AstralRinth App", - "version": "0.10.3", + "version": "0.10.302", "mainBinaryName": "AstralRinth App", "identifier": "AstralRinthApp", "plugins": {