mirror of
				https://github.com/velopack/velopack.git
				synced 2025-10-25 15:19:22 +00:00 
			
		
		
		
	code formatting
This commit is contained in:
		| @@ -3,28 +3,8 @@ use std::fs; | ||||
| use std::path::Path; | ||||
|  | ||||
| fn main() { | ||||
|  | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|      | ||||
|     // Get the workspace version | ||||
|     let version = get_workspace_version().unwrap_or_else(|| { | ||||
|         env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string()) | ||||
|     }); | ||||
|     let version = get_workspace_version().unwrap_or_else(|| env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string())); | ||||
|  | ||||
|     let python_version = convert_to_python_version(&version); | ||||
|  | ||||
| @@ -65,8 +45,7 @@ fn get_workspace_version() -> Option<String> { | ||||
|         } | ||||
|  | ||||
|         if trimmed.starts_with('[') && trimmed != "[workspace.package]" { | ||||
|             if in_workspace_package { | ||||
|             } | ||||
|             if in_workspace_package {} | ||||
|             in_workspace_package = false; | ||||
|             continue; | ||||
|         } | ||||
|   | ||||
| @@ -85,8 +85,7 @@ impl VelopackAppWrapper { | ||||
|     /// Runs the Velopack startup logic | ||||
|     pub fn run(&mut self, _py: Python) -> PyResult<()> { | ||||
|         // Create the Rust VelopackApp with our stored configuration | ||||
|         let mut app = VelopackAppRust::build() | ||||
|             .set_auto_apply_on_startup(self.auto_apply); | ||||
|         let mut app = VelopackAppRust::build().set_auto_apply_on_startup(self.auto_apply); | ||||
|  | ||||
|         // Set args if provided | ||||
|         if let Some(ref args) = self.args { | ||||
| @@ -175,4 +174,3 @@ impl VelopackAppWrapper { | ||||
|         Ok(()) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| use pyo3::prelude::*; | ||||
| use pyo3::exceptions::PyException; | ||||
| use pyo3::prelude::*; | ||||
|  | ||||
| #[pyclass(name="VelopackError", extends=PyException, module="velopack.exceptions")] | ||||
| #[derive(Debug)] | ||||
| @@ -18,4 +18,3 @@ impl VelopackError { | ||||
|         self.message.clone() | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,38 +1,35 @@ | ||||
| use asset::PyUpdateInfo; | ||||
| use pyo3::prelude::*; | ||||
| use pyo3::types::PyModule; | ||||
|  | ||||
| mod asset; | ||||
| pub use asset::PyVelopackAsset; | ||||
|  | ||||
| mod types; | ||||
| use types::*; | ||||
|  | ||||
| mod exceptions; | ||||
| pub use exceptions::VelopackError; | ||||
| use exceptions::VelopackError; | ||||
|  | ||||
| mod app; | ||||
| pub use app::VelopackAppWrapper; | ||||
| use app::VelopackAppWrapper; | ||||
|  | ||||
| mod manager; | ||||
| pub use manager::UpdateManagerWrapper; | ||||
|  | ||||
| use manager::UpdateManagerWrapper; | ||||
|  | ||||
| #[pymodule] | ||||
| fn velopack(m: &Bound<'_, PyModule>) -> PyResult<()> { | ||||
|     m.add_class::<VelopackError>()?; | ||||
|  | ||||
|     // auto-generated DTO's | ||||
|     m.add_class::<PyVelopackAsset>()?; | ||||
|     m.add_class::<PyUpdateInfo>()?; | ||||
|     m.add_class::<PyUpdateOptions>()?; | ||||
|     m.add_class::<PyVelopackLocatorConfig>()?; | ||||
|  | ||||
|      | ||||
|  | ||||
|     // concrete classes | ||||
|     m.add_class::<VelopackAppWrapper>()?; | ||||
|     m.add_class::<UpdateManagerWrapper>()?; | ||||
|  | ||||
|     // add __version__ attribute | ||||
|     m.add("__version__", env!("CARGO_PKG_VERSION"))?; | ||||
|  | ||||
|      | ||||
|      | ||||
|     // add __author__ attribute | ||||
|     m.add("__author__", env!("CARGO_PKG_AUTHORS"))?; | ||||
|  | ||||
|   | ||||
| @@ -1,13 +1,12 @@ | ||||
| use pyo3::prelude::*; | ||||
| use std::sync::mpsc; | ||||
| use std::thread; | ||||
|  | ||||
| use pyo3::prelude::*; | ||||
|  | ||||
| use velopack::{UpdateCheck, UpdateInfo, UpdateManager as VelopackUpdateManagerRust}; | ||||
| use velopack::sources::AutoSource; | ||||
| use velopack::{UpdateCheck, UpdateInfo, UpdateManager as VelopackUpdateManagerRust}; | ||||
|  | ||||
| use crate::exceptions::VelopackError; | ||||
| use crate::asset::PyUpdateInfo; | ||||
| use crate::types::*; | ||||
|  | ||||
| #[pyclass(name = "UpdateManager")] | ||||
| pub struct UpdateManagerWrapper { | ||||
| @@ -17,42 +16,34 @@ pub struct UpdateManagerWrapper { | ||||
| #[pymethods] | ||||
| impl UpdateManagerWrapper { | ||||
|     // for new, just take in a string, which is the source | ||||
| #[new] | ||||
| pub fn new(source: String) -> PyResult<Self> { | ||||
|     #[new] | ||||
|     #[pyo3(signature = (source, options = None, locator = None))] | ||||
|     pub fn new(source: String, options: Option<PyUpdateOptions>, locator: Option<PyVelopackLocatorConfig>) -> PyResult<Self> { | ||||
|         let source = AutoSource::new(&source); | ||||
|         // set myinner to a new VelopackUpdateManager with the source | ||||
|     let inner = VelopackUpdateManagerRust::new(source, None, None) | ||||
|         let inner = VelopackUpdateManagerRust::new(source, options.map(Into::into), locator.map(Into::into)) | ||||
|             .map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to create UpdateManager: {}", e)))?; | ||||
|     Ok(UpdateManagerWrapper { | ||||
|         inner, | ||||
| } | ||||
|     ) | ||||
| } | ||||
|         Ok(UpdateManagerWrapper { inner }) | ||||
|     } | ||||
|  | ||||
|  | ||||
| // check_for_updates return update info indicating if updates are available | ||||
|     // check_for_updates return update info indicating if updates are available | ||||
|     /// This method checks for updates and returns update info if updates are available, None otherwise. | ||||
| pub fn check_for_updates(&mut self) -> PyResult<Option<PyUpdateInfo>> { | ||||
|     let update_check = self.inner.check_for_updates() | ||||
|         .map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to check for updates: {}", e)))?; | ||||
|     pub fn check_for_updates(&mut self) -> PyResult<Option<PyUpdateInfo>> { | ||||
|         let update_check = | ||||
|             self.inner.check_for_updates().map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to check for updates: {}", e)))?; | ||||
|  | ||||
|         match update_check { | ||||
|             UpdateCheck::UpdateAvailable(updates) => { | ||||
|                 let py_updates = PyUpdateInfo::from(updates); | ||||
|                 Ok(Some(py_updates)) | ||||
|         }, | ||||
|         UpdateCheck::NoUpdateAvailable => { | ||||
|             Ok(None) | ||||
|         }, | ||||
|         UpdateCheck::RemoteIsEmpty => { | ||||
|             Ok(None) | ||||
|             } | ||||
|             UpdateCheck::NoUpdateAvailable => Ok(None), | ||||
|             UpdateCheck::RemoteIsEmpty => Ok(None), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| #[pyo3(signature = (update_info, progress_callback = None))] | ||||
| pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback: Option<PyObject>) -> PyResult<()> { | ||||
|     #[pyo3(signature = (update_info, progress_callback = None))] | ||||
|     pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback: Option<PyObject>) -> PyResult<()> { | ||||
|         // Convert PyUpdateInfo back to rust UpdateInfo | ||||
|         let rust_update_info: UpdateInfo = update_info.clone().into(); | ||||
|  | ||||
| @@ -74,7 +65,9 @@ pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback | ||||
|             }); | ||||
|  | ||||
|             // Call download with the sender | ||||
|         let result = self.inner.download_updates(&rust_update_info, Some(sender)) | ||||
|             let result = self | ||||
|                 .inner | ||||
|                 .download_updates(&rust_update_info, Some(sender)) | ||||
|                 .map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to download updates: {}", e))); | ||||
|  | ||||
|             // Wait for the progress thread to finish | ||||
| @@ -83,22 +76,20 @@ pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback | ||||
|             result.map(|_| ()) | ||||
|         } else { | ||||
|             // No progress callback provided | ||||
|         self.inner.download_updates(&rust_update_info, None) | ||||
|             self.inner | ||||
|                 .download_updates(&rust_update_info, None) | ||||
|                 .map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to download updates: {}", e))) | ||||
|                 .map(|_| ()) | ||||
|         } | ||||
| } | ||||
|     } | ||||
|  | ||||
| pub fn apply_updates_and_restart(&mut self, update_info: &PyUpdateInfo) -> PyResult<()> { | ||||
|     pub fn apply_updates_and_restart(&mut self, update_info: &PyUpdateInfo) -> PyResult<()> { | ||||
|         // Convert PyUpdateInfo back to rust UpdateInfo | ||||
|         let rust_update_info: UpdateInfo = update_info.clone().into(); | ||||
|  | ||||
|     self.inner.apply_updates_and_restart(&rust_update_info) | ||||
|         self.inner | ||||
|             .apply_updates_and_restart(&rust_update_info) | ||||
|             .map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to apply updates and restart: {}", e))) | ||||
|             .map(|_| ()) | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user