Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/updater-date-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"updater": "minor:bug"
"updater-js": "minor:bug"
---

Fix JS API `Update.date` not formatted to RFC 3339
10 changes: 7 additions & 3 deletions examples/api/src/views/Updater.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
isChecking = true
try {
const update = await check()
onMessage(`Should update: ${update.available}`)
onMessage(update)
if (update) {
onMessage(`Should update: ${update.available}`)
onMessage(update)

newUpdate = update
newUpdate = update
} else {
onMessage('No update available')
}
} catch (e) {
onMessage(e)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion plugins/updater/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions plugins/updater/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface DownloadOptions {

interface UpdateMetadata {
rid: number
available: boolean
currentVersion: string
version: string
date?: string
Expand All @@ -53,6 +52,8 @@ type DownloadEvent =
| { event: 'Finished' }

class Update extends Resource {
// TODO: remove this field in v3
/** @deprecated This is always true, check if the return value is `null` instead when using {@linkcode check} */
available: boolean
currentVersion: string
version: string
Expand All @@ -63,7 +64,7 @@ class Update extends Resource {

constructor(metadata: UpdateMetadata) {
super(metadata.rid)
this.available = metadata.available
this.available = true
this.currentVersion = metadata.currentVersion
this.version = metadata.version
this.date = metadata.date
Expand Down Expand Up @@ -131,12 +132,10 @@ async function check(options?: CheckOptions): Promise<Update | null> {
options.headers = Array.from(new Headers(options.headers).entries())
}

return await invoke<UpdateMetadata>('plugin:updater|check', {
const metadata = await invoke<UpdateMetadata | null>('plugin:updater|check', {
...options
}).then((meta) =>
// TODO: Handle this in the rust side
meta.available ? new Update(meta) : null
)
})
return metadata ? new Update(metadata) : null
}

export type { CheckOptions, DownloadOptions, DownloadEvent }
Expand Down
37 changes: 22 additions & 15 deletions plugins/updater/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ pub enum DownloadEvent {
#[derive(Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Metadata {
rid: Option<ResourceId>,
available: bool,
rid: ResourceId,
current_version: String,
version: String,
date: Option<String>,
Expand All @@ -40,16 +39,14 @@ pub(crate) struct Metadata {
struct DownloadedBytes(pub Vec<u8>);
impl Resource for DownloadedBytes {}

// TODO: Align this with the result of `updater.check` to Result<Option<Metadata>>
// and remove `available` instead of handling this in the js side
#[tauri::command]
pub(crate) async fn check<R: Runtime>(
webview: Webview<R>,
headers: Option<Vec<(String, String)>>,
timeout: Option<u64>,
proxy: Option<String>,
target: Option<String>,
) -> Result<Metadata> {
) -> Result<Option<Metadata>> {
let mut builder = webview.updater_builder();
if let Some(headers) = headers {
for (k, v) in headers {
Expand All @@ -69,18 +66,28 @@ pub(crate) async fn check<R: Runtime>(

let updater = builder.build()?;
let update = updater.check().await?;
let mut metadata = Metadata::default();

if let Some(update) = update {
metadata.available = true;
metadata.current_version.clone_from(&update.current_version);
metadata.version.clone_from(&update.version);
metadata.date = update.date.map(|d| d.to_string());
metadata.body.clone_from(&update.body);
metadata.raw_json.clone_from(&update.raw_json);
metadata.rid = Some(webview.resources_table().add(update));
let formatted_date = if let Some(date) = update.date {
let formatted_date = date
.format(&time::format_description::well_known::Rfc3339)
.map_err(|_| crate::Error::FormatDate)?;
Some(formatted_date)
} else {
None
};
let metadata = Metadata {
current_version: update.current_version.clone(),
version: update.version.clone(),
date: formatted_date,
body: update.body.clone(),
raw_json: update.raw_json.clone(),
rid: webview.resources_table().add(update),
};
Ok(Some(metadata))
} else {
Ok(None)
}

Ok(metadata)
}

#[tauri::command]
Expand Down
2 changes: 2 additions & 0 deletions plugins/updater/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub enum Error {
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
#[error(transparent)]
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
#[error("Failed to format date")]
FormatDate,
/// The configured updater endpoint must use a secure protocol like `https`
#[error("The configured updater endpoint must use a secure protocol like `https`.")]
InsecureTransportProtocol,
Expand Down
3 changes: 2 additions & 1 deletion plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ impl UpdaterBuilder {
I: IntoIterator<Item = S>,
S: Into<OsString>,
{
self.installer_args.extend(args.into_iter().map(Into::into));
self.current_exe_args
.extend(args.into_iter().map(Into::into));
self
}
}
Expand Down
Loading