11use tauri:: AppHandle ;
22use tauri_plugin_updater:: UpdaterExt ;
3- use std:: time:: Duration ;
43
54#[ tauri:: command]
65pub async fn check_for_updates ( app_handle : AppHandle ) -> Result < bool , String > {
76 match app_handle. updater ( ) {
87 Ok ( updater) => {
98 match updater. check ( ) . await {
109 Ok ( Some ( update) ) => {
11- println ! ( "✅ Update available from GitHub : {}" , update. version) ;
10+ println ! ( "[UPDATE] Available : {}" , update. version) ;
1211 Ok ( true )
1312 }
1413 Ok ( None ) => {
15- println ! ( "📦 No update available from GitHub " ) ;
14+ println ! ( "[UPDATE] No update available" ) ;
1615 Ok ( false )
1716 }
1817 Err ( e) => {
19- eprintln ! ( "❌ Failed to check GitHub for updates: {}" , e) ;
20- // If signature verification fails, provide helpful error
21- if e. to_string ( ) . contains ( "signature" ) || e. to_string ( ) . contains ( "public key" ) {
22- return Err ( "Signature verification failed. For development, you can disable signing in tauri.conf.json" . to_string ( ) ) ;
23- }
18+ eprintln ! ( "[UPDATE ERROR] Check failed: {}" , e) ;
2419 Err ( e. to_string ( ) )
2520 }
2621 }
2722 }
2823 Err ( e) => {
29- eprintln ! ( "⚠️ Updater not configured: {}" , e) ;
30- Err ( format ! ( "Updater not available: {} (Check tauri.conf.json configuration) " , e) )
24+ eprintln ! ( "[UPDATE ERROR] Updater not configured: {}" , e) ;
25+ Err ( format ! ( "Updater not available: {}" , e) )
3126 }
3227 }
3328}
@@ -38,79 +33,32 @@ pub async fn install_update(app_handle: AppHandle) -> Result<(), String> {
3833 Ok ( updater) => {
3934 match updater. check ( ) . await {
4035 Ok ( Some ( update) ) => {
41- println ! ( "Installing update : {}" , update. version) ;
36+ println ! ( "[UPDATE] Installing : {}" , update. version) ;
4237
43- // Download the update
44- let mut downloaded = 0 ;
4538 let bytes = update
4639 . download (
4740 |chunk_length, content_length| {
48- downloaded += chunk_length;
49- println ! ( "downloaded {downloaded} from {content_length:?}" ) ;
41+ println ! ( "[DOWNLOAD] {} / {:?}" , chunk_length, content_length) ;
5042 } ,
5143 || {
52- println ! ( "download finished " ) ;
44+ println ! ( "[DOWNLOAD] Finished " ) ;
5345 } ,
5446 )
5547 . await
5648 . map_err ( |e| e. to_string ( ) ) ?;
5749
58- println ! ( "Update downloaded successfully" ) ;
59-
60- // Install the update
6150 update. install ( & bytes) . map_err ( |e| e. to_string ( ) ) ?;
62-
63- // Restart the application
64- app_handle. restart ( ) ;
65- }
66- Ok ( None ) => {
67- Err ( "No update available to install" . to_string ( ) )
68- }
69- Err ( e) => {
70- eprintln ! ( "Failed to check for updates: {}" , e) ;
71- Err ( e. to_string ( ) )
51+ app_handle. restart ( )
7252 }
53+ Ok ( None ) => Err ( "No update available" . to_string ( ) ) ,
54+ Err ( e) => Err ( e. to_string ( ) ) ,
7355 }
7456 }
75- Err ( e) => {
76- eprintln ! ( "Updater not available: {}" , e) ;
77- Err ( format ! ( "Updater not available: {}" , e) )
78- }
57+ Err ( e) => Err ( format ! ( "Updater not available: {}" , e) ) ,
7958 }
8059}
8160
8261#[ tauri:: command]
83- pub async fn get_current_version ( ) -> String {
62+ pub fn get_current_version ( ) -> String {
8463 env ! ( "CARGO_PKG_VERSION" ) . to_string ( )
8564}
86-
87- pub fn start_background_update_checker ( app_handle : AppHandle ) {
88- let handle = app_handle. clone ( ) ;
89- tokio:: spawn ( async move {
90- let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 3600 ) ) ; // Check every hour
91-
92- loop {
93- interval. tick ( ) . await ;
94-
95- // Check for updates silently from GitHub releases
96- if let Ok ( update_available) = check_for_updates ( handle. clone ( ) ) . await {
97- if update_available {
98- println ! ( "Silent update check: GitHub release update available, installing automatically..." ) ;
99-
100- // Wait a bit to avoid potential conflicts
101- tokio:: time:: sleep ( Duration :: from_secs ( 30 ) ) . await ;
102-
103- // Install update silently
104- match install_update ( handle. clone ( ) ) . await {
105- Ok ( _) => {
106- println ! ( "Silent update from GitHub completed successfully" ) ;
107- }
108- Err ( e) => {
109- eprintln ! ( "Failed to install silent update from GitHub: {}" , e) ;
110- }
111- }
112- }
113- }
114- }
115- } ) ;
116- }
0 commit comments