updates check
This commit is contained in:
		
							parent
							
								
									af20324042
								
							
						
					
					
						commit
						c5b3246154
					
				| @ -43,6 +43,7 @@ | |||||||
|   "Open Folder": "打开文件夹", |   "Open Folder": "打开文件夹", | ||||||
|   "Configs": "配置", |   "Configs": "配置", | ||||||
|   "Automatic Updates Check": "自动检查更新", |   "Automatic Updates Check": "自动检查更新", | ||||||
|  |   "Updates Check Error": "检查更新失败", | ||||||
|   "Introduction": "介绍", |   "Introduction": "介绍", | ||||||
|   "Dark Mode": "深色模式", |   "Dark Mode": "深色模式", | ||||||
|   "Language": "语言", |   "Language": "语言", | ||||||
|  | |||||||
| @ -4,9 +4,8 @@ import {Dropdown, Option, Switch} from '@fluentui/react-components'; | |||||||
| import {Labeled} from '../components/Labeled'; | import {Labeled} from '../components/Labeled'; | ||||||
| import commonStore from '../stores/commonStore'; | import commonStore from '../stores/commonStore'; | ||||||
| import {observer} from 'mobx-react-lite'; | import {observer} from 'mobx-react-lite'; | ||||||
| import {UpdateApp} from '../../wailsjs/go/backend_golang/App'; |  | ||||||
| import {useTranslation} from 'react-i18next'; | import {useTranslation} from 'react-i18next'; | ||||||
| import {Language, Languages} from '../utils'; | import {checkUpdate, Language, Languages} from '../utils'; | ||||||
| 
 | 
 | ||||||
| export const Settings: FC = observer(() => { | export const Settings: FC = observer(() => { | ||||||
|   const {t, i18n} = useTranslation(); |   const {t, i18n} = useTranslation(); | ||||||
| @ -48,7 +47,7 @@ export const Settings: FC = observer(() => { | |||||||
|                       autoUpdatesCheck: data.checked |                       autoUpdatesCheck: data.checked | ||||||
|                     }); |                     }); | ||||||
|                     if (data.checked) |                     if (data.checked) | ||||||
|                       UpdateApp('http://localhost:34115/dist/RWKV-Runner.exe'); //TODO
 |                       checkUpdate(); | ||||||
|                   }}/> |                   }}/> | ||||||
|         }/> |         }/> | ||||||
|       </div> |       </div> | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| import commonStore, {defaultModelConfigs} from './stores/commonStore'; | import commonStore, {defaultModelConfigs} from './stores/commonStore'; | ||||||
| import {ReadJson} from '../wailsjs/go/backend_golang/App'; | import {ReadJson} from '../wailsjs/go/backend_golang/App'; | ||||||
| import {downloadProgramFiles, LocalConfig, refreshModels} from './utils'; | import {checkUpdate, downloadProgramFiles, LocalConfig, refreshModels} from './utils'; | ||||||
| import {getStatus} from './apis'; | import {getStatus} from './apis'; | ||||||
| 
 | 
 | ||||||
| export async function startup() { | export async function startup() { | ||||||
| @ -10,6 +10,9 @@ export async function startup() { | |||||||
|   initCache(); |   initCache(); | ||||||
|   await initConfig(); |   await initConfig(); | ||||||
| 
 | 
 | ||||||
|  |   if (commonStore.settings.autoUpdatesCheck) | ||||||
|  |     checkUpdate(); | ||||||
|  | 
 | ||||||
|   getStatus(500).then(status => { |   getStatus(500).then(status => { | ||||||
|     if (status) |     if (status) | ||||||
|       commonStore.setModelStatus(status); |       commonStore.setModelStatus(status); | ||||||
|  | |||||||
| @ -1,6 +1,8 @@ | |||||||
| import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App'; | import {DownloadFile, FileExists, ListDirFiles, ReadJson, SaveJson} from '../../wailsjs/go/backend_golang/App'; | ||||||
| import manifest from '../../../manifest.json'; | import manifest from '../../../manifest.json'; | ||||||
| import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore'; | import commonStore, {ModelConfig, ModelParameters, ModelSourceItem} from '../stores/commonStore'; | ||||||
|  | import {toast} from 'react-toastify'; | ||||||
|  | import {t} from 'i18next'; | ||||||
| 
 | 
 | ||||||
| export const Languages = { | export const Languages = { | ||||||
|   dev: 'English', // i18n default
 |   dev: 'English', // i18n default
 | ||||||
| @ -176,3 +178,26 @@ export function forceDownloadProgramFiles() { | |||||||
|     DownloadFile(path, url); |     DownloadFile(path, url); | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export async function checkUpdate() { | ||||||
|  |   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`; | ||||||
|  |           } else { | ||||||
|  |             throw new Error('Invalid response.'); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } else { | ||||||
|  |         throw new Error('Network response was not ok.'); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   ).catch((e) => { | ||||||
|  |     toast(t('Updates Check Error') + ' - ' + e.message, {type: 'error', position: 'bottom-left'}); | ||||||
|  |   }); | ||||||
|  |   return updateUrl; | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user