improve checkUpdate
This commit is contained in:
parent
deb9e030cb
commit
154827f367
@ -214,8 +214,7 @@ export function bytesToKb(size: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
||||||
let updateUrl = '';
|
fetch(!commonStore.settings.giteeUpdatesSource ?
|
||||||
await fetch(!commonStore.settings.giteeUpdatesSource ?
|
|
||||||
'https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest' :
|
'https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest' :
|
||||||
'https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/latest'
|
'https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/latest'
|
||||||
).then((r) => {
|
).then((r) => {
|
||||||
@ -224,9 +223,19 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
|||||||
if (data.tag_name) {
|
if (data.tag_name) {
|
||||||
const versionTag = data.tag_name;
|
const versionTag = data.tag_name;
|
||||||
if (versionTag.replace('v', '') > manifest.version) {
|
if (versionTag.replace('v', '') > manifest.version) {
|
||||||
updateUrl = !commonStore.settings.giteeUpdatesSource ?
|
const verifyUrl = !commonStore.settings.giteeUpdatesSource ?
|
||||||
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe` :
|
`https://api.github.com/repos/josstorer/RWKV-Runner/releases/tags/${versionTag}` :
|
||||||
`https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`;
|
`https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/tags/${versionTag}`;
|
||||||
|
|
||||||
|
fetch(verifyUrl).then((r) => {
|
||||||
|
if (r.ok) {
|
||||||
|
r.json().then((data) => {
|
||||||
|
if (data.assets && data.assets.length > 0) {
|
||||||
|
const asset = data.assets.find((a: any) => a.name.toLowerCase().includes(commonStore.platform.toLowerCase()));
|
||||||
|
if (asset) {
|
||||||
|
const updateUrl = !commonStore.settings.giteeUpdatesSource ?
|
||||||
|
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/${asset.name}` :
|
||||||
|
`https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/${asset.name}`;
|
||||||
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
|
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
|
||||||
DeleteFile('cache.json');
|
DeleteFile('cache.json');
|
||||||
toast(t('Downloading update, please wait. If it is not completed, please manually download the program from GitHub and replace the original program.'), {
|
toast(t('Downloading update, please wait. If it is not completed, please manually download the program from GitHub and replace the original program.'), {
|
||||||
@ -247,6 +256,13 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
|||||||
autoClose: false,
|
autoClose: false,
|
||||||
position: 'bottom-left'
|
position: 'bottom-left'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error('Verify response was not ok.');
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (notifyEvenLatest) {
|
if (notifyEvenLatest) {
|
||||||
toast(t('This is the latest version'), { type: 'success', position: 'bottom-left', autoClose: 2000 });
|
toast(t('This is the latest version'), { type: 'success', position: 'bottom-left', autoClose: 2000 });
|
||||||
@ -263,7 +279,6 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
|||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
toast(t('Updates Check Error') + ' - ' + e.message || e, { type: 'error', position: 'bottom-left' });
|
toast(t('Updates Check Error') + ' - ' + e.message || e, { type: 'error', position: 'bottom-left' });
|
||||||
});
|
});
|
||||||
return updateUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toastWithButton(text: string, buttonText: string, onClickButton: () => void, options?: ToastOptions) {
|
export function toastWithButton(text: string, buttonText: string, onClickButton: () => void, options?: ToastOptions) {
|
||||||
|
Loading…
Reference in New Issue
Block a user