From ef7f55691a0bfda258c8ae1cb308cbb58c6f5717 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Fri, 27 Jun 2025 12:04:06 +0100 Subject: [PATCH] Fix js typings for waitExitThenApplyUpdate and getUpdatePendingRestart --- src/lib-nodejs/src/index.ts | 22 ++++++++++++++++------ src/lib-nodejs/velopack_nodeffi/src/lib.rs | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lib-nodejs/src/index.ts b/src/lib-nodejs/src/index.ts index c3e18936..0d6c3e4e 100644 --- a/src/lib-nodejs/src/index.ts +++ b/src/lib-nodejs/src/index.ts @@ -19,7 +19,7 @@ declare module "./load" { function js_update_pending_restart( um: UpdateManagerOpaque, - ): UpdateInfo | null; + ): string | null; function js_check_for_updates_async( um: UpdateManagerOpaque, @@ -239,11 +239,15 @@ export class UpdateManager { } /** - * Returns an UpdateInfo object if there is an update downloaded which still needs to be applied. - * You can pass the UpdateInfo object to waitExitThenApplyUpdate to apply the update. + * Returns an VelopackAsset object if there is an update downloaded which still needs to be applied. + * You can pass the VelopackAsset object to waitExitThenApplyUpdate to apply the update. */ - getUpdatePendingRestart(): UpdateInfo | null { - return addon.js_update_pending_restart(this.opaque); + getUpdatePendingRestart(): VelopackAsset | null { + let json: string | null = addon.js_update_pending_restart(this.opaque); + if (json && json.length > 0) { + return JSON.parse(json); + } + return null; } /** @@ -290,7 +294,7 @@ export class UpdateManager { * optionally restart your app. The updater will only wait for 60 seconds before giving up. */ waitExitThenApplyUpdate( - update: UpdateInfo, + update: UpdateInfo | VelopackAsset, silent: boolean = false, restart: boolean = true, restartArgs: string[] = [], @@ -298,6 +302,12 @@ export class UpdateManager { if (!update) { throw new Error("update is required"); } + + // the backend API only accepts VelopackAsset, so we need to extract it from UpdateInfo + if ("TargetFullRelease" in update && typeof update.TargetFullRelease === "object") { + update = update.TargetFullRelease; + } + addon.js_wait_exit_then_apply_update( this.opaque, JSON.stringify(update), diff --git a/src/lib-nodejs/velopack_nodeffi/src/lib.rs b/src/lib-nodejs/velopack_nodeffi/src/lib.rs index 4cc52996..91d7bb71 100644 --- a/src/lib-nodejs/velopack_nodeffi/src/lib.rs +++ b/src/lib-nodejs/velopack_nodeffi/src/lib.rs @@ -209,12 +209,12 @@ fn js_wait_exit_then_apply_update(mut cx: FunctionContext) -> JsResult(2)?.value(&mut cx); let arg_restart = cx.argument::(3)?.value(&mut cx); - let update_info = serde_json::from_str::(&arg_update).or_else(|e| cx.throw_error(e.to_string()))?; + let asset = serde_json::from_str::(&arg_update).or_else(|e| cx.throw_error(e.to_string()))?; let arg_restart_args = cx.argument::(4)?; let restart_args = args_array_to_vec_string(&mut cx, arg_restart_args)?; - mgr_ref.wait_exit_then_apply_updates(update_info, arg_silent, arg_restart, restart_args).or_else(|e| cx.throw_error(e.to_string()))?; + mgr_ref.wait_exit_then_apply_updates(asset, arg_silent, arg_restart, restart_args).or_else(|e| cx.throw_error(e.to_string()))?; Ok(cx.undefined()) }