#[cfg(feature = "isolation")]
use std::sync::Arc;
use serde::Serialize;
use serialize_to_javascript::{default_template, Template};
#[cfg(feature = "isolation")]
pub const ISOLATION_IFRAME_SRC_DOMAIN: &str = "localhost";
#[derive(Debug)]
pub enum Pattern {
Brownfield,
#[cfg(feature = "isolation")]
Isolation {
assets: Arc<tauri_utils::assets::EmbeddedAssets>,
schema: String,
key: String,
crypto_keys: Box<tauri_utils::pattern::isolation::Keys>,
},
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase", tag = "pattern")]
pub(crate) enum PatternObject {
Brownfield,
#[cfg(feature = "isolation")]
Isolation {
side: IsolationSide,
},
}
impl From<&Pattern> for PatternObject {
fn from(pattern: &Pattern) -> Self {
match pattern {
Pattern::Brownfield => Self::Brownfield,
#[cfg(feature = "isolation")]
Pattern::Isolation { .. } => Self::Isolation {
side: IsolationSide::default(),
},
}
}
}
#[cfg(feature = "isolation")]
#[derive(Default, Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum IsolationSide {
#[default]
Original,
#[allow(dead_code)]
Secure,
}
#[derive(Template)]
#[default_template("../scripts/pattern.js")]
pub(crate) struct PatternJavascript {
pub(crate) pattern: PatternObject,
}
#[cfg(feature = "isolation")]
pub(crate) fn format_real_schema(schema: &str, https: bool) -> String {
if cfg!(windows) || cfg!(target_os = "android") {
let scheme = if https { "https" } else { "http" };
format!("{scheme}://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}/")
} else {
format!("{schema}://{ISOLATION_IFRAME_SRC_DOMAIN}/")
}
}