1#[cfg(feature = "isolation")]
6use std::sync::Arc;
7
8use serde::Serialize;
9use serialize_to_javascript::{default_template, Template};
10
11#[cfg(feature = "isolation")]
13pub const ISOLATION_IFRAME_SRC_DOMAIN: &str = "localhost";
14
15#[derive(Debug)]
17pub enum Pattern {
18 Brownfield,
20 #[cfg(feature = "isolation")]
22 Isolation {
23 assets: Arc<tauri_utils::assets::EmbeddedAssets>,
25
26 schema: String,
28
29 key: String,
33
34 crypto_keys: Box<tauri_utils::pattern::isolation::Keys>,
36 },
37}
38
39#[derive(Debug, Serialize)]
41#[serde(rename_all = "lowercase", tag = "pattern")]
42pub(crate) enum PatternObject {
43 Brownfield,
45 #[cfg(feature = "isolation")]
47 Isolation {
48 side: IsolationSide,
50 },
51}
52
53impl From<&Pattern> for PatternObject {
54 fn from(pattern: &Pattern) -> Self {
55 match pattern {
56 Pattern::Brownfield => Self::Brownfield,
57 #[cfg(feature = "isolation")]
58 Pattern::Isolation { .. } => Self::Isolation {
59 side: IsolationSide::default(),
60 },
61 }
62 }
63}
64
65#[cfg(feature = "isolation")]
67#[derive(Default, Debug, Serialize)]
68#[serde(rename_all = "lowercase")]
69pub(crate) enum IsolationSide {
70 #[default]
72 Original,
73 #[allow(dead_code)]
75 Secure,
76}
77
78#[derive(Template)]
79#[default_template("../scripts/pattern.js")]
80pub(crate) struct PatternJavascript {
81 pub(crate) pattern: PatternObject,
82}
83
84#[cfg(feature = "isolation")]
85pub(crate) fn format_real_schema(schema: &str, https: bool) -> String {
86 if cfg!(windows) || cfg!(target_os = "android") {
87 let scheme = if https { "https" } else { "http" };
88 format!("{scheme}://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}/")
89 } else {
90 format!("{schema}://{ISOLATION_IFRAME_SRC_DOMAIN}/")
91 }
92}