@@ -28,6 +28,7 @@ import {
2828 PanelGroup ,
2929 PanelResizeHandle ,
3030} from "react-resizable-panels" ;
31+ import { check } from "@tauri-apps/plugin-updater" ;
3132
3233// NOTE: keep Num converter here, do not lazy load. there's a rare crashing bug.
3334import Nums from "./Features/number-tools/Nums" ;
@@ -36,6 +37,8 @@ import { Settings } from "./Layout/Settings";
3637import { useDisclosure , useWindowEvent } from "@mantine/hooks" ;
3738import { trackOtherEvent , trackPageView } from "./utils/analytics" ;
3839import { db } from "./utils" ;
40+ import { ask , message } from "@tauri-apps/plugin-dialog" ;
41+ import { relaunch } from "@tauri-apps/plugin-process" ;
3942
4043// Lazy load components
4144const Welcome = loadable ( ( ) => import ( "./Components/Welcome" ) ) ;
@@ -154,6 +157,30 @@ function App() {
154157
155158 useEffect ( ( ) => {
156159 async function init ( ) {
160+ const update = await check ( ) ;
161+ if ( update === null ) {
162+ await message ( "Failed to check for updates.\nPlease try again later." , {
163+ title : "Error" ,
164+ kind : "error" ,
165+ okLabel : "OK" ,
166+ } ) ;
167+ return ;
168+ } else if ( update ?. available ) {
169+ const yes = await ask (
170+ `Update to ${ update . version } is available!\n\nRelease notes: ${ update . body } ` ,
171+ {
172+ title : "Update Available" ,
173+ kind : "info" ,
174+ okLabel : "Update" ,
175+ cancelLabel : "Cancel" ,
176+ }
177+ ) ;
178+ if ( yes ) {
179+ await update . downloadAndInstall ( ) ;
180+ await relaunch ( ) ;
181+ }
182+ }
183+
157184 const isFirstTime = await db . get ( "firstTime" ) ;
158185 if ( isFirstTime === true ) {
159186 tour . start ( ) ;
0 commit comments