@@ -4,9 +4,9 @@ use std::sync::mpsc;
44use std:: thread;
55
66use velopack:: sources:: AutoSource ;
7- use velopack:: { UpdateCheck , UpdateInfo , UpdateManager as VelopackUpdateManagerRust } ;
7+ use velopack:: { UpdateCheck , UpdateInfo , UpdateManager as VelopackUpdateManagerRust , VelopackAsset } ;
88
9- use crate :: types:: * ;
9+ use crate :: { types:: * , PyUpdateInfoOrAsset } ;
1010
1111#[ pyclass( name = "UpdateManager" ) ]
1212pub struct UpdateManagerWrapper {
@@ -19,11 +19,27 @@ impl UpdateManagerWrapper {
1919 #[ pyo3( signature = ( source, options = None , locator = None ) ) ]
2020 pub fn new ( source : String , options : Option < PyUpdateOptions > , locator : Option < PyVelopackLocatorConfig > ) -> Result < Self > {
2121 let source = AutoSource :: new ( & source) ;
22- // set myinner to a new VelopackUpdateManager with the source
2322 let inner = VelopackUpdateManagerRust :: new ( source, options. map ( Into :: into) , locator. map ( Into :: into) ) ?;
2423 Ok ( UpdateManagerWrapper { inner } )
2524 }
2625
26+ pub fn get_current_version ( & self ) -> String {
27+ self . inner . get_current_version_as_string ( )
28+ }
29+
30+ pub fn get_app_id ( & self ) -> String {
31+ self . inner . get_app_id ( ) . to_string ( )
32+ }
33+
34+ pub fn get_is_portable ( & self ) -> bool {
35+ self . inner . get_is_portable ( )
36+ }
37+
38+ pub fn get_update_pending_restart ( & self ) -> Option < PyVelopackAsset > {
39+ let pending = self . inner . get_update_pending_restart ( ) ;
40+ pending. map ( Into :: into)
41+ }
42+
2743 pub fn check_for_updates ( & mut self ) -> Result < Option < PyUpdateInfo > > {
2844 let update_check = self . inner . check_for_updates ( ) ?;
2945 match update_check {
@@ -37,9 +53,9 @@ impl UpdateManagerWrapper {
3753 }
3854
3955 #[ pyo3( signature = ( update_info, progress_callback = None ) ) ]
40- pub fn download_updates ( & mut self , update_info : & PyUpdateInfo , progress_callback : Option < PyObject > ) -> Result < ( ) > {
56+ pub fn download_updates ( & mut self , update_info : PyUpdateInfo , progress_callback : Option < PyObject > ) -> Result < ( ) > {
4157 // Convert PyUpdateInfo back to rust UpdateInfo
42- let rust_update_info: UpdateInfo = update_info. clone ( ) . into ( ) ;
58+ let rust_update_info: UpdateInfo = update_info. into ( ) ;
4359
4460 if let Some ( callback) = progress_callback {
4561 // Create a channel for progress updates
@@ -71,42 +87,35 @@ impl UpdateManagerWrapper {
7187 }
7288 }
7389
74- pub fn apply_updates_and_restart ( & mut self , update_info : & PyUpdateInfo ) -> Result < ( ) > {
75- // Convert PyUpdateInfo back to rust UpdateInfo
76- let rust_update_info: UpdateInfo = update_info. clone ( ) . into ( ) ;
77- self . inner . apply_updates_and_restart ( & rust_update_info) ?;
90+ pub fn apply_updates_and_restart ( & mut self , update : PyUpdateInfoOrAsset ) -> Result < ( ) > {
91+ let asset: VelopackAsset = update. into_asset ( ) ;
92+ self . inner . apply_updates_and_restart ( & asset) ?;
7893 Ok ( ( ) )
7994 }
8095
81- pub fn apply_updates_and_restart_with_args ( & mut self , update_info : & PyUpdateInfo , restart_args : Vec < String > ) -> Result < ( ) > {
82- // Convert PyUpdateInfo back to rust UpdateInfo
83- let rust_update_info: UpdateInfo = update_info. clone ( ) . into ( ) ;
84- self . inner . apply_updates_and_restart_with_args ( & rust_update_info, restart_args) ?;
96+ pub fn apply_updates_and_restart_with_args ( & mut self , update : PyUpdateInfoOrAsset , restart_args : Vec < String > ) -> Result < ( ) > {
97+ let asset: VelopackAsset = update. into_asset ( ) ;
98+ self . inner . apply_updates_and_restart_with_args ( & asset, restart_args) ?;
8599 Ok ( ( ) )
86100 }
87101
88- pub fn apply_updates_and_exit ( & mut self , update_info : & PyUpdateInfo ) -> Result < ( ) > {
89- // Convert PyUpdateInfo back to rust UpdateInfo
90- let rust_update_info: UpdateInfo = update_info. clone ( ) . into ( ) ;
91- self . inner . apply_updates_and_exit ( & rust_update_info) ?;
102+ pub fn apply_updates_and_exit ( & mut self , update : PyUpdateInfoOrAsset ) -> Result < ( ) > {
103+ let asset: VelopackAsset = update. into_asset ( ) ;
104+ self . inner . apply_updates_and_exit ( & asset) ?;
92105 Ok ( ( ) )
93106 }
94107
95- #[ pyo3( signature = ( update_info , silent = false , restart = true , restart_args = None ) ) ]
108+ #[ pyo3( signature = ( update , silent = false , restart = true , restart_args = None ) ) ]
96109 pub fn wait_exit_then_apply_updates (
97110 & mut self ,
98- update_info : & PyUpdateInfo ,
111+ update : PyUpdateInfoOrAsset ,
99112 silent : bool ,
100113 restart : bool ,
101114 restart_args : Option < Vec < String > > ,
102115 ) -> Result < ( ) > {
103- // Convert PyUpdateInfo back to rust UpdateInfo
104- let rust_update_info: UpdateInfo = update_info. clone ( ) . into ( ) ;
105-
106- // Convert restart_args to the format expected by the Rust function
116+ let asset: VelopackAsset = update. into_asset ( ) ;
107117 let args = restart_args. unwrap_or_default ( ) ;
108-
109- self . inner . wait_exit_then_apply_updates ( & rust_update_info, silent, restart, args) ?;
118+ self . inner . wait_exit_then_apply_updates ( & asset, silent, restart, args) ?;
110119 Ok ( ( ) )
111120 }
112121}
0 commit comments