This commit is contained in:
41
client/app/middleware/00.updater.global.ts
Normal file
41
client/app/middleware/00.updater.global.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { relaunch } from '@tauri-apps/plugin-process'
|
||||
import { check } from '@tauri-apps/plugin-updater'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
if (from?.name)
|
||||
return
|
||||
|
||||
const update = await check()
|
||||
|
||||
console.log(update)
|
||||
|
||||
if (import.meta.dev)
|
||||
return
|
||||
|
||||
if (update) {
|
||||
console.log(
|
||||
`found update ${update.version} from ${update.date} with notes ${update.body}`,
|
||||
)
|
||||
let downloaded = 0
|
||||
let contentLength = 0
|
||||
// alternatively we could also call update.download() and update.install() separately
|
||||
await update.downloadAndInstall((event) => {
|
||||
switch (event.event) {
|
||||
case 'Started':
|
||||
contentLength = event.data.contentLength ?? 0
|
||||
console.log(`started downloading ${event.data.contentLength} bytes`)
|
||||
break
|
||||
case 'Progress':
|
||||
downloaded += event.data.chunkLength
|
||||
console.log(`downloaded ${downloaded} from ${contentLength}`)
|
||||
break
|
||||
case 'Finished':
|
||||
console.log('download finished')
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
console.log('update installed')
|
||||
await relaunch()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user