add giteeUpdatesSource

This commit is contained in:
josc146
2023-05-22 00:04:18 +08:00
parent b2960052d9
commit c98c32f2f6
4 changed files with 119 additions and 100 deletions

View File

@@ -10,15 +10,15 @@ import {
} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json';
import commonStore from '../stores/commonStore';
import {toast} from 'react-toastify';
import {t} from 'i18next';
import {ToastOptions} from 'react-toastify/dist/types';
import {Button} from '@fluentui/react-components';
import {Language, Languages, SettingsType} from '../pages/Settings';
import {ModelSourceItem} from '../pages/Models';
import {ModelConfig, ModelParameters} from '../pages/Configs';
import {IntroductionContent} from '../pages/Home';
import {AboutContent} from '../pages/About';
import { toast } from 'react-toastify';
import { t } from 'i18next';
import { ToastOptions } from 'react-toastify/dist/types';
import { Button } from '@fluentui/react-components';
import { Language, Languages, SettingsType } from '../pages/Settings';
import { ModelSourceItem } from '../pages/Models';
import { ModelConfig, ModelParameters } from '../pages/Configs';
import { IntroductionContent } from '../pages/Home';
import { AboutContent } from '../pages/About';
export type Cache = {
models: ModelSourceItem[]
@@ -35,7 +35,7 @@ export type LocalConfig = {
}
export async function refreshBuiltInModels(readCache: boolean = false) {
let cache: { models: ModelSourceItem[] } = {models: []};
let cache: { models: ModelSourceItem[] } = { models: [] };
if (readCache)
await ReadJson('cache.json').then((cacheData: Cache) => {
if (cacheData.models)
@@ -99,7 +99,7 @@ export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, f
export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) {
const manifestUrls = commonStore.modelSourceManifestList.split(/[,;\n]/);
const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
url => fetch(url, {cache: 'no-cache'}).then(r => r.json()));
url => fetch(url, { cache: 'no-cache' }).then(r => r.json()));
await Promise.allSettled(requests)
.then((data: PromiseSettledResult<Cache>[]) => {
@@ -175,7 +175,7 @@ export function isSystemLightMode() {
}
export function downloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
manifest.programFiles.forEach(({ url, path }) => {
FileExists(path).then(exists => {
if (!exists)
AddToDownloadList(path, url);
@@ -184,13 +184,13 @@ export function downloadProgramFiles() {
}
export function forceDownloadProgramFiles() {
manifest.programFiles.forEach(({url, path}) => {
manifest.programFiles.forEach(({ url, path }) => {
DownloadFile(path, url);
});
}
export function deletePythonProgramFiles() {
manifest.programFiles.forEach(({path}) => {
manifest.programFiles.forEach(({ path }) => {
if (path.endsWith('.py') && !path.includes('get-pip.py'))
DeleteFile(path);
});
@@ -210,43 +210,48 @@ export function bytesToKb(size: number) {
export async function checkUpdate(notifyEvenLatest: boolean = false) {
let updateUrl = '';
await fetch('https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest').then((r) => {
if (r.ok) {
r.json().then((data) => {
if (data.tag_name) {
const versionTag = data.tag_name;
if (versionTag.replace('v', '') > manifest.version) {
updateUrl = `https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`;
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
deletePythonProgramFiles();
setTimeout(() => {
UpdateApp(updateUrl).catch((e) => {
toast(t('Update Error, Please restart this program') + ' - ' + e.message || e, {
type: 'error',
position: 'bottom-left',
autoClose: false
});
await fetch(!commonStore.settings.giteeUpdatesSource ?
'https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest' :
'https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/latest'
).then((r) => {
if (r.ok) {
r.json().then((data) => {
if (data.tag_name) {
const versionTag = data.tag_name;
if (versionTag.replace('v', '') > manifest.version) {
updateUrl = !commonStore.settings.giteeUpdatesSource ?
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe` :
`https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`;
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
deletePythonProgramFiles();
setTimeout(() => {
UpdateApp(updateUrl).catch((e) => {
toast(t('Update Error, Please restart this program') + ' - ' + e.message || e, {
type: 'error',
position: 'bottom-left',
autoClose: false
});
}, 500);
}, {
autoClose: false,
position: 'bottom-left'
});
} else {
if (notifyEvenLatest) {
toast(t('This is the latest version'), {type: 'success', position: 'bottom-left', autoClose: 2000});
}
}
});
}, 500);
}, {
autoClose: false,
position: 'bottom-left'
});
} else {
throw new Error('Invalid response.');
if (notifyEvenLatest) {
toast(t('This is the latest version'), { type: 'success', position: 'bottom-left', autoClose: 2000 });
}
}
});
} else {
throw new Error('Network response was not ok.');
}
} else {
throw new Error('Invalid response.');
}
});
} else {
throw new Error('Network response was not ok.');
}
}
).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;
}