use std::path::Path;
use tauri_bundler::WebviewRuntime;
use tauri_utils::config::WebviewInstallMode;
use crate::interface::rust::manifest::Manifest;
pub mod cef;
#[cfg(target_os = "macos")]
pub mod macos_dev;
pub const WRY_CRATE_NAME: &str = "tauri-runtime-wry";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Runtime {
Wry,
Cef,
Other,
}
#[cfg(target_os = "linux")]
#[derive(Debug, Clone, Copy)]
pub struct LinuxDependency {
pub deb_package: &'static str,
pub library: &'static str,
}
impl Runtime {
pub fn detect(manifest: &Manifest, enabled_features: &[String], target_triple: &str) -> Self {
if manifest.uses_dependency(cef::CRATE_NAME, enabled_features, target_triple) {
Self::Cef
} else if manifest.uses_dependency(WRY_CRATE_NAME, enabled_features, target_triple) {
Self::Wry
} else {
Self::Other
}
}
#[cfg(target_os = "linux")]
pub fn linux_dependencies(self) -> &'static [LinuxDependency] {
const GTK: LinuxDependency = LinuxDependency {
deb_package: "libgtk-3-0",
library: "libgtk-3.so.0",
};
const WEBKIT2GTK: LinuxDependency = LinuxDependency {
deb_package: "libwebkit2gtk-4.1-0",
library: "libwebkit2gtk-4.1.so.0",
};
match self {
Self::Wry => &[WEBKIT2GTK, GTK],
Self::Cef | Self::Other => &[GTK],
}
}
pub fn webview_install_mode(self, configured: WebviewInstallMode) -> WebviewInstallMode {
match self {
Self::Wry => configured,
Self::Cef | Self::Other => WebviewInstallMode::Skip,
}
}
pub fn minimum_webview2_version(self, configured: Option<String>) -> Option<String> {
match self {
Self::Wry => configured,
Self::Cef | Self::Other => None,
}
}
#[cfg(target_os = "macos")]
pub fn macos_entitlements(self) -> plist::Dictionary {
let mut entitlements = plist::Dictionary::new();
match self {
Self::Wry | Self::Other => {}
Self::Cef => {
entitlements.insert("com.apple.security.cs.allow-jit".to_string(), true.into());
entitlements.insert(
"com.apple.security.cs.allow-unsigned-executable-memory".to_string(),
true.into(),
);
entitlements.insert(
"com.apple.security.cs.disable-library-validation".to_string(),
true.into(),
);
}
}
entitlements
}
#[cfg(target_os = "macos")]
pub fn macos_dev_in_app_bundle(self) -> bool {
match self {
Self::Cef => true,
Self::Wry | Self::Other => false,
}
}
pub fn bundler_runtime(
self,
embed_cef: bool,
target: &str,
workspace_dir: &Path,
target_dir: &Path,
) -> crate::Result<WebviewRuntime> {
Ok(match self {
Self::Wry => WebviewRuntime::Wry,
Self::Other => WebviewRuntime::Other,
Self::Cef => {
let cef_path = crate::runtime::cef::cef_path_env();
let helper = if target.contains("apple-darwin") {
let (cef_crate_path, cef_dll_sys_crate_path) =
cef::resolved_crate_paths(workspace_dir, target)?;
Some(tauri_bundler::bundle::CefHelperSettings {
cef_crate_path,
cef_dll_sys_crate_path,
cef_path: cef_path.clone(),
build_dir: target_dir.join("tauri-cef-helper"),
})
} else {
None
};
if embed_cef {
WebviewRuntime::Cef {
distribution: Some(cef::resolve_path_for_bundle(
cef_path,
target,
workspace_dir,
)?),
helper,
}
} else {
WebviewRuntime::Cef {
distribution: None,
helper,
}
}
}
})
}
}