Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into refactor/muda-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 20, 2023
2 parents 0c53ebc + b727735 commit d1b81bf
Show file tree
Hide file tree
Showing 67 changed files with 6,039 additions and 406 deletions.
5 changes: 5 additions & 0 deletions .changes/android-on-new-intent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": 'patch:enhance'
---

Listen to `onNewIntent` and forward it to registered plugins.
6 changes: 6 additions & 0 deletions .changes/cli-expose-plugin-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---

Expose an environment variable `TAURI_${PLUGIN_NAME}_PLUGIN_CONFIG` for each defined plugin configuration object.
6 changes: 6 additions & 0 deletions .changes/cli-ios-metadata-env-var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---

Expose the `TAURI_IOS_PROJECT_PATH` and `TAURI_IOS_APP_NAME` environment variables when using `ios` commands.
5 changes: 5 additions & 0 deletions .changes/core-app-montior.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Add `App::primary_monitor`, `App::available_monitors`, `AppHandle::primary_monitor`, and `AppHandle::available_monitors`
5 changes: 5 additions & 0 deletions .changes/file-associations-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-utils": minor:feat
---

Add a configuration object for file associations under `BundleConfig`.
5 changes: 5 additions & 0 deletions .changes/file-associations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": minor:feat
---

Added support to file associations.
6 changes: 6 additions & 0 deletions .changes/ios-entitlements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:feat
"@tauri-apps/cli": patch:feat
---

Generate empty entitlements file for the iOS project.
5 changes: 5 additions & 0 deletions .changes/plugin-config-getter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---

Added the `config::plugin_config` function to read the plugin configuration set from the CLI.
5 changes: 5 additions & 0 deletions .changes/rewrite-android-manifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---

Added the `mobile::update_android_manifest` function.
5 changes: 5 additions & 0 deletions .changes/run-event-opened.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:feat
---

Expose `RunEvent::Opened` on macOS and iOS for deep link support.
6 changes: 6 additions & 0 deletions .changes/runtime-monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-runtime": "minor:feat"
"tauri-runtime-wry": "minor:feat"
---

Added `primary_monitor` and `available_monitors` to `Runtime` and `RuntimeHandle`.
6 changes: 6 additions & 0 deletions .changes/runtime-opened-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-runtime": minor:feat
"tauri-runtime-wry": minor:feat
---

Added the `Opened` variant to `RunEvent`.
5 changes: 5 additions & 0 deletions .changes/update-entitlements-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---

Added the `mobile::update_entitlements` function for iOS.
2 changes: 1 addition & 1 deletion .github/workflows/covector-version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
steps.covector.outputs.successfulPublish == 'true' &&
contains(steps.covector.outputs.packagesPublished, '@tauri-apps/cli')
run: |
echo '${{ steps.covector.outputs }}' > output.json
echo '${{ toJSON(steps.covector.outputs) }}' > output.json
id=$(jq '.["-tauri-apps-cli-releaseId"]' < output.json)
rm output.json
echo "cliReleaseId=$id" >> "$GITHUB_OUTPUT"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exclude = [
"examples/resources/src-tauri",
"examples/sidecar/src-tauri",
"examples/web/core",
"examples/file-associations/src-tauri",
"examples/workspace",
]

Expand Down
1 change: 1 addition & 0 deletions core/tauri-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ semver = "1"

[target."cfg(target_os = \"macos\")".dependencies]
swift-rs = { version = "1.0.5", features = [ "build" ] }
plist = "1"

[features]
codegen = [ "tauri-codegen", "quote" ]
Expand Down
22 changes: 22 additions & 0 deletions core/tauri-build/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use serde::de::DeserializeOwned;

use std::{env::var, io::Cursor};

pub fn plugin_config<T: DeserializeOwned>(name: &str) -> Option<T> {
let config_env_var_name = format!(
"TAURI_{}_PLUGIN_CONFIG",
name.to_uppercase().replace('-', "_")
);
if let Ok(config_str) = var(&config_env_var_name) {
println!("cargo:rerun-if-env-changed={config_env_var_name}");
serde_json::from_reader(Cursor::new(config_str))
.map(Some)
.expect("failed to parse configuration")
} else {
None
}
}
2 changes: 2 additions & 0 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use std::{
mod allowlist;
#[cfg(feature = "codegen")]
mod codegen;
/// Tauri configuration functions.
pub mod config;
/// Mobile build functions.
pub mod mobile;
mod static_vcruntime;
Expand Down
129 changes: 128 additions & 1 deletion core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{
env::{var, var_os},
fs::{copy, create_dir, create_dir_all, remove_dir_all, write},
fs::{copy, create_dir, create_dir_all, read_to_string, remove_dir_all, write},
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -146,6 +146,97 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()
Ok(())
}

#[cfg(target_os = "macos")]
fn update_plist_file<P: AsRef<Path>, F: FnOnce(&mut plist::Dictionary)>(
path: P,
f: F,
) -> Result<()> {
use std::io::Cursor;

let path = path.as_ref();
if path.exists() {
let plist_str = read_to_string(path)?;
let mut plist = plist::Value::from_reader(Cursor::new(&plist_str))?;
if let Some(dict) = plist.as_dictionary_mut() {
f(dict);
let mut plist_buf = Vec::new();
let writer = Cursor::new(&mut plist_buf);
plist::to_writer_xml(writer, &plist)?;
let new_plist_str = String::from_utf8(plist_buf)?;
if new_plist_str != plist_str {
write(path, new_plist_str)?;
}
}
}

Ok(())
}

#[cfg(target_os = "macos")]
pub fn update_entitlements<F: FnOnce(&mut plist::Dictionary)>(f: F) -> Result<()> {
if let (Some(project_path), Ok(app_name)) = (
var_os("TAURI_IOS_PROJECT_PATH").map(PathBuf::from),
var("TAURI_IOS_APP_NAME"),
) {
update_plist_file(
project_path
.join(format!("{app_name}_iOS"))
.join(format!("{app_name}_iOS.entitlements")),
f,
)?;
}

Ok(())
}

fn xml_block_comment(id: &str) -> String {
format!("<!-- {id}. AUTO-GENERATED. DO NOT REMOVE. -->")
}

fn insert_into_xml(xml: &str, block_identifier: &str, parent_tag: &str, contents: &str) -> String {
let block_comment = xml_block_comment(block_identifier);

let mut rewritten = Vec::new();
let mut found_block = false;
let parent_closing_tag = format!("</{parent_tag}>");
for line in xml.split('\n') {
if line.contains(&block_comment) {
found_block = !found_block;
continue;
}

// found previous block which should be removed
if found_block {
continue;
}

if let Some(index) = line.find(&parent_closing_tag) {
let identation = " ".repeat(index + 4);
rewritten.push(format!("{}{}", identation, block_comment));
for l in contents.split('\n') {
rewritten.push(format!("{}{}", identation, l));
}
rewritten.push(format!("{}{}", identation, block_comment));
}

rewritten.push(line.to_string());
}

rewritten.join("\n").to_string()
}

pub fn update_android_manifest(block_identifier: &str, parent: &str, insert: String) -> Result<()> {
if let Some(project_path) = var_os("TAURI_ANDROID_PROJECT_PATH").map(PathBuf::from) {
let manifest_path = project_path.join("app/src/main/AndroidManifest.xml");
let manifest = read_to_string(&manifest_path)?;
let rewritten = insert_into_xml(&manifest, block_identifier, parent, &insert);
if rewritten != manifest {
write(manifest_path, rewritten)?;
}
}
Ok(())
}

pub(crate) fn generate_gradle_files(project_dir: PathBuf) -> Result<()> {
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");
Expand Down Expand Up @@ -198,3 +289,39 @@ dependencies {"

Ok(())
}

#[cfg(test)]
mod tests {
#[test]
fn insert_into_xml() {
let manifest = format!(
r#"<manifest>
<application>
<intent-filter>
</intent-filter>
</application>
</manifest>"#
);
let id = "tauritest";
let new = super::insert_into_xml(&manifest, id, "application", "<something></something>");

let block_id_comment = super::xml_block_comment(id);
let expected = format!(
r#"<manifest>
<application>
<intent-filter>
</intent-filter>
{block_id_comment}
<something></something>
{block_id_comment}
</application>
</manifest>"#
);

assert_eq!(new, expected);

// assert it's still the same after an empty update
let new = super::insert_into_xml(&expected, id, "application", "<something></something>");
assert_eq!(new, expected);
}
}
Loading

0 comments on commit d1b81bf

Please sign in to comment.