feat: add updater
This commit is contained in:
@@ -97,7 +97,7 @@
|
||||
},
|
||||
"updater": {
|
||||
"active": true,
|
||||
"endpoints": ["https://sv.risuai.xyz/hub/update"],
|
||||
"endpoints": ["https://github.com/kwaroran/RisuAI/releases/latest/download/latest.json"],
|
||||
"dialog": false,
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDU2ODMzOTIxMDMxOTY1MUYKUldRZlpSa0RJVG1EVmx5Vm1WYlhFM29HMEJrUTRrYmg5dDQ0RFpvdUphNDdxQmVlWXJHVmV5TEYK",
|
||||
"windows": {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { get } from "svelte/store";
|
||||
import {open} from '@tauri-apps/api/shell'
|
||||
import { DataBase, loadedStore, setDatabase, type Database, defaultSdDataFunc } from "./database";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import { checkUpdate } from "../update";
|
||||
import { checkRisuUpdate } from "../update";
|
||||
import { botMakerMode, selectedCharID } from "../stores";
|
||||
import { Body, ResponseType, fetch as TauriFetch } from "@tauri-apps/api/http";
|
||||
import { loadPlugins } from "../plugins/plugins";
|
||||
@@ -419,7 +419,7 @@ export async function loadData() {
|
||||
throw "Your save file is corrupted"
|
||||
}
|
||||
}
|
||||
await checkUpdate()
|
||||
await checkRisuUpdate()
|
||||
await changeFullscreen()
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +1,30 @@
|
||||
import { fetch } from "@tauri-apps/api/http";
|
||||
import { DataBase, appVer, setDatabase } from "./storage/database";
|
||||
import { alertConfirm, alertError, alertMd } from "./alert";
|
||||
import { alertConfirm, alertWait } from "./alert";
|
||||
import { language } from "../lang";
|
||||
import { get } from "svelte/store";
|
||||
import {open} from '@tauri-apps/api/shell'
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
import {
|
||||
checkUpdate,
|
||||
installUpdate,
|
||||
} from '@tauri-apps/api/updater'
|
||||
import { relaunch } from '@tauri-apps/api/process'
|
||||
|
||||
export async function checkRisuUpdate(){
|
||||
|
||||
if(Capacitor.isNativePlatform()){
|
||||
return
|
||||
}
|
||||
|
||||
export async function checkUpdate(){
|
||||
try {
|
||||
|
||||
if(Capacitor.isNativePlatform()){
|
||||
return
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
const da = await fetch('https://raw.githubusercontent.com/kwaroran/RisuAI-release/main/version.json')
|
||||
//@ts-ignore
|
||||
const v:string = da.data.version
|
||||
if(!v){
|
||||
return
|
||||
}
|
||||
if(v === db.lastup){
|
||||
return
|
||||
}
|
||||
const nextVer = versionStringToNumber(v)
|
||||
if(isNaN(nextVer) || (!nextVer)){
|
||||
return
|
||||
}
|
||||
const appVerNum = versionStringToNumber(appVer)
|
||||
|
||||
if(appVerNum < nextVer){
|
||||
const checked = await checkUpdate()
|
||||
if(checked.shouldUpdate){
|
||||
const conf = await alertConfirm(language.newVersion)
|
||||
if(conf){
|
||||
open("https://risuai.net/?page=download")
|
||||
}
|
||||
else{
|
||||
db = get(DataBase)
|
||||
db.lastup = v
|
||||
setDatabase(db)
|
||||
alertWait(`Updating to ${checked.manifest.version}...`)
|
||||
await installUpdate()
|
||||
await relaunch()
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
alertError(error)
|
||||
return
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user