feat(updater): allow passing headers & timeout in Update.download* methods (#1661)

closes #1634
This commit is contained in:
Amr Bashir
2024-09-03 01:02:16 +03:00
committed by GitHub
parent b9bcb2b6af
commit f8255e1db5
6 changed files with 69 additions and 11 deletions
+22 -4
View File
@@ -4,14 +4,14 @@
import { invoke, Channel, Resource } from "@tauri-apps/api/core";
/** Options used to check for updates */
/** Options used when checking for updates */
interface CheckOptions {
/**
* Request headers
*/
headers?: HeadersInit;
/**
* Timeout in seconds
* Timeout in milliseconds
*/
timeout?: number;
/**
@@ -24,6 +24,18 @@ interface CheckOptions {
target?: string;
}
/** Options used when downloading an update */
interface DownloadOptions {
/**
* Request headers
*/
headers?: HeadersInit;
/**
* Timeout in milliseconds
*/
timeout?: number;
}
interface UpdateMetadata {
rid: number;
available: boolean;
@@ -57,7 +69,10 @@ class Update extends Resource {
}
/** Download the updater package */
async download(onEvent?: (progress: DownloadEvent) => void): Promise<void> {
async download(
onEvent?: (progress: DownloadEvent) => void,
options?: DownloadOptions,
): Promise<void> {
const channel = new Channel<DownloadEvent>();
if (onEvent) {
channel.onmessage = onEvent;
@@ -65,6 +80,7 @@ class Update extends Resource {
const downloadedBytesRid = await invoke<number>("plugin:updater|download", {
onEvent: channel,
rid: this.rid,
...options,
});
this.downloadedBytes = new Resource(downloadedBytesRid);
}
@@ -87,6 +103,7 @@ class Update extends Resource {
/** Downloads the updater package and installs it */
async downloadAndInstall(
onEvent?: (progress: DownloadEvent) => void,
options?: DownloadOptions,
): Promise<void> {
const channel = new Channel<DownloadEvent>();
if (onEvent) {
@@ -95,6 +112,7 @@ class Update extends Resource {
await invoke("plugin:updater|download_and_install", {
onEvent: channel,
rid: this.rid,
...options,
});
}
@@ -115,5 +133,5 @@ async function check(options?: CheckOptions): Promise<Update | null> {
}).then((meta) => (meta.available ? new Update(meta) : null));
}
export type { CheckOptions, DownloadEvent };
export type { CheckOptions, DownloadOptions, DownloadEvent };
export { check, Update };