forked from tauri-apps/plugins-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
74 lines (67 loc) · 2.5 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#[path = "src/config.rs"]
mod config;
use config::{AssociatedDomain, Config};
const COMMANDS: &[&str] = &["get_current", "register", "unregister", "is_registered"];
// TODO: Consider using activity-alias in case users may have multiple activities in their app.
// TODO: Do we want to support the other path* configs too?
fn intent_filter(domain: &AssociatedDomain) -> String {
format!(
r#"<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="{}" />
{}
</intent-filter>"#,
domain.host,
domain
.path_prefix
.iter()
.map(|prefix| format!(r#"<data android:pathPrefix="{prefix}" />"#))
.collect::<Vec<_>>()
.join("\n ")
)
}
fn main() {
let result = tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.android_path("android")
.try_build();
// when building documentation for Android the plugin build result is always Err() and is irrelevant to the crate documentation build
if !(cfg!(docsrs) && std::env::var("TARGET").unwrap().contains("android")) {
result.unwrap();
}
if let Some(config) = tauri_plugin::plugin_config::<Config>("deep-link") {
tauri_plugin::mobile::update_android_manifest(
"DEEP LINK PLUGIN",
"activity",
config
.mobile
.iter()
.map(intent_filter)
.collect::<Vec<_>>()
.join("\n"),
)
.expect("failed to rewrite AndroidManifest.xml");
#[cfg(target_os = "macos")]
{
tauri_plugin::mobile::update_entitlements(|entitlements| {
entitlements.insert(
"com.apple.developer.associated-domains".into(),
config
.mobile
.into_iter()
.map(|d| format!("applinks:{}", d.host).into())
.collect::<Vec<_>>()
.into(),
);
})
.expect("failed to update entitlements");
}
}
}