fix: missing check for update

This commit is contained in:
reya
2024-11-03 13:50:31 +07:00
parent cd6ba5884f
commit 85fa1e2359
9 changed files with 50 additions and 87 deletions
+38 -11
View File
@@ -1,14 +1,41 @@
import { commands } from '@/commands.gen'
import { createFileRoute, redirect } from '@tanstack/react-router'
import { commands } from "@/commands.gen";
import { createFileRoute, redirect } from "@tanstack/react-router";
import { ask } from "@tauri-apps/plugin-dialog";
import { relaunch } from "@tauri-apps/plugin-process";
import { check } from "@tauri-apps/plugin-updater";
export const Route = createFileRoute('/_app')({
beforeLoad: async () => {
const accounts = await commands.getAccounts()
async function checkForAppUpdates() {
const update = await check();
if (!accounts.length) {
throw redirect({ to: '/new', replace: true })
}
if (update?.available) {
const yes = await ask(
`Update to ${update.version} is available!\n\nRelease notes: ${update.body}`,
{
title: "Update Available",
kind: "info",
okLabel: "Update",
cancelLabel: "Cancel",
},
);
return { accounts }
},
})
if (yes) {
await update.downloadAndInstall();
await relaunch();
}
return;
}
}
export const Route = createFileRoute("/_app")({
beforeLoad: async () => {
await checkForAppUpdates();
const accounts = await commands.getAccounts();
if (!accounts.length) {
throw redirect({ to: "/new", replace: true });
}
return { accounts };
},
});