mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix js typings for waitExitThenApplyUpdate and getUpdatePendingRestart
This commit is contained in:
@@ -19,7 +19,7 @@ declare module "./load" {
|
|||||||
|
|
||||||
function js_update_pending_restart(
|
function js_update_pending_restart(
|
||||||
um: UpdateManagerOpaque,
|
um: UpdateManagerOpaque,
|
||||||
): UpdateInfo | null;
|
): string | null;
|
||||||
|
|
||||||
function js_check_for_updates_async(
|
function js_check_for_updates_async(
|
||||||
um: UpdateManagerOpaque,
|
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.
|
* Returns an VelopackAsset 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.
|
* You can pass the VelopackAsset object to waitExitThenApplyUpdate to apply the update.
|
||||||
*/
|
*/
|
||||||
getUpdatePendingRestart(): UpdateInfo | null {
|
getUpdatePendingRestart(): VelopackAsset | null {
|
||||||
return addon.js_update_pending_restart(this.opaque);
|
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.
|
* optionally restart your app. The updater will only wait for 60 seconds before giving up.
|
||||||
*/
|
*/
|
||||||
waitExitThenApplyUpdate(
|
waitExitThenApplyUpdate(
|
||||||
update: UpdateInfo,
|
update: UpdateInfo | VelopackAsset,
|
||||||
silent: boolean = false,
|
silent: boolean = false,
|
||||||
restart: boolean = true,
|
restart: boolean = true,
|
||||||
restartArgs: string[] = [],
|
restartArgs: string[] = [],
|
||||||
@@ -298,6 +302,12 @@ export class UpdateManager {
|
|||||||
if (!update) {
|
if (!update) {
|
||||||
throw new Error("update is required");
|
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(
|
addon.js_wait_exit_then_apply_update(
|
||||||
this.opaque,
|
this.opaque,
|
||||||
JSON.stringify(update),
|
JSON.stringify(update),
|
||||||
|
|||||||
@@ -209,12 +209,12 @@ fn js_wait_exit_then_apply_update(mut cx: FunctionContext) -> JsResult<JsUndefin
|
|||||||
let arg_silent = cx.argument::<JsBoolean>(2)?.value(&mut cx);
|
let arg_silent = cx.argument::<JsBoolean>(2)?.value(&mut cx);
|
||||||
let arg_restart = cx.argument::<JsBoolean>(3)?.value(&mut cx);
|
let arg_restart = cx.argument::<JsBoolean>(3)?.value(&mut cx);
|
||||||
|
|
||||||
let update_info = serde_json::from_str::<UpdateInfo>(&arg_update).or_else(|e| cx.throw_error(e.to_string()))?;
|
let asset = serde_json::from_str::<VelopackAsset>(&arg_update).or_else(|e| cx.throw_error(e.to_string()))?;
|
||||||
|
|
||||||
let arg_restart_args = cx.argument::<JsArray>(4)?;
|
let arg_restart_args = cx.argument::<JsArray>(4)?;
|
||||||
let restart_args = args_array_to_vec_string(&mut cx, arg_restart_args)?;
|
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())
|
Ok(cx.undefined())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user