Skip to content

Commit

Permalink
feat(core): implement new config structure
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Feb 1, 2024
1 parent d6c7568 commit a033e20
Show file tree
Hide file tree
Showing 98 changed files with 3,635 additions and 7,884 deletions.
7 changes: 1 addition & 6 deletions core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ impl CodegenContext {
let (config, config_parent) = tauri_codegen::get_config(&self.config_path)?;

// rerun if changed
let app_url = if self.dev {
&config.build.dev_path
} else {
&config.build.dist_dir
};
match app_url {
match &config.build.frontend_dist {
Some(AppUrl::Url(WebviewUrl::App(p))) => {
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
}
Expand Down
22 changes: 10 additions & 12 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}
let config: Config = serde_json::from_value(config)?;

let s = config.tauri.bundle.identifier.split('.');
let s = config.identifier.split('.');
let last = s.clone().count() - 1;
let mut android_package_prefix = String::new();
for (i, w) in s.enumerate() {
Expand Down Expand Up @@ -500,7 +500,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
.parent()
.unwrap();

if let Some(paths) = &config.tauri.bundle.external_bin {
if let Some(paths) = &config.bundle.external_bin {
copy_binaries(
ResourcePaths::new(external_binaries(paths, &target_triple).as_slice(), true),
&target_triple,
Expand All @@ -511,16 +511,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

#[allow(unused_mut, clippy::redundant_clone)]
let mut resources = config
.tauri
.bundle
.resources
.clone()
.unwrap_or_else(|| BundleResources::List(Vec::new()));
if target_triple.contains("windows") {
if let Some(fixed_webview2_runtime_path) =
match &config.tauri.bundle.windows.webview_fixed_runtime_path {
match &config.bundle.windows.webview_fixed_runtime_path {
Some(path) => Some(path),
None => match &config.tauri.bundle.windows.webview_install_mode {
None => match &config.bundle.windows.webview_install_mode {
WebviewInstallMode::FixedRuntime { path } => Some(path),
_ => None,
},
Expand All @@ -537,7 +536,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}

if target_triple.contains("darwin") {
if let Some(frameworks) = &config.tauri.bundle.macos.frameworks {
if let Some(frameworks) = &config.bundle.macos.frameworks {
if !frameworks.is_empty() {
let frameworks_dir = target_dir.parent().unwrap().join("Frameworks");
let _ = std::fs::remove_dir_all(&frameworks_dir);
Expand All @@ -551,7 +550,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}
}

if let Some(version) = &config.tauri.bundle.macos.minimum_system_version {
if let Some(version) = &config.bundle.macos.minimum_system_version {
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET={version}");
}
}
Expand All @@ -562,7 +561,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

fn find_icon<F: Fn(&&String) -> bool>(config: &Config, predicate: F, default: &str) -> PathBuf {
let icon_path = config
.tauri
.bundle
.icon
.iter()
Expand All @@ -585,23 +583,23 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
res.set_manifest(include_str!("window-app-manifest.xml"));
}

if let Some(version_str) = &config.package.version {
if let Some(version_str) = &config.version {
if let Ok(v) = Version::parse(version_str) {
let version = v.major << 48 | v.minor << 32 | v.patch << 16;
res.set_version_info(VersionInfo::FILEVERSION, version);
res.set_version_info(VersionInfo::PRODUCTVERSION, version);
}
}

if let Some(product_name) = &config.package.product_name {
if let Some(product_name) = &config.product_name {
res.set("ProductName", product_name);
}

if let Some(short_description) = &config.tauri.bundle.short_description {
if let Some(short_description) = &config.bundle.short_description {
res.set("FileDescription", short_description);
}

if let Some(copyright) = &config.tauri.bundle.copyright {
if let Some(copyright) = &config.bundle.copyright {
res.set("LegalCopyright", copyright);
}

Expand Down
8 changes: 4 additions & 4 deletions core/tauri-build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use anyhow::{anyhow, Result};
use cargo_toml::{Dependency, Manifest};
use tauri_utils::config::{Config, PatternKind, TauriConfig};
use tauri_utils::config::{AppConfig, Config, PatternKind};

#[derive(Debug, Default, PartialEq, Eq)]
struct Diff {
Expand Down Expand Up @@ -34,7 +34,7 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
alias: None,
kind: DependencyKind::Build,
all_cli_managed_features: Some(vec!["isolation"]),
expected_features: match config.tauri.pattern {
expected_features: match config.app.security.pattern {
PatternKind::Isolation { .. } => vec!["isolation".to_string()],
_ => vec![],
},
Expand All @@ -44,13 +44,13 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
alias: None,
kind: DependencyKind::Normal,
all_cli_managed_features: Some(
TauriConfig::all_features()
AppConfig::all_features()
.into_iter()
.filter(|f| f != &"tray-icon")
.collect(),
),
expected_features: config
.tauri
.app
.features()
.into_iter()
.filter(|f| f != &"tray-icon")
Expand Down
27 changes: 10 additions & 17 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,30 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
.map(Target::from_triple)
.unwrap_or_else(|_| Target::current());

let mut options = AssetOptions::new(config.tauri.pattern.clone())
.freeze_prototype(config.tauri.security.freeze_prototype)
let mut options = AssetOptions::new(config.app.security.pattern.clone())
.freeze_prototype(config.app.security.freeze_prototype)
.dangerous_disable_asset_csp_modification(
config
.tauri
.app
.security
.dangerous_disable_asset_csp_modification
.clone(),
);
let csp = if dev {
config
.tauri
.app
.security
.dev_csp
.as_ref()
.or(config.tauri.security.csp.as_ref())
.or(config.app.security.csp.as_ref())
} else {
config.tauri.security.csp.as_ref()
config.app.security.csp.as_ref()
};
if csp.is_some() {
options = options.with_csp();
}

let app_url = if dev {
&config.build.dev_path
} else {
&config.build.dist_dir
};

let assets = match app_url {
let assets = match &config.build.frontend_dist {
Some(url) => match url {
AppUrl::Url(url) => match url {
WebviewUrl::External(_) | WebviewUrl::CustomProtocol(_) => Default::default(),
Expand Down Expand Up @@ -257,12 +251,12 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
quote!(::std::option::Option::None)
};

let package_name = if let Some(product_name) = &config.package.product_name {
let package_name = if let Some(product_name) = &config.product_name {
quote!(#product_name.to_string())
} else {
quote!(env!("CARGO_PKG_NAME").to_string())
};
let package_version = if let Some(version) = &config.package.version {
let package_version = if let Some(version) = &config.version {
semver::Version::from_str(version)?;
quote!(#version.to_string())
} else {
Expand All @@ -279,7 +273,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
);

let with_tray_icon_code = if target.is_desktop() {
if let Some(tray) = &config.tauri.tray_icon {
if let Some(tray) = &config.app.tray_icon {
let tray_icon_icon_path = config_parent.join(&tray.icon_path);
let ext = tray_icon_icon_path.extension();
if ext.map_or(false, |e| e == "ico") {
Expand Down Expand Up @@ -533,7 +527,6 @@ fn find_icon<F: Fn(&&String) -> bool>(
default: &str,
) -> PathBuf {
let icon_path = config
.tauri
.bundle
.icon
.iter()
Expand Down
Loading

0 comments on commit a033e20

Please sign in to comment.