@@ -18,6 +18,8 @@ use owmods_core::{
1818 progress:: bars:: ProgressBars ,
1919 protocol:: ProtocolPayload ,
2020} ;
21+ use tauri:: AppHandle ;
22+ use tauri_plugin_updater:: UpdaterExt ;
2123
2224use anyhow:: anyhow;
2325use time:: macros:: format_description;
@@ -93,6 +95,39 @@ pub struct State {
9395 mods_in_progress : StatePart < Vec < String > > ,
9496}
9597
98+ async fn update ( app : AppHandle ) -> tauri_plugin_updater:: Result < ( ) > {
99+ log:: debug!( "Checking for Manager Updates" ) ;
100+ if let Some ( update) = app. updater ( ) ?. check ( ) . await ? {
101+ let mut bytes: usize = 0 ;
102+ let mut last_debounce: usize = 0 ;
103+ log:: info!( "Manager Update Found! (${})" , update. version) ;
104+ update
105+ . download_and_install (
106+ |recv, tot| {
107+ bytes = bytes. saturating_add ( recv) ;
108+ let debounce = bytes / 1000000 ;
109+ if last_debounce != debounce {
110+ last_debounce = debounce;
111+ log:: debug!(
112+ "Download Update ({}/{})" ,
113+ bytes / 1000 ,
114+ tot. unwrap_or( u64 :: MAX ) / 1000
115+ ) ;
116+ }
117+ } ,
118+ || {
119+ log:: debug!( "Download complete! Installing" ) ;
120+ } ,
121+ )
122+ . await ?;
123+ log:: info!( "Manager Update Complete" ) ;
124+ Ok ( ( ) )
125+ } else {
126+ log:: debug!( "No Manager Updates" ) ;
127+ Ok ( ( ) )
128+ }
129+ }
130+
96131fn main ( ) -> Result < ( ) , Box < dyn Error > > {
97132 let config = Config :: get ( None ) . unwrap_or ( Config :: default ( None ) ?) ;
98133 let gui_config = GuiConfig :: get ( ) . unwrap_or_default ( ) ;
@@ -144,6 +179,18 @@ fn main() -> Result<(), Box<dyn Error>> {
144179 debug ! ( "Setup window state" ) ;
145180 }
146181
182+ // Update Setup
183+ let update_handle = app. handle ( ) . clone ( ) ;
184+
185+ tauri:: async_runtime:: spawn ( async {
186+ update_handle
187+ . plugin ( tauri_plugin_updater:: Builder :: new ( ) . build ( ) )
188+ . unwrap ( ) ;
189+ if let Err ( why) = update ( update_handle) . await {
190+ warn ! ( "Failed to update: {why:?}" ) ;
191+ }
192+ } ) ;
193+
147194 // Protocol Listener Setup
148195
149196 protocol:: prep_protocol ( app. handle ( ) . clone ( ) ) ;
0 commit comments