Skip to content

Commit 3ba32af

Browse files
committed
Add python missing UM methods and fix apply signature
1 parent a2c5590 commit 3ba32af

3 files changed

Lines changed: 53 additions & 27 deletions

File tree

‎samples/PythonWXPython/build.bat‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cd %~dp0
1111

1212
echo.
1313
echo Installing dependencies
14-
uv sync
14+
uv sync --reinstall-package velopack
1515
if errorlevel 1 exit /b 1
1616

1717
echo update_url = R"%~dp0releases" > _build_config.py

‎src/lib-python/src/lib.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ use app::VelopackAppWrapper;
1010
mod manager;
1111
use manager::UpdateManagerWrapper;
1212

13+
use ::velopack::VelopackAsset;
14+
15+
#[derive(FromPyObject)]
16+
pub enum PyUpdateInfoOrAsset {
17+
UpdateInfo(PyUpdateInfo),
18+
Asset(PyVelopackAsset),
19+
}
20+
21+
impl PyUpdateInfoOrAsset {
22+
pub fn into_asset(self) -> VelopackAsset {
23+
match self {
24+
PyUpdateInfoOrAsset::UpdateInfo(update_info) => update_info.TargetFullRelease.into(),
25+
PyUpdateInfoOrAsset::Asset(asset) => asset.into(),
26+
}
27+
}
28+
}
29+
1330
#[pymodule]
1431
#[pyo3(name = "velopack")]
1532
fn velopack(m: &Bound<'_, PyModule>) -> PyResult<()> {
1633
pyo3_log::init();
17-
34+
1835
// auto-generated DTO's
1936
m.add_class::<PyVelopackAsset>()?;
2037
m.add_class::<PyUpdateInfo>()?;

‎src/lib-python/src/manager.rs‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::sync::mpsc;
44
use std::thread;
55

66
use 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")]
1212
pub 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

Comments
 (0)