1
0

refactor: minor changes in update.js

This commit is contained in:
2025-10-19 21:06:03 +03:00
parent 8e720ccef5
commit 4b86c4ee8a
2 changed files with 105 additions and 91 deletions

View File

@@ -211,28 +211,34 @@ const messages = defineMessages({
<ModalWrapper ref="updateModalView" :has-to-type="false" header="Request to update the AstralRinth launcher"> <ModalWrapper ref="updateModalView" :has-to-type="false" header="Request to update the AstralRinth launcher">
<div class="space-y-4"> <div class="space-y-4">
<div class="space-y-2"> <div class="space-y-2">
<p>The new version of the AstralRinth launcher is available.</p> <strong>The new version of the AstralRinth launcher is available!</strong>
<p>Your version is outdated. We recommend that you update to the latest version.</p> <p>Your version is outdated. We recommend that you update to the latest version.</p>
<p><strong> Warning </strong></p> <br/>
<br/>
<p><strong> Please, read this notice before initialize update process</strong></p>
<p> <p>
Before updating, make sure that you have saved all running instances and made a backup copy of the instances Before updating, make sure that you have saved and closed all running instances and made a backup copy of the launcher data such as
that are valuable to you. Remember that the authors of the product are not responsible for the breakdown of <code>%appdata%\Roaming\AstralRinthApp</code> on Windows or <code>~/Library/Application Support/AstralRinthApp</code> on macOS.
your files, so you should always make copies of them and keep them in a safe place. Remember that the authors of the product are not responsible for the breakdown of
your files, so you should always make back up copies of them and keep them in a safe place.
</p> </p>
</div> </div>
<div class="text-sm text-secondary space-y-1"> <div class="text-sm text-secondary space-y-1">
<a class="neon-text" href="https://me.astralium.su/get/ar" target="_blank"
rel="noopener noreferrer"><strong>Source:</strong> Git Astralium</a>
<p> <p>
<strong>Version on remote server:</strong> <strong> Latest release tag:</strong>
<span id="releaseData" class="neon-text"></span> <span id="releaseTag" class="neon-text"></span>
</p> <br/>
<p> <strong> Latest release title:</strong>
<strong>Version on local device:</strong> <span id="releaseTitle" class="neon-text"></span>
<br/>
<strong>💾 Installed & Running version:</strong>
<span class="neon-text">v{{ version }}</span> <span class="neon-text">v{{ version }}</span>
</p> </p>
</div> </div>
<a class="neon-text" href="https://me.astralium.su/get/ar" target="_blank"
rel="noopener noreferrer">
Checkout our git repository
</a>
<div class="absolute bottom-4 right-4 flex items-center gap-4 neon-button neon"> <div class="absolute bottom-4 right-4 flex items-center gap-4 neon-button neon">
<Button class="bordered" @click="updateModalView.hide()">Cancel</Button> <Button class="bordered" @click="updateModalView.hide()">Cancel</Button>
<Button class="bordered" @click="initDownload()">Download file</Button> <Button class="bordered" @click="initDownload()">Download file</Button>
@@ -271,4 +277,11 @@ const messages = defineMessages({
@import '../../../../../../packages/assets/styles/neon-icon.scss'; @import '../../../../../../packages/assets/styles/neon-icon.scss';
@import '../../../../../../packages/assets/styles/neon-button.scss'; @import '../../../../../../packages/assets/styles/neon-button.scss';
@import '../../../../../../packages/assets/styles/neon-text.scss'; @import '../../../../../../packages/assets/styles/neon-text.scss';
code {
background: linear-gradient(90deg, #005eff, #00cfff);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
</style> </style>

View File

@@ -1,20 +1,20 @@
import { ref } from 'vue'
import { getVersion } from '@tauri-apps/api/app' import { getVersion } from '@tauri-apps/api/app'
import { initUpdateLauncher, getOS } from '@/helpers/utils.js' import { ref } from 'vue'
import { getOS, initUpdateLauncher } from '@/helpers/utils.js'
export const allowState = ref(false) export const allowState = ref(false)
export const installState = ref(false) export const installState = ref(false)
export const updateState = ref(false) export const updateState = ref(false)
const currentOS = ref('') const currentOS = await getOS()
const releaseLink = `https://git.astralium.su/api/v1/repos/didirus/AstralRinth/releases/latest` const api = `https://git.astralium.su/api/v1/repos/didirus/AstralRinth/releases/latest`
const failedFetch = [`Failed to fetch remote releases:`, `Failed to fetch remote commits:`]
const osList = ['macos', 'windows', 'linux'] const systems = ['macos', 'windows', 'linux']
const macExtensionList = ['.dmg', '.pkg'] const macosExtensions = ['.dmg', '.pkg', '.app']
const windowsExtensionList = ['.exe', '.msi'] const windowsExtensions = ['.exe', '.msi']
const blacklistPrefixes = [ const blacklistBeginPrefixes = [
`dev`, `dev`,
`nightly`, `nightly`,
`dirty`, `dirty`,
@@ -25,23 +25,24 @@ const blacklistPrefixes = [
] // This is blacklisted builds for download. For example, file.startsWith('dev') is not allowed. ] // This is blacklisted builds for download. For example, file.startsWith('dev') is not allowed.
export async function getRemote(isDownloadState) { export async function getRemote(isDownloadState) {
var releaseData = null; var releaseTag = null;
var releaseTitle = null;
var result = false; var result = false;
try { try {
const response = await fetch(releaseLink); const response = await fetch(api);
if (!response.ok) { if (!response.ok) {
throw new Error(response.status); throw new Error(response.status);
} }
const remoteData = await response.json(); const remoteData = await response.json();
currentOS.value = await getOS(); releaseTag = document.getElementById('releaseTag');
const remoteLatestReleaseTag = remoteData.tag_name; releaseTitle = document.getElementById('releaseTitle');
releaseData = document.getElementById('releaseData'); if (releaseTag && releaseTitle) {
const remoteVersion = releaseData ? (releaseData.textContent = remoteLatestReleaseTag) : remoteLatestReleaseTag; releaseTag.textContent = remoteData.tag_name;
releaseTitle.textContent = remoteData.name;
if (osList.includes(currentOS.value.toLowerCase())) { }
if (systems.includes(currentOS.toLowerCase())) {
const localVersion = await getVersion(); const localVersion = await getVersion();
const isUpdateAvailable = !remoteVersion.includes(localVersion); const isUpdateAvailable = !remoteData.tag_name.includes(localVersion);
updateState.value = isUpdateAvailable; updateState.value = isUpdateAvailable;
allowState.value = isUpdateAvailable; allowState.value = isUpdateAvailable;
} else { } else {
@@ -49,25 +50,25 @@ export async function getRemote(isDownloadState) {
allowState.value = false; allowState.value = false;
} }
if (isDownloadState) { if (isDownloadState) {
try {
installState.value = true; installState.value = true;
const builds = remoteData.assets; const builds = remoteData.assets;
const fileName = getInstaller(getExtension(), builds); const fileName = getInstaller(getExtension(), builds);
result = fileName ? await initUpdateLauncher(fileName[1], fileName[0], currentOS.value, true) : false; result = fileName ? await initUpdateLauncher(fileName[1], fileName[0], currentOS, true) : false;
installState.value = false;
} catch (err) {
installState.value = false; installState.value = false;
} }
}
console.log('Update available state is', updateState.value); console.log('Update available state is', updateState.value);
console.log('Remote version is', remoteVersion); console.log('Remote version is', remoteData.tag_name);
console.log('Remote title is', remoteData.name);
console.log('Local version is', await getVersion()); console.log('Local version is', await getVersion());
console.log('Operating System is', currentOS.value); console.log('Operating System is', currentOS);
return result; return result;
} catch (error) { } catch (error) {
console.error(failedFetch[0], error); console.error("Failed to fetch remote releases:", error);
if (!releaseData) { if (!releaseTag) {
const errorData = document.getElementById('releaseData');
if (errorData) {
errorData.textContent = `${error.message}`;
}
updateState.value = false; updateState.value = false;
allowState.value = false; allowState.value = false;
installState.value = false; installState.value = false;
@@ -78,7 +79,7 @@ export async function getRemote(isDownloadState) {
function getInstaller(osExtension, builds) { function getInstaller(osExtension, builds) {
console.log(osExtension, builds) console.log(osExtension, builds)
for (const build of builds) { for (const build of builds) {
if (blacklistPrefixes.some(prefix => build.name.startsWith(prefix))) { if (blacklistBeginPrefixes.some(prefix => build.name.startsWith(prefix))) {
continue; continue;
} }
if (osExtension.some(ext => build.name.endsWith(ext))) { if (osExtension.some(ext => build.name.endsWith(ext))) {
@@ -90,7 +91,7 @@ function getInstaller(osExtension, builds) {
} }
function getExtension() { function getExtension() {
return osList.find(osName => osName === currentOS.value.toLowerCase())?.endsWith('macos') return systems.find(osName => osName === currentOS.toLowerCase())?.endsWith('macos')
? macExtensionList ? macosExtensions
: windowsExtensionList; : windowsExtensions;
} }