mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-01 12:08:06 +02:00
4ab90f048e
Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Nogueira <lucas@tauri.app>
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use serde::{Deserialize, Deserializer};
|
|
use url::Url;
|
|
|
|
/// Updater configuration.
|
|
#[derive(Debug, Clone, Deserialize, Default)]
|
|
pub struct Config {
|
|
#[serde(default)]
|
|
pub endpoints: Vec<UpdaterEndpoint>,
|
|
/// Additional arguments given to the NSIS or WiX installer.
|
|
#[serde(default, alias = "installer-args")]
|
|
pub installer_args: Vec<String>,
|
|
}
|
|
|
|
/// A URL to an updater server.
|
|
///
|
|
/// The URL must use the `https` scheme on production.
|
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
|
pub struct UpdaterEndpoint(pub Url);
|
|
|
|
impl std::fmt::Display for UpdaterEndpoint {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}", self.0)
|
|
}
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for UpdaterEndpoint {
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let url = Url::deserialize(deserializer)?;
|
|
#[cfg(all(not(debug_assertions), not(feature = "schema")))]
|
|
{
|
|
if url.scheme() != "https" {
|
|
return Err(serde::de::Error::custom(
|
|
"The configured updater endpoint must use the `https` protocol.",
|
|
));
|
|
}
|
|
}
|
|
Ok(Self(url))
|
|
}
|
|
}
|