Add python missing UM methods and fix apply signature

This commit is contained in:
Caelan Sayler
2025-06-27 13:38:21 +01:00
committed by Caelan
parent a2c559072b
commit 3ba32af42b
3 changed files with 53 additions and 27 deletions

View File

@@ -11,7 +11,7 @@ cd %~dp0
echo.
echo Installing dependencies
uv sync
uv sync --reinstall-package velopack
if errorlevel 1 exit /b 1
echo update_url = R"%~dp0releases" > _build_config.py

View File

@@ -10,11 +10,28 @@ use app::VelopackAppWrapper;
mod manager;
use manager::UpdateManagerWrapper;
use ::velopack::VelopackAsset;
#[derive(FromPyObject)]
pub enum PyUpdateInfoOrAsset {
UpdateInfo(PyUpdateInfo),
Asset(PyVelopackAsset),
}
impl PyUpdateInfoOrAsset {
pub fn into_asset(self) -> VelopackAsset {
match self {
PyUpdateInfoOrAsset::UpdateInfo(update_info) => update_info.TargetFullRelease.into(),
PyUpdateInfoOrAsset::Asset(asset) => asset.into(),
}
}
}
#[pymodule]
#[pyo3(name = "velopack")]
fn velopack(m: &Bound<'_, PyModule>) -> PyResult<()> {
pyo3_log::init();
// auto-generated DTO's
m.add_class::<PyVelopackAsset>()?;
m.add_class::<PyUpdateInfo>()?;

View File

@@ -4,9 +4,9 @@ use std::sync::mpsc;
use std::thread;
use velopack::sources::AutoSource;
use velopack::{UpdateCheck, UpdateInfo, UpdateManager as VelopackUpdateManagerRust};
use velopack::{UpdateCheck, UpdateInfo, UpdateManager as VelopackUpdateManagerRust, VelopackAsset};
use crate::types::*;
use crate::{types::*, PyUpdateInfoOrAsset};
#[pyclass(name = "UpdateManager")]
pub struct UpdateManagerWrapper {
@@ -19,11 +19,27 @@ impl UpdateManagerWrapper {
#[pyo3(signature = (source, options = None, locator = None))]
pub fn new(source: String, options: Option<PyUpdateOptions>, locator: Option<PyVelopackLocatorConfig>) -> Result<Self> {
let source = AutoSource::new(&source);
// set myinner to a new VelopackUpdateManager with the source
let inner = VelopackUpdateManagerRust::new(source, options.map(Into::into), locator.map(Into::into))?;
Ok(UpdateManagerWrapper { inner })
}
pub fn get_current_version(&self) -> String {
self.inner.get_current_version_as_string()
}
pub fn get_app_id(&self) -> String {
self.inner.get_app_id().to_string()
}
pub fn get_is_portable(&self) -> bool {
self.inner.get_is_portable()
}
pub fn get_update_pending_restart(&self) -> Option<PyVelopackAsset> {
let pending = self.inner.get_update_pending_restart();
pending.map(Into::into)
}
pub fn check_for_updates(&mut self) -> Result<Option<PyUpdateInfo>> {
let update_check = self.inner.check_for_updates()?;
match update_check {
@@ -37,9 +53,9 @@ impl UpdateManagerWrapper {
}
#[pyo3(signature = (update_info, progress_callback = None))]
pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback: Option<PyObject>) -> Result<()> {
pub fn download_updates(&mut self, update_info: PyUpdateInfo, progress_callback: Option<PyObject>) -> Result<()> {
// Convert PyUpdateInfo back to rust UpdateInfo
let rust_update_info: UpdateInfo = update_info.clone().into();
let rust_update_info: UpdateInfo = update_info.into();
if let Some(callback) = progress_callback {
// Create a channel for progress updates
@@ -71,42 +87,35 @@ impl UpdateManagerWrapper {
}
}
pub fn apply_updates_and_restart(&mut self, update_info: &PyUpdateInfo) -> Result<()> {
// Convert PyUpdateInfo back to rust UpdateInfo
let rust_update_info: UpdateInfo = update_info.clone().into();
self.inner.apply_updates_and_restart(&rust_update_info)?;
pub fn apply_updates_and_restart(&mut self, update: PyUpdateInfoOrAsset) -> Result<()> {
let asset: VelopackAsset = update.into_asset();
self.inner.apply_updates_and_restart(&asset)?;
Ok(())
}
pub fn apply_updates_and_restart_with_args(&mut self, update_info: &PyUpdateInfo, restart_args: Vec<String>) -> Result<()> {
// Convert PyUpdateInfo back to rust UpdateInfo
let rust_update_info: UpdateInfo = update_info.clone().into();
self.inner.apply_updates_and_restart_with_args(&rust_update_info, restart_args)?;
pub fn apply_updates_and_restart_with_args(&mut self, update: PyUpdateInfoOrAsset, restart_args: Vec<String>) -> Result<()> {
let asset: VelopackAsset = update.into_asset();
self.inner.apply_updates_and_restart_with_args(&asset, restart_args)?;
Ok(())
}
pub fn apply_updates_and_exit(&mut self, update_info: &PyUpdateInfo) -> Result<()> {
// Convert PyUpdateInfo back to rust UpdateInfo
let rust_update_info: UpdateInfo = update_info.clone().into();
self.inner.apply_updates_and_exit(&rust_update_info)?;
pub fn apply_updates_and_exit(&mut self, update: PyUpdateInfoOrAsset) -> Result<()> {
let asset: VelopackAsset = update.into_asset();
self.inner.apply_updates_and_exit(&asset)?;
Ok(())
}
#[pyo3(signature = (update_info, silent = false, restart = true, restart_args = None))]
#[pyo3(signature = (update, silent = false, restart = true, restart_args = None))]
pub fn wait_exit_then_apply_updates(
&mut self,
update_info: &PyUpdateInfo,
update: PyUpdateInfoOrAsset,
silent: bool,
restart: bool,
restart_args: Option<Vec<String>>,
) -> Result<()> {
// Convert PyUpdateInfo back to rust UpdateInfo
let rust_update_info: UpdateInfo = update_info.clone().into();
// Convert restart_args to the format expected by the Rust function
let asset: VelopackAsset = update.into_asset();
let args = restart_args.unwrap_or_default();
self.inner.wait_exit_then_apply_updates(&rust_update_info, silent, restart, args)?;
self.inner.wait_exit_then_apply_updates(&asset, silent, restart, args)?;
Ok(())
}
}