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(Debug, Serialize)]
68#[serde(rename_all = "lowercase")]
69pub(crate) enum IsolationSide {
70 Original,
72 #[allow(dead_code)]
74 Secure,
75}
76
77#[cfg(feature = "isolation")]
78impl Default for IsolationSide {
79 fn default() -> Self {
80 Self::Original
81 }
82}
83
84#[derive(Template)]
85#[default_template("../scripts/pattern.js")]
86pub(crate) struct PatternJavascript {
87 pub(crate) pattern: PatternObject,
88}
89
90#[cfg(feature = "isolation")]
91pub(crate) fn format_real_schema(schema: &str, https: bool) -> String {
92 if cfg!(windows) || cfg!(target_os = "android") {
93 let scheme = if https { "https" } else { "http" };
94 format!("{scheme}://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}/")
95 } else {
96 format!("{schema}://{ISOLATION_IFRAME_SRC_DOMAIN}/")
97 }
98}