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,96 +1,97 @@
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`,
`dirty-dev`, `dirty-dev`,
`dirty-nightly`, `dirty-nightly`,
`dirty_dev`, `dirty_dev`,
`dirty_nightly`, `dirty_nightly`,
] // 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 result = false; var releaseTitle = null;
try { var result = false;
const response = await fetch(releaseLink); try {
if (!response.ok) { const response = await fetch(api);
throw new Error(response.status); if (!response.ok) {
} throw new Error(response.status);
const remoteData = await response.json(); }
currentOS.value = await getOS(); const remoteData = await response.json();
const remoteLatestReleaseTag = remoteData.tag_name; releaseTag = document.getElementById('releaseTag');
releaseData = document.getElementById('releaseData'); releaseTitle = document.getElementById('releaseTitle');
const remoteVersion = releaseData ? (releaseData.textContent = remoteLatestReleaseTag) : remoteLatestReleaseTag; if (releaseTag && releaseTitle) {
releaseTag.textContent = remoteData.tag_name;
if (osList.includes(currentOS.value.toLowerCase())) { releaseTitle.textContent = remoteData.name;
const localVersion = await getVersion(); }
const isUpdateAvailable = !remoteVersion.includes(localVersion); if (systems.includes(currentOS.toLowerCase())) {
const localVersion = await getVersion();
updateState.value = isUpdateAvailable; const isUpdateAvailable = !remoteData.tag_name.includes(localVersion);
allowState.value = isUpdateAvailable; updateState.value = isUpdateAvailable;
} else { allowState.value = isUpdateAvailable;
updateState.value = false; } else {
allowState.value = false; updateState.value = false;
} allowState.value = false;
if (isDownloadState) { }
installState.value = true; if (isDownloadState) {
const builds = remoteData.assets; try {
const fileName = getInstaller(getExtension(), builds); installState.value = true;
result = fileName ? await initUpdateLauncher(fileName[1], fileName[0], currentOS.value, true) : false; const builds = remoteData.assets;
installState.value = false; const fileName = getInstaller(getExtension(), builds);
} result = fileName ? await initUpdateLauncher(fileName[1], fileName[0], currentOS, true) : false;
installState.value = false;
console.log('Update available state is', updateState.value); } catch (err) {
console.log('Remote version is', remoteVersion); installState.value = false;
console.log('Local version is', await getVersion()); }
console.log('Operating System is', currentOS.value); }
return result; console.log('Update available state is', updateState.value);
} catch (error) { console.log('Remote version is', remoteData.tag_name);
console.error(failedFetch[0], error); console.log('Remote title is', remoteData.name);
if (!releaseData) { console.log('Local version is', await getVersion());
const errorData = document.getElementById('releaseData'); console.log('Operating System is', currentOS);
if (errorData) { return result;
errorData.textContent = `${error.message}`; } catch (error) {
} console.error("Failed to fetch remote releases:", error);
updateState.value = false; if (!releaseTag) {
allowState.value = false; updateState.value = false;
installState.value = false; allowState.value = false;
} installState.value = false;
} }
}
} }
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))) {
console.log(build.name, build.browser_download_url); console.log(build.name, build.browser_download_url);
return [build.name, build.browser_download_url]; return [build.name, build.browser_download_url];
} }
} }
return null; return null;
} }
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;
} }